@@ -166,10 +166,6 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort)
166
166
167
167
void ArduinoIoTCloudTCP::update ()
168
168
{
169
- /* Retrieve the latest data from the MQTT Client. */
170
- if (_mqttClient.connected ())
171
- _mqttClient.poll ();
172
-
173
169
/* Run through the state machine. */
174
170
State next_state = _state;
175
171
switch (_state)
@@ -182,6 +178,19 @@ void ArduinoIoTCloudTCP::update()
182
178
case State::Connected: next_state = handle_Connected (); break ;
183
179
}
184
180
_state = next_state;
181
+
182
+ /* Check for new data from the MQTT client. */
183
+ if (_mqttClient.connected ())
184
+ _mqttClient.poll ();
185
+
186
+ #if OTA_ENABLED
187
+ /* If a _ota_logic object has been instantiated then we are spinning its
188
+ * 'update' method here in order to process incoming data and generally
189
+ * to transition to the OTA logic update states.
190
+ */
191
+ OTAError const err = _ota_logic.update ();
192
+ _ota_error = static_cast <int >(err);
193
+ #endif /* OTA_ENABLED */
185
194
}
186
195
187
196
int ArduinoIoTCloudTCP::connected ()
@@ -231,7 +240,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_ConnectMqttBroker()
231
240
return State::SubscribeMqttTopics;
232
241
233
242
DBG_ERROR (" ArduinoIoTCloudTCP::%s could not connect to %s:%d" , __FUNCTION__, _brokerAddress.c_str (), _brokerPort);
234
- return State::ConnectMqttBroker ;
243
+ return State::ConnectPhy ;
235
244
}
236
245
237
246
ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SubscribeMqttTopics ()
@@ -290,28 +299,22 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
290
299
{
291
300
if (!_mqttClient.connected ())
292
301
{
302
+ DBG_ERROR (" ArduinoIoTCloudTCP::%s MQTT client connection lost" , __FUNCTION__);
303
+
304
+ /* Forcefully disconnect MQTT client and trigger a reconnection. */
305
+ _mqttClient.stop ();
306
+
293
307
/* The last message was definitely lost, trigger a retransmit. */
294
308
_mqtt_data_request_retransmit = true ;
295
309
296
310
/* We are not connected anymore, trigger the callback for a disconnected event. */
297
311
execCloudEventCallback (ArduinoIoTCloudEvent::DISCONNECT);
298
312
299
- /* Forcefully disconnect MQTT client and trigger a reconnection. */
300
- _mqttClient.stop ();
301
- return State::ConnectMqttBroker;
313
+ return State::ConnectPhy;
302
314
}
303
315
/* We are connected so let's to our stuff here. */
304
316
else
305
317
{
306
- #if OTA_ENABLED
307
- /* If a _ota_logic object has been instantiated then we are spinning its
308
- * 'update' method here in order to process incoming data and generally
309
- * to transition to the OTA logic update states.
310
- */
311
- OTAError const err = _ota_logic.update ();
312
- _ota_error = static_cast <int >(err);
313
- #endif /* OTA_ENABLED */
314
-
315
318
/* Check if a primitive property wrapper is locally changed.
316
319
* This function requires an existing time service which in
317
320
* turn requires an established connection. Not having that
0 commit comments