File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -178,6 +178,7 @@ void ArduinoIoTCloudTCP::update()
178178 switch (_state)
179179 {
180180 case State::ConnectPhy: next_state = handle_ConnectPhy (); break ;
181+ case State::SyncTime: next_state = handle_SyncTime (); break ;
181182 case State::ConnectMqttBroker: next_state = handle_ConnectMqttBroker (); break ;
182183 case State::SubscribeMqttTopics: next_state = handle_SubscribeMqttTopics (); break ;
183184 case State::RequestLastValues: next_state = handle_RequestLastValues (); break ;
@@ -215,11 +216,18 @@ void ArduinoIoTCloudTCP::setOTAStorage(OTAStorage & ota_storage)
215216ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_ConnectPhy ()
216217{
217218 if (_connection->check () == NetworkConnectionState::CONNECTED)
218- return State::ConnectMqttBroker ;
219+ return State::SyncTime ;
219220 else
220221 return State::ConnectPhy;
221222}
222223
224+ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SyncTime ()
225+ {
226+ unsigned long const internal_posix_time = time_service.getTime ();
227+ DBG_VERBOSE (" ArduinoIoTCloudTCP::%s internal clock configured to posix timestamp %d" , __FUNCTION__, internal_posix_time);
228+ return State::ConnectMqttBroker;
229+ }
230+
223231ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_ConnectMqttBroker ()
224232{
225233 if (_mqttClient.connect (_brokerAddress.c_str (), _brokerPort))
Original file line number Diff line number Diff line change @@ -99,6 +99,7 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass
9999 enum class State
100100 {
101101 ConnectPhy,
102+ SyncTime,
102103 ConnectMqttBroker,
103104 SubscribeMqttTopics,
104105 RequestLastValues,
@@ -148,6 +149,7 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass
148149 inline String getTopic_ota_in () { return String (" /a/d/" + getDeviceId () + " /ota/i" ); }
149150
150151 State handle_ConnectPhy ();
152+ State handle_SyncTime ();
151153 State handle_ConnectMqttBroker ();
152154 State handle_SubscribeMqttTopics ();
153155 State handle_RequestLastValues ();
You can’t perform that action at this time.
0 commit comments