I've been working around with the nRF24L01+ modules and the RF24Mesh libraries and have finally got everything working properly through all of the examples, but I am unsure what the proper procedure is for speaking back and forth between two nodes using data structures (say a master to a another node, and then back from that node to the master). My end goal is to incorporate many nodes that all feed their data back to a master, and are able to talk back and forth assuring regular communication between any device and the master.
I currently have a simple data structure set up like this:
struct rxtx_t
{
int Percentage; //send to node
int Status; //send to node
float TempC; //send to master
int overHeatFlag; //send to master
};
rxtx_t rxtx;
and I would like to update two of the elements on the master end, and send to my nodes. Then I would like each node to respectively receive and interpret the data in the structure, update the other two elements of the structure, and send the structure back to the master (with the master being able to identify which node sent the message).
I have spent a lot of time reading through the RF24 documentation and libraries, but have not managed to figure out how to get this working.
I have set up and configured everything as in the examples:
/***** Configure the chosen CE,CS pins *****/
RF24 radio(CE,CS); // differing per uC used.
RF24Network network(radio);
RF24Mesh mesh(radio,network);
and
// Set the nodeID to 0 for the master node
mesh.setNodeID(0); //0 for master and 1 for first node
Serial.println(mesh.getNodeID());
// Connect to the mesh
mesh.begin();
my loop:
// Call mesh.update to keep the network updated
mesh.update();
// In addition, keep the 'DHCP service' running on the master node so addresses will
// be assigned to the sensor nodes
mesh.DHCP();
meshTx();
meshRx();
where meshRx(); is
void meshRx()
{
// Check for incoming data from the sensors
if(network.available()){
RF24NetworkHeader header;
network.peek(header);
switch(header.type){
// Display the incoming millis() values from the sensor nodes
case 'M': network.read(header,&rxtx,sizeof(rxtx)); Serial.println(rxtx.TempC); break;
default: network.read(header,0,0); Serial.println(header.type);break;
}
}
}
and meshTx(); is
void meshTx()
{
if(!mesh.write(&rxtx,'M',sizeof(rxtx))){
// If a write fails, check connectivity to the mesh network
if( ! mesh.checkConnection() )
{
//refresh the network address
Serial.println("Renewing Address");
mesh.renewAddress();
}
else
{
Serial.println("Send fail, Test OK");
}
}
else
{
Serial.print("Send OK: "); Serial.println(rxtx.Percentage);
}
}
If I send simple numeric/character data, it is much easier, but I can't seem to get this to work with structures. I commonly get a "renewing address" on the host end or "connecting to mesh" on the sensor node end. Any suggestions for how to proceed? I'm quite confident I just need a few changes in my procedure/code and I would be up and running.
Additionally, I was curious if this had anything to do with the "message type" (which right now I have set as message type 'M'. I was unable to find any specifics on this, just that I can define my own type of message. Is there a specific type of message I should be using to send structures?
Any elaboration on this entire process would be extremely helpful and much appreciated.
Thanks!