I have nrf24l01 transcievers and Arduino Unos, and I am trying to get a system where my Arduino at my computer has 2 children that collect data from 5 children each. So there would be 10 Arduinos reading sensor values, 5 on moisture probe and 5 on temp sensor (all in different places). The 5 moisture would send values to another Arduino to collect them all, and the temo Arduinos would do the same with a different one. These 2 Arduinos would then send to 1 master that collects all 10 values. I looked it up and it seems like a mesh network would allow this from TMRh20's library. I successfully made connection from one acting as a transmitter and one as a receiver.
transmitter code:
#include <SPI.h>
#include "RF24.h"
RF24 myRadio (7, 8);
byte addresses[][6] = {"0"};
struct package
{
int id=1;
float moisture;
};
typedef struct package Package;
Package data;
void setup()
{
Serial.begin(9600);
delay(1000);
myRadio.begin();
myRadio.setChannel(115);
myRadio.setPALevel(RF24_PA_MAX);
myRadio.setDataRate( RF24_250KBPS ) ;
myRadio.openWritingPipe( addresses[0]);
delay(1000);
}
void loop()
{
myRadio.write(&data, sizeof(data));
Serial.println(analogRead(A0));
data.moisture = analogRead(A0);
}
receiver code:
#include <SPI.h>
#include "RF24.h"
RF24 myRadio (7, 8);
struct package
{
int id=0;
float moisture;
};
byte addresses[][6] = {"0"};
typedef struct package Package;
Package data;
int row = 0;
int x = 0;
void setup()
{
Serial.begin(9600);
delay(1000);
Serial.println("CLEARDATA");
Serial.println("LABEL,Time,Moisture");
Serial.println("RESETTIMER");
myRadio.begin();
myRadio.setChannel(115);
myRadio.setPALevel(RF24_PA_MAX);
myRadio.setDataRate( RF24_250KBPS ) ;
myRadio.openReadingPipe(1, addresses[0]);
myRadio.startListening();
}
void loop()
{
if ( myRadio.available())
{
while (myRadio.available())
{
myRadio.read( &data, sizeof(data) );
}
Serial.print("DATA,TIME,");
Serial.println((-10.32 * (log(data.moisture) / log(2.718)) + 72.66));
row++;
x++;
if (row > 60)
{Serial.println("CLEARDATA");
Serial.println("ROW,SET,2");
row = 0;}
}
}
I have read through the entire library on TMRh20, but there is not great description of what does what and how to put it in the code. I have spent hours each day for over a week and I have gotten nowhere at all, so I figured I'd ask people who know a lot about this.
It would be greatly appreciated if anyone could help with me setting up a system that accomplishes my mission. It would also help if you know if a mesh network will or won't work doing this and if there is a more efficient way to do this than a mesh network.