LoRa Socket send or recv fails with packet > 24 bytes
rdixey last edited by
I'm using the nanogateway.py and abp_node.py code from the pycom libraries examples github. The gateway and client are able to connect to the TTN and send / receive data okay.
The issue is that with a s.send() from abp_node with user data > 11 bytes (or packet > 24 bytes), then the nanogateway lora_sock.recv() only receives a 12 byte message. However this is only the case for the first s.send(). With a multiple sequence of s.send() of the same user data all 24 bytes are received correctly after the first. So from a TTN perspective I have to send my data twice in sequence, the first arrives as garbage, the second is my valid data.
I've tried numerous different LoRa settings but no resolution, hoping someone can give me advice to transmit the packet correctly on the first send?
As an example; here I am sending a byte string 12 bytes long (a 25 byte packet) in a sequence of 3.
But only a 12 byte packet is received by the GW for the 1st sent. For the 2nd & 3rd send in the sequence the GW receives the full 25 byte packet.
TERMINAL OF abp_node: >OKSent from abp_node: b'this is test' type: <class 'bytes'> lenght: 12 Sent from abp_node: b'this is test' type: <class 'bytes'> lenght: 12 Sent from abp_node: b'this is test' type: <class 'bytes'> lenght: 12 > TERMINAL OF nanogateway: >>> received event: 1 received data: b'@/\x15\x02&\x00\x01\x00 VM\xe4' lenght in bytes: 12 Lora Stats: (rx_timestamp=17967923, rssi=-41, snr=26, sfrx=7, sftx=0, tx_trials=0) Push ack received event: 1 received data: b'@/\x15\x02&\x00\x02\x00\x02\xa4\x05\x93\xdb\x85-^U\xa2\xe9-\xff\xb2[\xe7\xf7' lenght in bytes: 25 Lora Stats: (rx_timestamp=22995715, rssi=-40, snr=29, sfrx=7, sftx=0, tx_trials=0) Push ack Pull ack received event: 1 received data: b'@/\x15\x02&\x00\x03\x00\x02\xf8\x0f\x9c\xc4>a\xfaj\xab\xde\x11\xdb\xa8\xfdW\x19' lenght in bytes: 25 Lora Stats: (rx_timestamp=28003579, rssi=-39, snr=28, sfrx=7, sftx=0, tx_trials=0) HERE IS MY ABP Code: from network import LoRa import socket import binascii import struct import time # Initialize LoRa in LORAWAN mode. lora = LoRa(mode=LoRa.LORAWAN, frequency=915000000, power_mode=LoRa.ALWAYS_ON, tx_power=14, bandwidth=LoRa.BW_125KHZ, sf=7, preamble=8, coding_rate=LoRa.CODING_4_5, tx_iq=True, rx_iq=False) # create an ABP authentication params dev_addr = struct.unpack(">l", binascii.unhexlify (config.devAddr.replace(' ', ''))) nwk_swkey = binascii.unhexlify(config.nwkSKey.replace(' ', '')) app_swkey = binascii.unhexlify(config.appSKey.replace(' ', '')) # join a network using ABP (Activation By Personalization) lora.join(activation=LoRa.ABP, auth=(dev_addr, nwk_swkey, app_swkey)) # remove all the existing USA channels and leave just one for channel in range(0, 72): lora.remove_channel(channel) # set the default channels to the same frequency lora.add_channel(0, frequency=915000000, dr_min=0, dr_max=3) # create a LoRa socket s = socket.socket(socket.AF_LORA, socket.SOCK_RAW) # set the LoRaWAN data rate s.setsockopt(socket.SOL_LORA, socket.SO_DR, 3) # make the socket blocking s.setblocking(False) for i in range(3): '''s.send(b'PKT #' + bytes([i])) print('sent:', (b'PKT #' + bytes([i])))''' msg = 'this is test' msg = bytes(msg, 'ascii') s.send(msg) print('Sent from abp_node:', msg, '\ttype:', type(msg), '\tlenght:', len(msg),) time.sleep(5) rx = s.recv(256) if rx: print('Receive:', rx) time.sleep(2)
rdixey last edited by
@jmarcelino I've tweaked the LoRa configs in every way I can think of. I get the same results when using data rate 4. I suppose the next step would be to examine if the packet (header + payload) is being created correctly through socket.send() however I know of no way to do that at the uPython command level. Any suggestions of next steps?
jmarcelino last edited by
Interesting, a packet decode shows that your first packet only contains the (seemingly valid) LoRaWAN header
While the second has the header and payload
Unfortunately I'm not sure why that happens but maybe this is be helpful for debugging.