@Majenko thank you for your suggestion, I have been playing around a little bit with the powerDown() and powerUp() functions but unfortunately I haven't got it to work yet. Again, it seemed to work for a couple of hours and then again seem to get stuck. Therefore, I also included my code to see if I maybe made some major mistakes.
Furthermore, I assume that I'm having such Chinese clones of the NRF24L01+, as I have bought mine on Aliexpress.
I have included several parts of my code, the following part resets the NRF24L01+ module once a failure is detected. In here I also included the suggested powerDown and powerUp functions.
void NetworkReconnect()
{
pinMode(CE_PIN, OUTPUT); digitalWrite(CE_PIN, HIGH);
pinMode(CS_PIN, OUTPUT); digitalWrite(CS_PIN, HIGH);
radio.powerDown();
radio.begin();
radio.powerDown();
Network.begin(90, thisNode);
delay(100);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_1MBPS);
radio.powerUp();
}
The following code I have in my void.loop(), every 5 seconds I check the network connection, by calling NetworkCheckConnection() (see last part of included code). Which tries to figure out whether the module has crashed, I found this failure detection as a suggestion at a discussion form on the RF24 library on GitHub Discussion. Furthermore, the while loop is limited to only 500ms to avoid being in an infinite loop, if this is exceed, the function NetworkReconnect() is called again.
void loop()
{
Network.update();
if (millis() - Timer > 5000)
{
NetworkCheckConnection();
Timer = millis();
}
if(radio.failureDetected){
radio.failureDetected = false;
delay(250);
Serial.println("Radio failure detected, restarting radio");
NetworkReconnect();
}
if (Network.available())
{
uint32_t failTimer = millis();
while (Network.available())
{
if(millis() - failTimer > 500)
{
radio.failureDetected = true;
Serial.println("Radio available failure detected");
break;
}
... The usual Network.read stuff ...
}
}
... Remainder of code ...
}
And lastly the NetworkCheckConnection() code, this code is based on the RF24 Failure handling example and the principles used for checking connectivity of the RF24Mesh network link (see line 140).
void NetworkCheckConnection()
{
if (radio.getDataRate() != RF24_1MBPS)
{
radio.failureDetected = true;
Serial.println("CheckConnection FailureDetected");
return;
}
// see line 140 of: https://github.com/nRF24/RF24Mesh/blob/master/RF24Mesh.cpp
bool ok = 0;
if(radio.rxFifoFull() || (Network.networkFlags & 1))
{
return;
}
RF24NetworkHeader header(otherNode, NETWORK_PING);
ok = Network.write(header,0,0);
if(ok) { Serial.println("Network Connected"); return;}
if(!ok){ radio.stopListening(); NetworkReconnect(); return;}
}
Lastly, I also call the NetworkReconnect() function if any of my Network.write functions fails.
I hope that you can give me some suggestions on how to get this module to work more reliable, any suggestion is welcome!
Thanks in advance :)