@@ -82,7 +82,7 @@ void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, b
82
82
if (nc.nodeId != AUTO) {
83
83
setupNode ();
84
84
// Wait configuration reply.
85
- waitForReply ( );
85
+ wait ( 2000 );
86
86
}
87
87
}
88
88
@@ -127,7 +127,7 @@ void MySensor::requestNodeId() {
127
127
debug (PSTR (" req node id\n " ));
128
128
RF24::openReadingPipe (CURRENT_NODE_PIPE, TO_ADDR (nc.nodeId ));
129
129
sendRoute (build (msg, nc.nodeId , GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_ID_REQUEST, false ).set (" " ));
130
- waitForReply ( );
130
+ wait ( 2000 );
131
131
}
132
132
133
133
void MySensor::setupNode () {
@@ -155,13 +155,15 @@ void MySensor::findParentNode() {
155
155
sendWrite (BROADCAST_ADDRESS, msg, true );
156
156
157
157
// Wait for ping response.
158
- waitForReply ( );
158
+ wait ( 2000 );
159
159
}
160
160
161
161
void MySensor::waitForReply () {
162
162
unsigned long enter = millis ();
163
163
// Wait a couple of seconds for response
164
164
while (millis () - enter < 2000 ) {
165
+ // reset watchdog
166
+ wdt_reset ();
165
167
process ();
166
168
}
167
169
}
@@ -498,19 +500,13 @@ void MySensor::sleep(unsigned long ms) {
498
500
}
499
501
500
502
void MySensor::wait (unsigned long ms) {
501
- bool slept_enough = false ;
502
- unsigned long start = millis ();
503
- unsigned long now;
504
-
505
503
// Let serial prints finish (debug, log etc)
506
504
Serial.flush ();
507
-
508
- while (!slept_enough) {
509
- MySensor::process ();
510
- now = millis ();
511
- if (now - start > ms) {
512
- slept_enough = true ;
513
- }
505
+ unsigned long enter = millis ();
506
+ while (millis () - enter < ms) {
507
+ // reset watchdog
508
+ wdt_reset ();
509
+ process ();
514
510
}
515
511
}
516
512
0 commit comments