• LoRa encoding/decoding

    LoPy kpn lora encoding decode
    9
    0 Votes
    9 Posts
    2k Views
    V
    My apologies for the late response and any confusion I might have caused by switching to integers within the post. The big/little-endian format was indeed the issue. Adding a '>' sign in both the micropython and the php script solved the problem. This is what I ended up doing. Micropython encoding # Pack data data = struct.pack('>5i', 25, 36, 81, 11) # Send data print('Sending data') lora.join(activation=LoRa.ABP, auth=(dev_addr, nwk_swkey, app_swkey)) s = socket.socket(socket.AF_LORA, socket.SOCK_RAW) s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5) s.setblocking(True) s.send(bytes(data)) s.setblocking(False) PHP decoding $struct = new Struct(); $decoded_payload = $struct->unpack('>5i', hex2bin($decrypted_payload)); $data = [ 'var1' => $decoded_payload[0]/10, 'var2' => $decoded_payload[1]/10, 'var3' => $decoded_payload[2]/10, 'var4' => $decoded_payload[3]/10, 'var5' => $decoded_payload[4]/10 ]; The PHP struct class I used in the PHP decoding script can be found here. Thanks a lot for your help!
  • 0 Votes
    2 Posts
    1k Views
    K
    Found my answer after hours of looking around. Found this beautiful post on TTN regarding decoding the values of different types and what have you found here by Arjanvanb on TTN The main answer was posted on Stackoverflow by Ilya Bursov.
  • 0 Votes
    3 Posts
    1k Views
    RobTuDelftR
    Question 1: that is correct, the payload is still encrypted. Question 2: this has been discussed before here. I would like to refer you to Pierre's blog here.