Project

General

Profile

rfm12b ack question

Added by spikie almost 4 years ago

Greetings all,

i’m started with code again and trying to get my ack scripts done.
when i was searching the web about more information i can’t find anything i really want.
and myabe some of you guys could help me.
at the moment i understand that when i send an ack to a node it is:

rf12_sendStart(RF12_HDR_ACK, "hello!", 6);

and at the receive side

 if (RF12_WANTS_ACK) {

      rf12_sendStart(RF12_ACK_REPLY, &payload, sizeof payload);

    }

this far it goes well..

but at the transceiver its getting the ack back and then?!

what i want for my project is that when i receive the ack back, i can proces it further.
like: node is online: sends ack back with a simple ok.
and when the node is offline : cant send back and the sender of the ack needs to be alarm the rest of the system cause there is a node down..

Maybe its a easy question with a easy answer but at the moment i cant find it.

greets,

Spikie


Replies (2)

RE: rfm12b ack question - Added by spikie almost 4 years ago

someone maybe could help me a bit futher?

RE: rfm12b ack question - Added by JohnO almost 4 years ago

Hi spikie,

I clipped this from the roomNode.ino example in the jeelib/examples directory:

    for (byte i = 0; i < RETRY_LIMIT; ++i) {
        rf12_sleep(RF12_WAKEUP);
        rf12_sendNow(RF12_HDR_ACK, &payload, sizeof payload);
        rf12_sendWait(RADIO_SYNC_MODE);
        byte acked = waitForAck();
        rf12_sleep(RF12_SLEEP);

        if (acked) {
            #if DEBUG
                Serial.print(" ack ");
                Serial.println((int) i);
                serialFlush();
            #endif
            // reset scheduling to start a fresh measurement cycle
            scheduler.timer(MEASURE, MEASURE_PERIOD);
            return;
        }

        delay(RETRY_PERIOD * 100);
    }
    scheduler.timer(MEASURE, MEASURE_PERIOD);
    #if DEBUG
        Serial.println(" no ack!");
        serialFlush();
    #endif
}

.
.
.
static byte waitForAck() {
    MilliTimer ackTimer;
    while (!ackTimer.poll(ACK_TIME)) {
        if (rf12_recvDone() && rf12_crc == 0 &&
                // see http://talk.jeelabs.net/topic/811#post-4712
                rf12_hdr == (RF12_HDR_DST | RF12_HDR_CTL | myNodeID))
            return 1;
        set_sleep_mode(SLEEP_MODE_IDLE);
        sleep_mode();
    }
    return 0;
}

It is a little complex in the above example but ideally you would use most of it as is since the logic and nesting is involved.

    (1-2/2)