A copy of the RF24GatewayNode example using interrupts.
#include <RF24/RF24.h>
#include <RF24Network/RF24Network.h>
#include <RF24Mesh/RF24Mesh.h>
#include <RF24Gateway/RF24Gateway.h>
RF24 radio(22, 0);
RF24Network network(radio);
RF24Mesh mesh(radio, network);
void intHandler()
{
gw.update(true);
}
uint32_t mesh_timer = 0;
int main(int argc, char** argv)
{
gw.begin();
char ip[] = "10.10.2.2";
char subnet[] = "255.255.255.0";
gw.setIP(ip, subnet);
radio.maskIRQ(1, 1, 0);
attachInterrupt(23, INT_EDGE_FALLING, intHandler);
uint32_t failCounter = 0;
while (1) {
if (network.available()) {
RF24NetworkHeader header;
size_t size = network.peek(header);
uint8_t buf[size];
network.read(header, &buf, size);
printf("Received Network Message, type: %d id %d from %d\n", header.type, header.id, mesh.getNodeID(header.from_node));
}
if (millis() - mesh_timer > 30000 && mesh.getNodeID() > 0) {
mesh_timer = millis();
if (!mesh.checkConnection()) {
mesh.renewAddress();
}
}
if (radio.failureDetected > 0 || radio.getDataRate() != RF24_1MBPS) {
radio.failureDetected = 0;
std::ofstream myFile;
myFile.open("failLog.txt");
if (myFile.is_open()) {
myFile << ++failCounter << "\n";
myFile.close();
}
delay(500);
mesh.begin();
}
gw.poll(2);
}
return 0;
}