Example of node to node communication using RF24Mesh
#include "RF24.h"
#include "RF24Network.h"
#include <SPI.h>
RF24 radio(7, 8);
RF24Network network(radio);
#define nodeID 1
#define otherNodeID 2
uint32_t millisTimer = 0;
void setup() {
Serial.begin(115200);
while (!Serial) {
}
mesh.setNodeID(nodeID);
Serial.println(F("Connecting to the mesh..."));
if (!mesh.begin()) {
if (radio.isChipConnected()) {
do {
Serial.println(F("Could not connect to network.\nConnecting to the mesh..."));
} else {
Serial.println(F("Radio hardware not responding."));
while (1) {
}
}
}
}
void loop() {
mesh.update();
if (network.available()) {
RF24NetworkHeader header;
uint32_t mills;
network.read(header, &mills, sizeof(mills));
Serial.print(F("Rcv "));
Serial.print(mills);
Serial.print(F(" from nodeID "));
int _ID = mesh.getNodeID(header.from_node);
if (_ID > 0) {
Serial.println(_ID);
} else {
Serial.println(F("Mesh ID Lookup Failed"));
}
}
if (millis() - millisTimer >= 1000) {
millisTimer = millis();
if (!mesh.write(&millisTimer, 'M', sizeof(millisTimer), otherNodeID)) {
if (!mesh.checkConnection()) {
do {
Serial.println(F("Reconnecting to mesh network..."));
} else {
Serial.println(F("Send fail, Test OK"));
}
}
}
}
#define MESH_DEFAULT_ADDRESS