I'm doing weather stations, for demo i do 3layer like this
*| | 00 | Master Node (00)
*|--------------------------------------------
*| | | 01 | 02 | 1st level children of master (00)
*| |011| 2nd level children of master. Children of 1st level.
Node 011: temperature, humidity sensors
Node 01 : as a router forward package from node011 to node00 (assum that node011 too far away
from node00)
Node 02 :temperature, humidity sensors
I've succeed with 2 layer node00, node01, node02. Here is what is found but dont really understand. Have anyone done with Rf24network, could you give me some tips for my project.
- When sending a message using RF24Network::write(), you fill in the header with the logical
- node address. The network layer figures out the right path to find that node, and sends
- it through the system until it gets to the right place. This works even if the two nodes
- are far separated, as it will send the message down to the base node, and then back out
- to the final destination.
My TX code for 2 layer
#include <SPI.h>
#include <RF24Network.h>
#include <RF24Network_config.h>
#include <Sync.h>
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
struct package0
{
float temperature = 0;
float humidity = 0;
int soil = 0;
};
typedef struct package0 Package0;
Package0 pack0;
/*******************************************/
struct package1
{
float temperature = 0;
float humidity = 0;
int soil = 0;
};
typedef struct package1 Package1;
Package1 pack1;
/******************RF24******************/
RF24 radio(25,26);
RF24Network network(radio);
const uint16_t this_node = 00; //Octal format
const uint16_t node01 = 01;
const uint16_t node02 = 02;
const uint16_t node011 = 011;
/****************************************/
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
SPI.begin();
WiFi_init();
radio.begin();
network.begin(90, this_node);
radio.setPALevel(RF24_PA_MIN);
radio.setDataRate(RF24_250KBPS);
}
void loop()
{
// put your main code here, to run repeatedly:
network.update();
if(network.available())
{
RF24NetworkHeader header;
network.read(header, &pack0, sizeof(pack0));
if (header.from_node == 1)
{
Serial.print("From node0");
Serial.println(header.from_node);
Serial.print(pack0.temperature);
Serial.println("C");
Serial.print(pack0.humidity);
Serial.println("%");
Serial.print(pack0.soil);
Serial.println("%");
}
else if (header.from_node == 2)
{
pack1.temperature = pack0.temperature;
pack1.humidity = pack0.humidity;
pack1.soil= pack0.soil;
}
}
}
My TX code
#include <DHT.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
#include <RF24Network.h>
#include <RF24Network_config.h>
#include <Sync.h>
/**************soil***************/
int SOILPIN = 36;
/*********************************/
/***************DHT***************/
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
float temperature_old = 0;
float humidity_old = 0;
int soil_old = 0;
struct package0
{
float temperature = 0;
float humidity = 0;
int soil = 0;
};
typedef struct package0 Package0;
Package0 pack0;
/**********************************/
/**************RF24****************/
RF24 radio(25,26);
RF24Network network(radio);
const uint16_t this_node = 01;
const uint16_t master00 = 00;
/**********************************/
void setup() {
pinMode(SOILPIN, INPUT);
Serial.begin(9600);
dht.begin();
radio.begin();
network.begin(90, this_node);
radio.setPALevel(RF24_PA_MIN);
radio.setDataRate(RF24_250KBPS);
}
void loop() {
// put your main code here, to run repeatedly:
network.update();
readdht();
}
void readdht()
{
delay(2000);
pack0.humidity = dht.readHumidity();
pack0.temperature = dht.readTemperature();
pack0.soil = map(analogRead(SOILPIN), 0, 4096, 100, 0);//convert to percentage
if (isnan(pack0.humidity) || isnan(pack0.temperature))
{
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
RF24NetworkHeader header(master00);
bool ok = network.write(header, &pack0, sizeof(pack0));
}
for 3 layers, from what i understand
For node011, just use
RF24NetworkHeader header(master00);
bool ok = network.write(header, &pack0, sizeof(pack0));
am i correct? i dont see what is difference with the code i use, and node011 dont have any reference with node01