nRF24L01 to send and recieve data with sketches, but i have some questions.

Hi guys, i have an idea to build a wireless thermostat for my rooms in my house. The function goes as this.

1 arduino in the living room houses a tempsensor and an graphic controller of some kind. This sensor sends data to another arduino in the same room that is attached to a relay controlling my heating system. The slave continually sends it´s state to the master telling the master if it´s on or not.

I have cobbled together some code for this purpose down below.

The master sends a number to the slave and the slave reads it and then sends it back. The master verifies it. BUT i imagine with the nrf24L01 there are alot more that goes into this. Do i need to think about what happens if no responce comes? How would you guys do it?

Master

#include <SPI.h>   // Comes with Arduino IDE
#include "RF24.h"  // Download and Install (See above)
RF24 myRadio (7, 8); // "myRadio" is the identifier you will use in following methods
byte addresses[][6] = {"1Node"}; // Create address for 1 pipe.
int dataTransmitted;  // Data that will be Transmitted from the transmitter
int dataReceived;  // Data that will be received from the transmitter

void setup()
{
  Serial.begin(115200);
  delay(1000);
  dataTransmitted = 100;
  myRadio.begin();  // Start up the physical nRF24L01 Radio
  myRadio.setChannel(108);  // Above most Wifi Channels
  myRadio.setPALevel(RF24_PA_MIN);
  myRadio.openWritingPipe( addresses[0]); // Use the first entry in array 'addresses' (Only 1 right now)
  myRadio.openReadingPipe(1, addresses[0]); // Use the first entry in array 'addresses' (Only 1 right now)
}

void loop()
{
   myRadio.stopListening();
   myRadio.write( &dataTransmitted, sizeof(dataTransmitted) ); //  Transmit the data
   Serial.println(dataTransmitted);
   dataTransmitted = dataTransmitted + 1;  // Send different data next time
   myRadio.startListening();
   delay(1000);
   
  if ( myRadio.available()) // Check for incoming data from transmitter
  {
    while (myRadio.available())  // While there is data ready
    {
      myRadio.read( &dataReceived, sizeof(dataReceived) ); // Get the data payload (You must have defined that already!)
    }
    // DO something with the data, like print it
    Serial.print("Data received = ");
    Serial.println(dataReceived);

  }

}

Slave

#include <SPI.h>   // Comes with Arduino IDE
#include "RF24.h"  // Download and Install (See above)
RF24 myRadio (7, 8); // "myRadio" is the identifier you will use in following methods
byte addresses[][6] = {"1Node"}; // Create address for 1 pipe.
int dataTransmitted;  // Data that will be Transmitted from the transmitter
int dataReceived;  // Data that will be received from the transmitter

void setup()
{
  Serial.begin(115200);
  delay(1000);
  dataTransmitted = 100;
  myRadio.begin();  // Start up the physical nRF24L01 Radio
  myRadio.setChannel(108);  // Above most Wifi Channels
  myRadio.setPALevel(RF24_PA_MIN);
  myRadio.openWritingPipe( addresses[0]); // Use the first entry in array 'addresses' (Only 1 right now)
  myRadio.openReadingPipe(1, addresses[0]); // Use the first entry in array 'addresses' (Only 1 right now)
  myRadio.startListening();
  delay(1000);  
}

void loop()
{

  if ( myRadio.available()) // Check for incoming data from transmitter
  {
    while (myRadio.available())  // While there is data ready
    {
      myRadio.read( &dataReceived, sizeof(dataReceived) ); // Get the data payload (You must have defined that already!)
    }
    // DO something with the data, like print it
    Serial.print("Data received = ");
    Serial.println(dataReceived);

    myRadio.stopListening();
    myRadio.write( &dataReceived, sizeof(dataReceived) ); //  Transmit the data
    Serial.print("Sending data back = "); Serial.println(dataReceived);
    myRadio.startListening();
    delay(1000);  
  }

}

This Simple nRF24L01+ Tutorial may give you some ideas.

There is a lot of error correction in the nRF24 system and if the sending nRF24 receives an acknowledgement you can be sure that the receiver has got the message correctly. There is no need to send the data back.

Whether your program needs to do something if no acknowledgement is received is a matter for you to decide taking account of the system you are trying to build.

For example I have a model train control system. The controller normally sends a message about 10 times per second. If the program in the locomotive (the receiver) misses a message it continues to use the speed and direction data it already has. If it fails to receive 10 messages in a row it makes the loco stop.

...R