LoPy: bytes data received in HEX convert to original text
-
To whom it concerns,
I'm sending LoRa messages from an Adafruit Radio bonnet to a LoPy4 but the message received seems to be in Hex -Adafruit Radio bonnet with the following settings:
# Configure LoRa Radio CS = DigitalInOut(board.CE1) RESET = DigitalInOut(board.D25) spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, 869.85) # freq = 869.85mHz rfm9x.tx_power = 23 rfm9x.spreading_factor = 12 rfm9x.signal_bandwidth = 125000 rfm9x.preamble_length = 8
when button "A" is pressed "Hello" is transmitted as follows:
button_a_data = bytes("Hello","utf-8") rfm9x.send(button_a_data)
On the LoPy4 set up as follows:
lora = LoRa(mode=LoRa.LORA, region=LoRa.EU868, sf=12, frequency=869850000, bandwidth=LoRa.BW_125KHZ, public=False, preamble=8, coding_rate=LoRa.CODING_4_5, tx_iq=False, rx_iq=False, power_mode=LoRa.ALWAYS_ON, tx_power=14) s = socket.socket(socket.AF_LORA, socket.SOCK_RAW) s.setblocking(False) raw_data = s.recv(32) if len(raw_data) != 0: print('RX: data received') print(len(raw_data)) print(type(raw_data)) print(raw_data) data = raw_data.decode("utf-8") print(type(data)) print(data)
The LoPy receives the "Hello" from the Adafruit Radio Bonnet as follows:
RX: data received
data length: 9
data type: <class 'bytes'>
data: b'\xff\xff\x00\x00tO+\xf1\x80'In the above code I attempt to convert bytes to string:
data type: <class 'str'>
string data: ��tO+�RSSI: -126, SNR: -7.0
How should I interpret the raw data received and convert it back to the original "Hello" transmitted?
Thank you,
Paul