Unable to send response msg from Gateway to Node [solved]

Started by charlieb, March 17, 2016, 02:40:57 PM

charlieb

I'm a newbie and I've been playing with a couple of Moteinos.  I have a simple setup: 1 Mote set as Node and another one set as Gateway.  I've downloaded the sample code from Github for each of them and now I'm trying to implement a sort of client/server (node/gateway) example.  This is the behavior I want:
1. Node sends a request to Gateway (including ACK request). The request is a plain text message.
2. Gateway responds almost immediately with ACK (e.g. acknowledge message received)
3. After a small delay to simulate some work, Gateway sends a message back to the node as a response to the original request (also a plain text message).

Trouble is, with the Gateway/Node sample code provided in GitHub I'm able to get up to step 2 (Gateway sends ACK back to node) but for some reason step 3 does not work (the Gateway is unable to send a message back to the node - code falls to "Failed" in the sendWithRetry() command).

Here's the code I'm using... Hope someone can tell me what I'm doing wrong:

if (radio.receiveDone())
{
    Serial.print("Msg from node");
    Serial.print(radio.SENDERID, DEC);
    Serial.print(": ");

    byte senderId = radio.SENDERID;

    for (byte i = 0; i < radio.DATALEN; i++) Serial.print((char)radio.DATA[i]);

    Blink(LED,3);

    if(radio.ACKRequested()) radio.sendACK();

    delay(100);

    Serial.print("   -->   Sending Response to node");
    Serial.print(senderId);
    Serial.print("... ");
    
    if (radio.sendWithRetry(senderId, "200 OK", 6, 0))  //The code fails here - the serial monitor shows "Failed"
    {
          Serial.println("  Ok");
          Blink(LED, 3);
    }
    else Serial.println(" Failed");
    
}


Thanks!
   

luisr320

if (radio.sendWithRetry(senderId, "200 OK", 6, 0))

That 0 (zero) means "make only 1 attempt with no retries".
Try to increase that number to 2 or 3 and see what happens.

charlieb

This is what worked for me (don't know why...)..  In my code I made sure that a call to radio.receivedone() was made first before attempting to transmit anything.  With that change, everything works perfectly (even without increasing the number of send retries as one of the posts suggested..)