File tree 2 files changed +22
-2
lines changed
2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -315,6 +315,9 @@ void ArduinoIoTCloudTCP::update()
315
315
case State::SubscribeMqttTopics: next_state = handle_SubscribeMqttTopics (); break ;
316
316
case State::RequestLastValues: next_state = handle_RequestLastValues (); break ;
317
317
case State::Connected: next_state = handle_Connected (); break ;
318
+ #if OTA_ENABLED
319
+ case State::Reset: next_state = handle_Reset (); break ;
320
+ #endif
318
321
}
319
322
_state = next_state;
320
323
@@ -520,8 +523,8 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
520
523
_ota_req = false ;
521
524
/* Transmit the cleared error and request flags to the cloud. */
522
525
sendPropertiesToCloud ();
523
- /* Reset the board to apply OTA update */
524
- systemReset () ;
526
+ /* We are now ready to reset and apply OTA update */
527
+ return State::Reset ;
525
528
}
526
529
}
527
530
#endif /* OTA_ENABLED */
@@ -530,6 +533,19 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
530
533
}
531
534
}
532
535
536
+ #if OTA_ENABLED
537
+ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Reset ()
538
+ {
539
+ static unsigned long const timeToReset = millis () + 1000 ;
540
+ /* We need to wait at least one second to make sure properties are synced up */
541
+ if (static_cast <int32_t >(timeToReset - millis ()) <= 0 ) {
542
+ /* Reset the board to apply OTA update */
543
+ systemReset ();
544
+ }
545
+ return State::Reset;
546
+ }
547
+ #endif /* OTA_ENABLED */
548
+
533
549
void ArduinoIoTCloudTCP::onMessage (int length)
534
550
{
535
551
ArduinoCloud.handleMessage (length);
Original file line number Diff line number Diff line change @@ -104,6 +104,9 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass
104
104
SubscribeMqttTopics,
105
105
RequestLastValues,
106
106
Connected,
107
+ #if OTA_ENABLED
108
+ Reset,
109
+ #endif
107
110
};
108
111
109
112
State _state;
@@ -156,6 +159,7 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass
156
159
State handle_SubscribeMqttTopics ();
157
160
State handle_RequestLastValues ();
158
161
State handle_Connected ();
162
+ State handle_Reset ();
159
163
160
164
static void onMessage (int length);
161
165
void handleMessage (int length);
You can’t perform that action at this time.
0 commit comments