ElectronicCats / Beelan-LoRaWAN

A LoRaWAN library for compatible arduino board
https://www.beelan.mx
MIT License
189 stars 77 forks source link

How to check for uplink confirmation? #61

Closed postfalk closed 3 years ago

postfalk commented 3 years ago

I am trying to receive an uplink confirmation by setting the confirm flag while running sendUplink. My network server (Chirpstack) acknowledges that it is a confirmed uplink). How do I check in my device code whether the packet has been received? I found the undocumented readAck method but it always returns true, even if I unplug my gateway and I am sure that there is no other gateway around.

I am using the send-class-A-OTAA example modified like this:

void loop() {
  // Check interval overflow
  if(millis() - previousMillis > interval) {
    previousMillis = millis(); 

    sprintf(myStr, "Counter-%d", counter); 

    Serial.print("Sending: ");
    Serial.println(myStr);

    // change 1: requesting acknowledgement
    lora.sendUplink(myStr, strlen(myStr), 1, 1);
    counter++;
  }

  // change 2: try to get confirmation, always True even if gateway turned off and no messages in the network server
  ackStatus = lora.readAck();
  if (ackStatus) {
    Serial.println("Acknowledged");
  }
  recvStatus = lora.readData(outStr);
  if(recvStatus) {
    Serial.println(outStr);
  }

  // Check Lora RX
  lora.update();
}
Mark-Wills commented 3 years ago

Looking at the code, I note that readAck() checks the flag Ack_Status and only returns true if Ack_Status is true. However, looking further down in the code, it looks like Ack_Status is only set in the update() function:

 //LoRa cycle
      LORA_Cycle(&Buffer_Tx, &Buffer_Rx, &RFM_Command_Status, &Session_Data, &OTAA_Data, &Message_Rx, &LoRa_Settings);

      if ((Message_Rx.Frame_Control & 0x20) > 0)
        Ack_Status = NEW_ACK;

I have verified that the code is checking the correct bit in the correct location in the FHDR structure, and it is correct (bit weight 0x20).

Therefore, my best suggestion is to call update() just prior to calling readAck() (in your code, you are calling readAck before update() - I think you need to do it the other way around):

lora.sendUplink(myStr, strlen(myStr), 1, 1);
lora.update();
if(lora.readAck()) {
  // ack was confirmed by back-end
} else {
  // no confirmation received
}

I have checked the sendUplink() function, and it does not call update() so maybe that is the issue? I defer to the wisdom of the maintainers, but it's worth a try!

Regards

Mark

geologic commented 3 years ago

Any news about this issue? I would like to check for uplink confirmation too...

novvere commented 3 years ago

sendUplink() just enqueue the downlink to be sent in next update() loop, it doesn't actually send the uplink. In the same way readData() returns already received (in the last update()) downlink data.

You can call update() before readAck() or you can check for ACK in the next Arduino loop()

postfalk commented 3 years ago

I still have problems to get this to work. I changed the order and tried the class A example with the .readData() method but no luck. I am using a Feather M0 Lora.

Mark-Wills commented 3 years ago

The issue might be that the network is not honouring the uplink confirmation request. Might be worth checking with your network provider.

On Wed, Feb 24, 2021 at 9:24 PM Falk Schuetzenmeister < notifications@github.com> wrote:

I still have problems to get this to work. I changed the order and tried the class A example with the .readData() method but no luck.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/BeelanMX/Beelan-LoRaWAN/issues/61#issuecomment-785394312, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFAGDCTQJANC5UWZJBKGGBDTAVVCJANCNFSM4TRD37QA .

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

daeynasvistas commented 3 years ago

I still have problems to get this to work. I changed the order and tried the class A example with the .readData() method but no luck. I am using a Feather M0 Lora.

Im unable to get it to work also.

what do you mean, the ".readData()" method?