Skip to content

Commit

Permalink
Add failure recovery to examples
Browse files Browse the repository at this point in the history
Utilize radio.failureDetected() method and verifying default radio config to detect problems communicating with the radio and restart/reconfigure the device. Makes radios hot-swappable with RF24Gateway.
  • Loading branch information
TMRh20 committed Jul 24, 2020
1 parent 207c960 commit d4455dd
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 10 deletions.
18 changes: 18 additions & 0 deletions examples/RF24GatewayNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ int main(int argc, char** argv) {
char subnet[] = "255.255.255.0";

gw.setIP(ip,subnet);
uint32_t failCounter = 0;

while(1){

Expand All @@ -59,6 +60,23 @@ int main(int argc, char** argv) {
mesh.renewAddress();
}
}
//This section checks for failures detected by RF24 & RF24Network as well as
//checking for deviations from the default configuration (1MBPS data rate)
//The mesh is restarted on failure and failure count logged to failLog.txt
//This makes the radios hot-swappable, disconnect & reconnect as desired, it should come up automatically
if(radio.failureDetected > 0 || radio.getDataRate() != RF24_1MBPS){
radio.failureDetected = 0;
radio.maskIRQ(1,1,1);
std::ofstream myFile;
myFile.open ("failLog.txt");
if (myFile.is_open()){
myFile << ++failCounter << "\n";
myFile.close();
}
delay(500);
mesh.begin(1);
radio.maskIRQ(1,1,0);
}

}
return 0;
Expand Down
35 changes: 27 additions & 8 deletions examples/gwNodeInt/RF24GatewayNodeInt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ int main(int argc, char** argv) {
radio.maskIRQ(1,1,0);
attachInterrupt(23, INT_EDGE_FALLING, intHandler);

uint32_t failCounter = 0;

while(1){

Expand All @@ -60,15 +61,33 @@ int main(int argc, char** argv) {
//The function will perform a delayed wait of max 3ms unless otherwise specified.
gw.poll(3);

if(millis()-mesh_timer > 30000 && mesh.getNodeID()){ //Every 30 seconds, test mesh connectivity
mesh_timer = millis();
if( ! mesh.checkConnection() ){
//refresh the network address
radio.maskIRQ(1,1,1); //Use polling only for address renewal
mesh.renewAddress();
radio.maskIRQ(1,1,0);
if(millis()-mesh_timer > 30000 && mesh.getNodeID()){ //Every 30 seconds, test mesh connectivity
mesh_timer = millis();
if( ! mesh.checkConnection() ){
//refresh the network address
radio.maskIRQ(1,1,1); //Use polling only for address renewal
mesh.renewAddress();
radio.maskIRQ(1,1,0);
}
}
}

//This section checks for failures detected by RF24 & RF24Network as well as
//checking for deviations from the default configuration (1MBPS data rate)
//The mesh is restarted on failure and failure count logged to failLog.txt
//This makes the radios hot-swappable, disconnect & reconnect as desired, it should come up automatically
if(radio.failureDetected > 0 || radio.getDataRate() != RF24_1MBPS){
radio.failureDetected = 0;
radio.maskIRQ(1,1,1);
std::ofstream myFile;
myFile.open ("failLog.txt");
if (myFile.is_open()){
myFile << ++failCounter << "\n";
myFile.close();
}
delay(500);
mesh.begin(1);
radio.maskIRQ(1,1,0);
}

}
return 0;
Expand Down
20 changes: 20 additions & 0 deletions examples/ncurses/RF24Gateway_ncurses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ int main() {
/******************************************************************/
/***********************LOOP***************************************/
bool ok = true;
uint32_t failCounter = 0;

while(1){

Expand Down Expand Up @@ -241,6 +242,25 @@ bool ok = true;


}

//This section checks for failures detected by RF24 & RF24Network as well as
//checking for deviations from the default configuration (1MBPS data rate)
//The mesh is restarted on failure and failure count logged to failLog.txt
//This makes the radios hot-swappable, disconnect & reconnect as desired, it should come up automatically
if(radio.failureDetected > 0 || radio.getDataRate() != RF24_1MBPS){
radio.failureDetected = 0;
radio.maskIRQ(1,1,1);
std::ofstream myFile;
myFile.open ("failLog.txt");
if (myFile.is_open()){
myFile << ++failCounter << "\n";
myFile.close();
}
delay(500);
mesh.begin(1);
radio.maskIRQ(1,1,0);
}

delay(2);
}//while 1

Expand Down
22 changes: 20 additions & 2 deletions examples/ncursesInt/RF24Gateway_ncursesInt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,10 @@ int main() {
/******************************************************************/
/***********************LOOP***************************************/
bool ok = true;
uint32_t failCounter = 0;

while(1){



if(millis()-mesh_timer > 30000 && mesh.getNodeID()){ //Every 30 seconds, test mesh connectivity
if( ! mesh.checkConnection() ){
wclear(renewPad);
Expand Down Expand Up @@ -265,6 +264,25 @@ bool ok = true;


}

//This section checks for failures detected by RF24 & RF24Network as well as
//checking for deviations from the default configuration (1MBPS data rate)
//The mesh is restarted on failure and failure count logged to failLog.txt
//This makes the radios hot-swappable, disconnect & reconnect as desired, it should come up automatically
if(radio.failureDetected > 0 || radio.getDataRate() != RF24_1MBPS){
radio.failureDetected = 0;
radio.maskIRQ(1,1,1);
std::ofstream myFile;
myFile.open ("failLog.txt");
if (myFile.is_open()){
myFile << ++failCounter << "\n";
myFile.close();
}
delay(500);
mesh.begin(1);
radio.maskIRQ(1,1,0);
}

}//while 1


Expand Down

0 comments on commit d4455dd

Please # to comment.