#include "RF24Network.h"
#include "RF24Mesh.h"
RF52Network network(radio);
RF52Mesh mesh(radio, network);
#define nodeID 1
uint32_t displayTimer = 0;
struct payload_t {
unsigned long ms;
unsigned long counter;
};
void setup() {
Serial.begin(115200);
while (!Serial) {
}
delay(5000);
mesh.setNodeID(nodeID);
Serial.println(F("Connecting to the mesh..."));
if (!mesh.begin()) {
do {
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) {
}
}
}
}
void loop() {
mesh.update();
if (millis() - displayTimer >= 1000) {
displayTimer = millis();
RF24NetworkHeader header(0,'M');
if(!network.write(header,&displayTimer,sizeof(displayTimer) ) ){
if (!mesh.checkConnection()) {
Serial.println("Renewing Address");
if (mesh.renewAddress() == MESH_DEFAULT_ADDRESS) {
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);
}
}
Driver class for nRF52840 2.4GHz Wireless Transceiver.
void setPALevel(uint8_t level, bool lnaEnable=true)