Acknowledgment giving wrong value
-
I was trying to follow the LoRa Nano-Gateway example in the docs https://docs.pycom.io/pycom_esp32/pycom_esp32/tutorial/includes/lora-nano-gateway.html. In the gateway code there is ack_pkg = struct.pack(_LORA_PKG_ACK_FORMAT, device_id, 1, 200)
lora_sock.send(ack_pkg). So, I should get an acknowledgment on the message sending node. I am not getting the acknowledgment. To debug I used a print statement and printed print(ack) on the node sending the data. Instead of getting 200, print(ack) produces 161. Why does the value of the ack change? I believe this problem is the cause for not receiving the acknowledgment.
-
while (True):
recv_pkg = lora_sock.recv(512)
time.sleep(0.2)if(len(recv_pkg) > 13): print(recv_pkg) recv_pkg_len = recv_pkg[12] # unpack the message based on protocol definition dest_addr, src_addr, pkg_len, msg = struct.unpack(_LORA_PKG_FORMAT % recv_pkg_len, recv_pkg) if(dest_addr==SRC_ADDR): ack_pkg = struct.pack(_LORA_ACK_FORMAT, src_addr, SRC_ADDR, 1, 200) lora_sock.send(ack_pkg) else: print("Message lost")
-
while (True):
recv_pkg = lora_sock.recv(512)
time.sleep(0.2)if(len(recv_pkg) > 13): recv_pkg_len = recv_pkg[12] # unpack the message based on protocol definition dest_addr, src_addr, sink_addr, pkg_len, msg = struct.unpack(_LORA_PKG_FORMAT % recv_pkg_len, recv_pkg) # Check whether it is final destination(Sink address) for message if(dest_addr==SRC_ADDR and sink_addr == NULL_ADDR): print("Src_addr: %s \t Pkg: %s" %(src_addr,msg)) ack_pkg = struct.pack(_LORA_ACK_FORMAT, DST_ADDR, SRC_ADDR, 1, 200) lora_sock.send(ack_pkg) waiting_ack = False
-
while True:
pkg = struct.pack(_LORA_PKG_FORMAT %len(msg), DEST_MAC_ADDR,
SRC_MAC_ADDR, SINK_MAC_ADDR,len(msg), msg)
lora_sock.send(pkg)waiting_ack = True while(waiting_ack): # if a message of the size of acknowledge message is received if(len(recv_ack) > 0): to_addr, from_addr , pkg_len, ack = struct.unpack(_LORA_ACK_FORMAT, recv_ack) if(to_addr == SRC_MAC_ADDR and from_addr == DEST_MAC_ADDR): if(ack == 200): waiting_ack=False print("Ack Received from: %s"%DEST_MAC_ADDR) else: waiting_ack = False print("Message Failed") elif(to_addr == SRC_MAC_ADDR and from_addr == SINK_MAC_ADDR): if(ack == 200): waiting_ack = False else: waiting_ack = False print("Ack Error") time.sleep(5)
-
@timeb
You must show more info, format used forpack
andunpack
Data used for call function arguments
also data send and what you recived
-
I am focusing on this part which belongs to the Node code as given in the docs. The thing is once recv_ack is unpacked and the following two conditions should be tested for the arrival of an acknowledgment.
if(device_id == DEVICE_ID):
if(ack == 200)So, in my case I don't receive the acknowledgment and I tried to debug it using print after unpacking then I did print(ack) but the value I get is 161 which is not equal to 200 and then I don't receive the acknowledgment. What could have possibly happened?
waiting_ack = True
while(waiting_ack):
recv_ack = lora_sock.recv(256)if (len(recv_ack) > 0): device_id, pkg_len, ack = struct.unpack(_LORA_PKG_ACK_FORMAT, recv_ack) if (device_id == DEVICE_ID): if (ack == 200): waiting_ack = False # If the uart = machine.UART(0, 115200) and os.dupterm(uart) are set in the boot.py this print should appear in the serial port print("ACK") else: waiting_ack = False # If the uart = machine.UART(0, 115200) and os.dupterm(uart) are set in the boot.py this print should appear in the serial port print("Message Failed") time.sleep(5)