• 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
    588 Views
    E
    @jokr2 Hi, in fact i doesn't understood what do you mean. LoraMac allows you to send data using lora radio modulation, this radio layer doesn't have ECC. LoraWan is upper protocol used by lot of gateway and have only a MIC field in frame (Message Integrity Control), i doesn't allow correction, only detection of altered frame (and AES used in lorawan is only used for encryption). If you use LoraMac mode you have to add to your data payload your ECC code by your own. Finaly, if you want to have your ECC added to all frame send by your socket without explicitly add ECC in python code (but it will added on lower layer in C code), you can build your own custom lopy firmware (instruction is present in the forum) Hope this help you