I am using RF24 Mesh with a Arduino nano. The example sketches for TMRh20's RF24 mesh library are working fine. My only issue is that how do I identify that which data is coming from which child node.
The incoming data on the master node looks like this.
I am using the Mesh Master Example for master node and Mesh example for child or sensor nodes.
Another thing is that i want this data to send on server database, how do i do that?
P.s. This is my first time here so please don't be harsh on me and help this fellow.
/** RF24Mesh_Example_Master.ino by TMRh20
*
*
* This example sketch shows how to manually configure a node via RF24Mesh as a master node, which
* will receive all data from sensor nodes.
*
* The nodes can change physical or logical position in the network, and reconnect through different
* routing nodes as required. The master node manages the address assignments for the individual nodes
* in a manner similar to DHCP.
*
*/
#include "RF24Network.h"
#include "RF24.h"
#include "RF24Mesh.h"
#include <SPI.h>
/***** Configure the chosen CE,CS pins *****/
RF24 radio(7, 8);
RF24Network network(radio);
RF24Mesh mesh(radio, network);
uint32_t displayTimer = 0;
void setup() {
Serial.begin(115200);
while (!Serial) {
// some boards need this because of native USB capability
}
// Set the nodeID to 0 for the master node
mesh.setNodeID(0);
Serial.println(mesh.getNodeID());
// Connect to the mesh
if (!mesh.begin()) {
// if mesh.begin() returns false for a master node, then radio.begin() returned false.
Serial.println(F("Radio hardware not responding."));
while (1) {
// hold in an infinite loop
}
}
}
void 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();
// Check for incoming data from the sensors
if (network.available()) {
RF24NetworkHeader header;
network.peek(header);
uint32_t dat = 0;
switch (header.type) {
// Display the incoming millis() values from the sensor nodes
case 'M':
network.read(header, &dat, sizeof(dat));
Serial.println(dat);
break;
default:
network.read(header, 0, 0);
Serial.println(header.type);
break;
}
}
if (millis() - displayTimer > 5000) {
displayTimer = millis();
Serial.println(" ");
Serial.println(F("********Assigned Addresses********"));
for (int i = 0; i < mesh.addrListTop; i++) {
Serial.print("NodeID: ");
Serial.print(mesh.addrList[i].nodeID);
Serial.print(" RF24Network Address: 0");
Serial.println(mesh.addrList[i].address, OCT);
}
Serial.println(F("**********************************"));
}
}
Child Nodes:
/** RF24Mesh_Example.ino by TMRh20
This example sketch shows how to manually configure a node via RF24Mesh, and send data to the
master node.
The nodes will refresh their network address as soon as a single write fails. This allows the
nodes to change position in relation to each other and the master node.
*/
#include "RF24.h"
#include "RF24Network.h"
#include "RF24Mesh.h"
#include <SPI.h>
//#include <printf.h>
/**** Configure the nrf24l01 CE and CS pins ****/
RF24 radio(7, 8);
RF24Network network(radio);
RF24Mesh mesh(radio, network);
/*
* User Configuration: nodeID - A unique identifier for each radio. Allows addressing
* to change dynamically with physical changes to the mesh.
*
* In this example, configuration takes place below, prior to uploading the sketch to the device
* A unique value from 1-255 must be configured for each node.
*/
#define nodeID 1
uint32_t displayTimer = 0;
struct payload_t {
unsigned long ms;
unsigned long counter;
};
void setup() {
Serial.begin(115200);
while (!Serial) {
// some boards need this because of native USB capability
}
// Set the nodeID manually
mesh.setNodeID(nodeID);
// Connect to the mesh
Serial.println(F("Connecting to the mesh..."));
if (!mesh.begin()) {
if (radio.isChipConnected()) {
do {
// mesh.renewAddress() will return MESH_DEFAULT_ADDRESS on failure to connect
Serial.println(F("Could not connect to network.\nConnecting to the mesh..."));
} while (mesh.renewAddress() == MESH_DEFAULT_ADDRESS);
} else {
Serial.println(F("Radio hardware not responding."));
while (1) {
// hold in an infinite loop
}
}
}
}
void loop() {
mesh.update();
// Send to the master node every second
if (millis() - displayTimer >= 1000) {
displayTimer = millis();
// Send an 'M' type message containing the current millis()
if (!mesh.write(&displayTimer, 'M', sizeof(displayTimer))) {
// If a write fails, check connectivity to the mesh network
if (!mesh.checkConnection()) {
//refresh the network address
Serial.println("Renewing Address");
if (mesh.renewAddress() == MESH_DEFAULT_ADDRESS) {
//If address renewal fails, reconfigure the radio and restart the mesh
//This allows recovery from most if not all radio errors
mesh.begin();
}
} else {
Serial.println("Send fail, Test OK");
}
} else {
Serial.print("Send OK: ");
Serial.println(displayTimer);
}
}
while (network.available()) {
RF24NetworkHeader header;
payload_t payload;
network.read(header, &payload, sizeof(payload));
Serial.print("Received packet #");
Serial.print(payload.counter);
Serial.print(" at ");
Serial.println(payload.ms);
}
}
Is there an easy way to send this data to firebase when there are lets say 50 nodes connected to the master????