nrf24l01+ radio.write() FAILS (and can't figure out why) =(

Hi everybody,

I’ve spent a lot of time trying to use two nrf24l01+ modules to create a wireless sensor network.

My intent is to send humidity and temperature from a DHT11 sensor to a reciever placed in another room.

Tried a lot of examples found on the web, but without luck … only the example pingpair.pde of the RF24 class worked once.

I found this code on RF24 library revisited , and modified it a bit to meet my project but is still not working and I cannot figure out why

The code of sender is:

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include <dht11.h>
dht11 DHT;
#define DHT11_PIN 4
 
int data[2];
 
RF24 radio(9,10);
 
const uint64_t pipe = 0xE8E8F0F0E1LL;
bool success;
 
void setup(void)
{
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(pipe);
  
  //Check sensor once starting 
  int chk;
  Serial.print("DHT11, \t");
  chk = DHT.read(DHT11_PIN);    // READ DATA
  switch (chk){
    case DHTLIB_OK:  
                Serial.print("OK,\t"); 
                break;
    case DHTLIB_ERROR_CHECKSUM: 
                Serial.print("Checksum error,\t"); 
                break;
    case DHTLIB_ERROR_TIMEOUT: 
                Serial.print("Time out error,\t"); 
                break;
    default: 
                Serial.print("Unknown error,\t"); 
                break;
  }
  
}
 
void loop(void)
{
  data[0] = DHT.humidity;
  Serial.print(data[0]);
  Serial.print(" , ");
  data[1] = DHT.temperature;
  Serial.println(data[1]);
  
  success = radio.write( data, sizeof(data) );
  switch(success){
    case true:
      Serial.println("OK");
      break;
    case false:
      Serial.println("Failed");
      break;
  }
  
 
}

The problem is that function radio.write() fails instead of succeding, wich means that the message was not sended !

Someone can help me ?

Thanks in advance
Uge

Its been a while since I used the RF24 stuff, but I'd check the return values from

  radio.begin();
  radio.openWritingPipe(pipe);

Also. Generally don't both using a switch statement when you only have 2 results ie true or false

And you don't need to waste a variable to store it, if you are not using that response later

  if (radio.write( data, sizeof(data) ){
      Serial.println("OK");
}
else
{
      Serial.println("Failed");
}

Hi Roger, thanks for your help.

Unfortunately radio.begin() and radio,openWritigPipe() are void functions, so do not returns anything ... how can I test them ?
(sorry for the question, I'm not an experienced programmer)