Maybe I'm missing something obvious, but I was trying to find an example of where somebody sends data back with the ACK. My g/w node is sending a packet to the node requesting that it turn on a specific port (could be a relay, LED, etc.). I want to make sure that the node does in fact perform that act so I'm doing a quick digitalWrite/digitalRead on the requested port. I want to be able to send the data from the digitalRead back in the ACK packet. I see in the RFM69 code where you are allowed to send a buffer of data back in the ACK response.
What I'm conceptually missing is how you detect and extract the data contained in the ACK packet. I'm sure I'm missing something fundamental but any pointers would be appreciated.
Sure, do it all the time... Try this...
rc = radio.sendWithRetry(to, &devDescriptor, devDescriptor.h.len);
return AckCheck(rc);
...
/******************************************************************************
*
* AckCheck() - local method to check to see if there is any AckData and save it locally if there is.
*
******************************************************************************/
bool AckCheck(bool rc)
{
if (rc)
{
noInterrupts();
// tranmission ok, see if any data was Ack'd
if (radio.DATALEN && radio.DATALEN==radio.DATA[0]) // got a valid packet?
{
// yup, save it
for (int i=0; i<radio.DATALEN; i++)
sendAckData[i] = radio.DATA[i];
}
else
sendAckData[0]=0;
interrupts();
} else
{
sendAckData[0]=0;
}
return rc;
}
/******************************************************************************
*
* getAckData() - return ptr to locally saved ack data
*
******************************************************************************/
byte *getAckData(void)
{
if (sendAckData[0]) return &sendAckData[0];
return NULL;
}
The data comes in with the ACK and is picked up by the receiveDone called from sendWithRetry().
Tom
TomWS, thanks for the code. I finally got around to testing it out today. There is one line, however, that I don't understand:
if (radio.DATALEN && radio.DATALEN==radio.DATA[0])This line always fails. When I print out the values of
radio.DATALEN and
radio.DATA[0], I get the following:
radio.DATALEN = 30 (my message in the ACK is "Hello there, glad to meet you"
radio.DATA[0] = 72 (72 in decimal = 48 in hex = "H" (ASCII))
If I leave off the "
&& radio.DATALEN==radio.DATA[0]", the code works great.
Any thoughts on what I'm doing wrong?