Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    LoPy: bytes data received in HEX convert to original text

    Scheduled Pinned Locked Moved LoPy
    1 Posts 1 Posters 272 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P Offline
      pkilcoyne
      last edited by

      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

      1 Reply Last reply Reply Quote 0

      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

      With your input, this post could be even better 💗

      Register Login
      • 1 / 1
      • First post
        Last post

      Pycom on Twitter

      Pycom