andrewrapp / xbee-arduino

Arduino library for communicating with XBee radios in API mode
GNU General Public License v2.0
334 stars 162 forks source link

readPacketUntilAvailable has weird behaviour #79

Open Ruudjhuu opened 5 years ago

Ruudjhuu commented 5 years ago

when using this funciton, it works the first time and all the other times after, i get the same response.

my case: I send DN (Detect node) request as an atcommandrequest option. When no device should be found, the function spend ten seconds waiting and then returns no device found. Just as it should. However, when the function is called the second time, it receives the same response within 1 ms.

I added ggetResponse().reset(); between line 850 and 851 and it works now.

matthijskooijman commented 5 years ago

This indeed looks like a bug. Your suggested fix seems reasonable to me, though it is probably better to call resetResponse() instead. One alternative would be to put a readPacket() in front of the loop (or turn it into a do/while loop), to make sure readPacket() is called at least once (which also resets the response).