Author Topic: ACK Response - How to tell!  (Read 14819 times)

fabltd

  • NewMember
  • *
  • Posts: 9
ACK Response - How to tell!
« on: May 18, 2017, 07:28:51 AM »
To confirm:

TX - radio.sendWithRetry - Sends the command to the RX.

RX gets command with - radio.receiveDone()

RX sends ack.

How can you tell that the TX got the ack command?

Thanks


perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: ACK Response - How to tell!
« Reply #1 on: May 18, 2017, 07:52:06 AM »
One way is to have the TX repeat the command if it doesn't get the ACK. Some systems use a counter in the packet that increments on new packets but not on repeat ones, if the receiver sees a packet it records the counter value and only responds with the ACK, i.e. doesn't actually do anything else with the packet, if the counter value is the same as it got before. That way the TX can repeat as many packets as it likes knowing the receiver will only action of them, but will still send an ACK where necessary. This mechanism is particularly useful with repeaters in ad-hoc type networks.

Mark.

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: ACK Response - How to tell!
« Reply #2 on: May 18, 2017, 03:08:51 PM »
To confirm:

TX - radio.sendWithRetry - Sends the command to the RX.

RX gets command with - radio.receiveDone()

RX sends ack.

How can you tell that the TX got the ack command?

Thanks
The radio.sendWithRetry() has a retry parameter as in:
Code: [Select]
virtual bool sendWithRetry(uint8_t toAddress, const void* buffer, uint8_t bufferSize, uint8_t retries=2, uint8_t retryWaitTime=40); // 40ms roundtrip req for 61byte packets
so the default is 2, meaning there will be a total of 3 TXs if no ACK is received.   If your sender did not get the ACK, it will automatically resend.   You can increase the number of retries in the call, but if you can't make it in three, there are probably other issues that would need your attention.

Also, Perky's suggestion of having an incrementing sequence number is a good one if you need to keep track of sequential packets.

Tom

fabltd

  • NewMember
  • *
  • Posts: 9
Re: ACK Response - How to tell!
« Reply #3 on: May 18, 2017, 05:23:57 PM »
Thanks

Is there any example code for the counter option?

I have an issue where the tx sends a packet it's then sent by serial but while this happens the tx sends another packet that is then missed by the rx.

The packets must follow in order otherwise the process at the tx fails.

We send two byes in each packet.

Thanks for the help so far. It's driving me crazy.



TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: ACK Response - How to tell!
« Reply #4 on: May 18, 2017, 06:59:37 PM »
Thanks

Is there any example code for the counter option?

I have an issue where the tx sends a packet it's then sent by serial but while this happens the tx sends another packet that is then missed by the rx.

The packets must follow in order otherwise the process at the tx fails.

We send two byes in each packet.

Thanks for the help so far. It's driving me crazy.
Ok, let's see if I understand...

You have a transmitter that sends packets at a certain rate.
You have a receiver that takes those packets and sends them on via a serial link to something else.
The serial interface is not fast enough to keep up with the packets sent by the transmitter.
The transmitter will fail if all the packets don't get through.

Hmmmm, hopefully this project isn't for a nuclear reactor.

What piece of information is missing?

Tom

joelucid

  • Hero Member
  • *****
  • Posts: 868
Re: ACK Response - How to tell!
« Reply #5 on: May 19, 2017, 01:38:45 AM »
Quote
Also, Perky's suggestion of having an incrementing sequence number is a good one if you need to keep track of sequential packets.

I also do that. I've found that it's best to have two counters so you can avoid double delivery of the payload and of any command you might send with the ack. I use 2x 4 bits so it fits into one byte. Each side transmits their sequence number and the one last seen from the other side.

Then you have a queue for the ack commands and redeliver until the client has seen a given command - as seen by it sending the right gw sequence number.

Joe

fabltd

  • NewMember
  • *
  • Posts: 9
Re: ACK Response - How to tell!
« Reply #6 on: May 19, 2017, 01:44:45 AM »
Cool does any one have some example
Code for this. I get the concept but cannot work out how to implement it.

