RF24Mesh - Automated Networking for nrf24L01 & nrf52x radios v2.0.0
2024 - A user friendly mesh overlay for sensor neworks using RF24Network
Loading...
Searching...
No Matches
RF24Mesh_SerialConfig.ino

This example sketch shows how the same sketch can be written to a large number of devices, which are configured later via Serial input.

#include "RF24Network.h"
#include "RF24.h"
#include "RF24Mesh.h"
#include <SPI.h>
#include <printf.h>
RF24 radio(7, 8);
RF24Network network(radio);
RF24Mesh mesh(radio, network);
void setup() {
Serial.begin(115200);
while (!Serial) {
// some boards need this because of native USB capability
}
// If this is a new node, the nodeID will return 0. Once the node is configured with an ID other than 0, this
// bit will no longer run.
while (!mesh.getNodeID()) {
// Wait for the nodeID to be set via Serial
if (Serial.available()) {
mesh.setNodeID(Serial.read());
Serial.print("Set NodeID: ");
Serial.println(mesh.getNodeID());
}
}
// Now that this node has a unique ID, 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
}
}
}
}
unsigned long displayTimer = 0;
void loop() {
mesh.update();
// Send an update in every second
if (millis() - displayTimer >= 1000) {
displayTimer = millis();
// Send the current millis() value to the master node as an 'M' type message
mesh.write(&displayTimer, 'M', sizeof(displayTimer));
}
}
#define MESH_DEFAULT_ADDRESS