@@ -102,6 +102,56 @@ int ArduinoIoTCloudTCP::begin(ConnectionHandler & connection, bool const enable_
102102 return begin (enable_watchdog, _brokerAddress, _brokerPort);
103103}
104104
105+ void ArduinoIoTCloudTCP::update ()
106+ {
107+ /* Feed the watchdog. If any of the functions called below
108+ * get stuck than we can at least reset and recover.
109+ */
110+ #if defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_MBED)
111+ watchdog_reset ();
112+ #endif
113+
114+ /* Run through the state machine. */
115+ State next_state = _state;
116+ switch (_state)
117+ {
118+ case State::ConnectPhy: next_state = handle_ConnectPhy (); break ;
119+ case State::SyncTime: next_state = handle_SyncTime (); break ;
120+ case State::ConnectMqttBroker: next_state = handle_ConnectMqttBroker (); break ;
121+ case State::Connected: next_state = handle_Connected (); break ;
122+ case State::Disconnect: next_state = handle_Disconnect (); break ;
123+ }
124+ _state = next_state;
125+
126+ /* This watchdog feed is actually needed only by the RP2040 Connect because its
127+ * maximum watchdog window is 8389 ms; despite this we feed it for all
128+ * supported ARCH to keep code aligned.
129+ */
130+ #if defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_MBED)
131+ watchdog_reset ();
132+ #endif
133+
134+ /* Check for new data from the MQTT client. */
135+ if (_mqttClient.connected ())
136+ _mqttClient.poll ();
137+ }
138+
139+ int ArduinoIoTCloudTCP::connected ()
140+ {
141+ return _mqttClient.connected ();
142+ }
143+
144+ void ArduinoIoTCloudTCP::printDebugInfo ()
145+ {
146+ DEBUG_INFO (" ***** Arduino IoT Cloud - configuration info *****" );
147+ DEBUG_INFO (" Device ID: %s" , getDeviceId ().c_str ());
148+ DEBUG_INFO (" MQTT Broker: %s:%d" , _brokerAddress.c_str (), _brokerPort);
149+ }
150+
151+ /* *****************************************************************************
152+ * PRIVATE MEMBER FUNCTIONS
153+ ******************************************************************************/
154+
105155int ArduinoIoTCloudTCP::begin (bool const enable_watchdog, String brokerAddress, uint16_t brokerPort)
106156{
107157 _brokerAddress = brokerAddress;
@@ -204,56 +254,6 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
204254 return 1 ;
205255}
206256
207- void ArduinoIoTCloudTCP::update ()
208- {
209- /* Feed the watchdog. If any of the functions called below
210- * get stuck than we can at least reset and recover.
211- */
212- #if defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_MBED)
213- watchdog_reset ();
214- #endif
215-
216- /* Run through the state machine. */
217- State next_state = _state;
218- switch (_state)
219- {
220- case State::ConnectPhy: next_state = handle_ConnectPhy (); break ;
221- case State::SyncTime: next_state = handle_SyncTime (); break ;
222- case State::ConnectMqttBroker: next_state = handle_ConnectMqttBroker (); break ;
223- case State::Connected: next_state = handle_Connected (); break ;
224- case State::Disconnect: next_state = handle_Disconnect (); break ;
225- }
226- _state = next_state;
227-
228- /* This watchdog feed is actually needed only by the RP2040 Connect because its
229- * maximum watchdog window is 8389 ms; despite this we feed it for all
230- * supported ARCH to keep code aligned.
231- */
232- #if defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_MBED)
233- watchdog_reset ();
234- #endif
235-
236- /* Check for new data from the MQTT client. */
237- if (_mqttClient.connected ())
238- _mqttClient.poll ();
239- }
240-
241- int ArduinoIoTCloudTCP::connected ()
242- {
243- return _mqttClient.connected ();
244- }
245-
246- void ArduinoIoTCloudTCP::printDebugInfo ()
247- {
248- DEBUG_INFO (" ***** Arduino IoT Cloud - configuration info *****" );
249- DEBUG_INFO (" Device ID: %s" , getDeviceId ().c_str ());
250- DEBUG_INFO (" MQTT Broker: %s:%d" , _brokerAddress.c_str (), _brokerPort);
251- }
252-
253- /* *****************************************************************************
254- * PRIVATE MEMBER FUNCTIONS
255- ******************************************************************************/
256-
257257ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_ConnectPhy ()
258258{
259259 if (_connection->check () == NetworkConnectionState::CONNECTED)
0 commit comments