xg590 / SX1276

MicroPython Library for SX1276 (A Long Range Radio Chip from Semtech)
Apache License 2.0
34 stars 8 forks source link

REQ not ACKed #7

Closed atonughosh closed 1 year ago

atonughosh commented 1 year ago

I am trying to send REQ messages in a while loop to a receiver who receives the message and responds with some content. The REQs are not ACKed in my code.

My requester is

while True:
    if received_payload != None:
        print(received_payload)
    payload = "Node,3"
    print('[Sending]', payload)
    lora.send(dst_id=1, msg=payload, pkt_type=lora.PKT_TYPE['REQ']) # Sender's lora_id is 1 and receiver's is 0
    #Check and resend the message
    resend_count = 0
    print(lora.seq_num)
    while (int(lora.seq_num) != 0) and resend_count < 7:
        lora.send(dst_id=1, msg=payload, pkt_type=lora.PKT_TYPE['REQ'])
        print("Resending packet..."+str(resend_count))
        resend_count += 1
    time.sleep(0.05)

The receiver is

while True:
    lora.mode = 'RXCONTINUOUS'

    if received_payload != None:
        count = 0
        resend_count = 0

        try:
            if str((received_payload), 'UTF-8').startswith("Node"):
                print("REQ Message starts with a 'Node'")
                if len(message_list) > 0:
                    print("Sending this node's messages")
                    send_message = "Table,"  + str(message_JSON)
                    print(send_message)
                    lora.send(dst_id=3, msg=send_message, pkt_type=lora.PKT_TYPE['REQ'])
                    print(lora.seq_num)
                    while (int(lora.seq_num) != 0) and resend_count < 7:
                        lora.send(dst_id=3, msg=send_message, pkt_type=lora.PKT_TYPE['REQ'])
                        print("Resending Message..."+str(resend_count))
                        resend_count += 1
                        print(lora.seq_num)

                    if (int(lora.seq_num) != 0) and resend_count >= 7:
                        print("Message sending failed!")
                    else:
                        print("Message sent!")
                else:
                    print("This node's message list contains no entries. Sending nothing back.")

        except:
            print("REQ Message Received But Payload Decode Error")

    sleep(0.03)

The receiver is receiving the REQ messages and is also sending the content. But somehow, the ACKs are not working. What I found from the debug prints is that the REQ sender does not receive the ACK messages.

xg590 commented 1 year ago

I am vacationing, will look after the problem this weekend. Happy Holidays.

atonughosh commented 1 year ago

I am vacationing, will look after the problem this weekend. Happy Holidays.

Ok. Thank you. Happy holidays.

xg590 commented 1 year ago

I am implementing the "Retry" mechanism. Will finish it ASAP. Do you mind share your whole send/receive scripts?

xg590 commented 1 year ago

I am vacationing, will look after the problem this weekend. Happy Holidays.

Ok. Thank you. Happy holidays.

I have implemented retry mechanism in the library and you can use the new parameter in send function to specify how many times you want the sender to retry if it doesn't hear an ACK packet from the receiver. The new send function has been used in the new sender.py

xg590 commented 1 year ago

I am closing this issue because of inactivity.