Error with multiple message with the RadioHead librairy

Hello

I’m using the RadioHead library [1] to have a communication between two Arduino with an NRF24L01+ wireless module. If I send one (1) message, everything works fine. But when I try to send four (4) messages of 15 Bytes, nothing works.

I tried everything in the last two days but I can’t have anything working.

Do someone have an idea?

There is my code

vserver.ino

#include <Speck.h>
#include <RH_NRF24.h>
#include <RHEncryptedDriver.h>
#include <RHReliableDatagram.h>

Speck CIPHER;
const unsigned char ENCRYPTION_KEY[16] =
    {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};

const int NRF_24_CE_PIN = 9, NRF_24_CSN_PIN = 10,
          SERVER_ADDRESS = 1, CLIENT_ADDRESS = 2,
          MANAGER_TIMEOUT = 5000;

RH_NRF24 NRF24(NRF_24_CE_PIN, NRF_24_CSN_PIN);
RHEncryptedDriver NRF24_DRIVER(NRF24, CIPHER);
RHReliableDatagram NRF24_MANAGER(NRF24_DRIVER, SERVER_ADDRESS);

uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
uint8_t from;

void setup() {
    Serial.begin(9600);

    if (!NRF24_MANAGER.init())
        Serial.println("NRF24 initialization failed");

    NRF24_MANAGER.setTimeout(MANAGER_TIMEOUT);

    CIPHER.setKey(ENCRYPTION_KEY, sizeof(ENCRYPTION_KEY));
}

void loop() {
    if (NRF24_MANAGER.available()) {
        if (NRF24_MANAGER.recvfromAck(buf, &len, &from)) {
            if(strcmp((char*)buf, "GET_DATA")  == 0) {

                uint8_t data0[] = "AAAAAAAAAAAAAA";
                uint8_t data1[] = "BBBBBBBBBBBBBB";
                uint8_t data2[] = "CCCCCCCCCCCCCC";
                uint8_t data3[] = "DDDDDDDDDDDDDD";

                if (NRF24_MANAGER.sendtoWait(data0, sizeof(data0), from)) {
                    Serial.println("sendtoWait 0 OK");

                    if (NRF24_MANAGER.sendtoWait(data1, sizeof(data1), from)) {
                        Serial.println("sendtoWait 1 OK");

                        if (NRF24_MANAGER.sendtoWait(data2, sizeof(data2), from)) {
                            Serial.println("sendtoWait 2 OK");

                            if (NRF24_MANAGER.sendtoWait(data3, sizeof(data3), from)) {
                                Serial.println("sendtoWait 3 OK");
                            }
                            else Serial.println("sendtoWait 3 failed");
                        }
                        else Serial.println("sendtoWait 2 failed");
                    }
                    else Serial.println("sendtoWait 1 failed");
                }
                else Serial.println("sendtoWait 0 failed");
            }
        }
    }
}

vclient.ino

#include <Speck.h>
#include <RH_NRF24.h>
#include <RHEncryptedDriver.h>
#include <RHReliableDatagram.h>

Speck CIPHER;
const unsigned char ENCRYPTION_KEY[16] =
    {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};

const int NRF_24_CE_PIN = 9, NRF_24_CSN_PIN = 10,
          SERVER_ADDRESS = 1, CLIENT_ADDRESS = 2;

RH_NRF24 NRF24(NRF_24_CE_PIN, NRF_24_CSN_PIN);
RHEncryptedDriver NRF24_DRIVER(NRF24, CIPHER);
RHReliableDatagram NRF24_MANAGER(NRF24_DRIVER, CLIENT_ADDRESS);

uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
uint8_t from;

bool GET_DATA = false;

void setup() {
    Serial.begin(9600);

    if (!NRF24_MANAGER.init())
        Serial.println("NRF24 initialization failed");

    CIPHER.setKey(ENCRYPTION_KEY, sizeof(ENCRYPTION_KEY));

    cli();
    TCCR1A = 0;
    TCCR1B = 0;
    TCNT1  = 0;
    OCR1A = 15624;
    TCCR1B |= (1 << WGM12);
    TCCR1B |= (1 << CS12) | (1 << CS10);
    TIMSK1 |= (1 << OCIE1A);
    sei();
}

void loop() {
    if(GET_DATA) {
        uint8_t data[] = "GET_DATA";
        if (NRF24_MANAGER.sendtoWait(data, sizeof(data), SERVER_ADDRESS)) {
            if (NRF24_MANAGER.recvfromAckTimeout(buf, &len, 1000, &from)) {
                Serial.print("Received 0: ");
                Serial.println((char*)buf);
                delay(500);

                if (NRF24_MANAGER.recvfromAckTimeout(buf, &len, 1000, &from)) {
                    Serial.print("Received 1: ");
                    Serial.println((char*)buf);
                    delay(500);

                    if (NRF24_MANAGER.recvfromAckTimeout(buf, &len, 1000, &from)) {
                        Serial.print("Received 2: ");
                        Serial.println((char*)buf);
                        delay(500);

                        if (NRF24_MANAGER.recvfromAckTimeout(buf, &len, 1000, &from)) {
                            Serial.print("Received 3: ");
                            Serial.println((char*)buf);

                            Serial.println("EVERYTHING OK! YEAH!");
                        } else Serial.println("Fail 3");
                    } else Serial.println("Fail 2");
                } else Serial.println("Fail 1");
            } else Serial.println("Fail 0");
        }
        GET_DATA = false;
    }
}


ISR(TIMER1_COMPA_vect) {
    static int seconds = 0;
    if(++seconds == 10) {
        GET_DATA = true;
        seconds = 0;
    }
}

Thanks

[1] RadioHead: RadioHead Packet Radio library for embedded microprocessors

vserver.ino (2.17 KB)

vclient.ino (2.41 KB)

I tried to add a delay but that didn't work too