Yes the issue is the tx can send before the rx is ready. It's a discovery algo for devices on a bus connected via serial. If a byte is missed we could mis discover the end network.

joelucid

  • Hero Member
  • *****
  • Posts: 868
Re: ACK Response - How to tell!
« Reply #7 on: May 19, 2017, 01:52:25 AM »
Quote
I have an issue where the tx sends a packet it's then sent by serial but while this happens the tx sends another packet that is then missed by the rx.

There could be two reasons for this.

Your serial speed could be so slow and the packet so large that you block in writing to serial and don't get a chance to timely ack the next packet from the radio. In that case you could increase the tx buffer size of the Arduino library to ensure that the packet can be delivered completely unblocking.

Or you might not put the radio into rx early enough to rx the next packet. To avoid that call receiveDone before sending the serial data. Actually I vaguely recall you might have to call it twice but I may be wrong. This will put the radio into rx and you can spend the tx duration doing other stuff.

Joe

joelucid

  • Hero Member
  • *****
  • Posts: 868
Re: ACK Response - How to tell!
« Reply #8 on: May 19, 2017, 01:54:43 AM »
Quote
Yes the issue is the tx can send before the rx is ready. It's a discovery algo for devices on a bus connected via serial. If a byte is missed we could mis discover the end network.

Sounds like it's the second case I described then. So receiveDone should fix it.

fabltd

  • NewMember
  • *
  • Posts: 9
Re: ACK Response - How to tell!
« Reply #9 on: May 19, 2017, 02:31:19 AM »
Hi

Ok will try that today.

If any one as an example for the counter too that would be great.

syrinxtech

  • Sr. Member
  • ****
  • Posts: 347
  • Country: us
    • Syrinx Technologies
Re: ACK Response - How to tell!
« Reply #10 on: May 19, 2017, 07:41:04 AM »
Two suggestions:

1. If you want to read more about the sequence numbers, read up on how TCP does it. 
2. How about a receive queue to help with missed packets.

Also, this is part of the RFM69 code....why wouldn't this work?

// should be polled immediately after sending a packet with ACK request
bool RFM69::ACKReceived(uint8_t fromNodeID) {
  if (receiveDone())
    return (SENDERID == fromNodeID || fromNodeID == RF69_BROADCAST_ADDR) && ACK_RECEIVED;
  return false;
}

I'll have to check some of my code but I'm pretty sure I have used this code chunk for this very reason.

I checked....this is how I used the ACKReceived() function in some code:

Code: [Select]
radio.send(NODEID, &xmitData, sizeof(xmitData), true);
sentTime = millis();
while (millis() - sentTime < 2500)
{
    if (radio.ACKReceived(NODEID))

   ---- act accordingly

}
« Last Edit: May 19, 2017, 02:06:03 PM by syrinxtech »

ChemE

  • Sr. Member
  • ****
  • Posts: 419
  • Country: us
Re: ACK Response - How to tell!
« Reply #11 on: May 19, 2017, 08:32:15 AM »
Cool does any one have some example
Code for this. I get the concept but cannot work out how to implement it.

https://lowpowerlab.com/forum/rf-range-antennas-rfm69-library/packet-error-rate/msg19539/#msg19539

My example only uses one 16-bit counter which the node increments and the gateway uses to tell if it has missed one or more packets.  It would not be hard to add joelucid's gateway-to-node counter using my code to track which ACKs have gotten through to the node.

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: ACK Response - How to tell!
« Reply #12 on: May 19, 2017, 08:34:10 AM »
802.15.4 has a packet counter built into the frame, because the hardware does auto-retries..  It's a very well thought out protocol and well documented too.

ChemE

  • Sr. Member
  • ****
  • Posts: 419
  • Country: us
Re: ACK Response - How to tell!
« Reply #13 on: May 19, 2017, 08:54:35 AM »
Damn WhiteHare, that is 708 pages of well thought out goodness.  This will take me a good while to comb through, but it looks pretty useful for our purposes.

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: ACK Response - How to tell!
« Reply #14 on: May 19, 2017, 09:31:59 AM »
Yeah, that's IEEE for you, but it's been very well vetted.