Raspberry Pi Example Sketch
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/RF24.h>
#include <RF24Network/RF24Network.h>
RF24 radio(22, 0);
RF24Network network(radio);
uint32_t displayTimer = 0;
int main(int argc, char** argv)
{
mesh.setNodeID(4);
radio.begin();
radio.setPALevel(RF24_PA_MIN, 0);
printf("start nodeID %d\n", mesh.getNodeID());
if (!mesh.begin()) {
if (radio.isChipConnected()) {
do {
printf("Could not connect to network.\nConnecting to the mesh...\n");
}
else {
printf("Radio hardware not responding.\n");
return 0;
}
}
radio.printDetails();
while (1)
{
mesh.update();
if (millis() - displayTimer >= 1000)
{
displayTimer = millis();
if (!mesh.write(&displayTimer, 'M', sizeof(displayTimer)))
{
if (!mesh.checkConnection())
{
printf("Renewing Address\n");
mesh.renewAddress();
}
else
{
printf("Send fail, Test OK\n");
}
}
else
{
printf("Send OK: %u\n", displayTimer);
}
}
delay(1);
}
return 0;
}
#define MESH_DEFAULT_ADDRESS