@@ -80,6 +80,7 @@ ArduinoIoTCloudTCP::ArduinoIoTCloudTCP()
8080 * PUBLIC MEMBER FUNCTIONS
8181 ******************************************************************************/
8282
83+ #if CONNECTION_HANDLER_ENABLED
8384int ArduinoIoTCloudTCP::begin (ConnectionHandler& connection, bool const enableWatchdog, String brokerAddress, uint16_t brokerPort, bool autoReconnect)
8485{
8586 _connection = &connection;
@@ -89,6 +90,7 @@ int ArduinoIoTCloudTCP::begin(ConnectionHandler& connection, bool const enableWa
8990 return begin (_connection->getClient (), _connection->getUDP (), enableWatchdog, brokerAddress, brokerPort, autoReconnect);
9091#endif
9192}
93+ #endif
9294
9395int ArduinoIoTCloudTCP::begin (Client& brokerClient, Client& otaClient, UDP& ntpClient, bool const enableWatchdog, String brokerAddress, uint16_t brokerPort, bool autoReconnect)
9496{
@@ -292,14 +294,15 @@ int ArduinoIoTCloudTCP::begin(bool const enableWatchdog, String brokerAddress, u
292294 _ota.setAuthentication (getDeviceId ().c_str (), _password.c_str ());
293295#endif // OTA_ENABLED && !defined(OFFLOADED_DOWNLOAD) && defined(OTA_BASIC_AUTH)
294296
295- #ifdef BOARD_HAS_OFFLOADED_ECCX08
297+
298+ #if defined(BOARD_HAS_OFFLOADED_ECCX08) && defined(CONNECTION_HANDLER_ENABLED) && (CONNECTION_HANDLER_ENABLED == 1)
296299 if (String (WiFi.firmwareVersion ()) < String (" 1.6.0" )) {
297300 DEBUG_ERROR (" ArduinoIoTCloudTCP::%s In order to connect to Arduino IoT Cloud, NINA firmware needs to be >= 1.6.0, current %s" , __FUNCTION__, WiFi.firmwareVersion ());
298301 return 0 ;
299302 }
300303#endif /* BOARD_HAS_OFFLOADED_ECCX08 */
301304
302- #if defined (ARDUINO_UNOWIFIR4)
305+ #if defined(ARDUINO_UNOWIFIR4) && defined(CONNECTION_HANDLER_ENABLED) && (CONNECTION_HANDLER_ENABLED == 1 )
303306 if (String (WiFi.firmwareVersion ()) < String (" 0.2.0" )) {
304307 DEBUG_ERROR (" ArduinoIoTCloudTCP::%s In order to connect to Arduino IoT Cloud, WiFi firmware needs to be >= 0.2.0, current %s" , __FUNCTION__, WiFi.firmwareVersion ());
305308 return 0 ;
@@ -342,8 +345,13 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Init()
342345 _otaTLSClient.begin (_otaClient);
343346#endif
344347
348+ #if CONNECTION_HANDLER_ENABLED
345349 /* Setup TimeService */
346- _time_service.begin (_connection);
350+ if (_connection != nullptr ) {
351+ _time_service.begin (_connection);
352+ } else
353+ #endif
354+ _time_service.begin (_ntpClient);
347355
348356 /* Since we do not control what code the user inserts
349357 * between ArduinoIoTCloudTCP::begin() and the first
@@ -354,8 +362,12 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Init()
354362 if (_enableWatchdog) {
355363 /* Initialize watchdog hardware */
356364 watchdog_enable ();
357- /* Setup callbacks to feed the watchdog during offloaded network operations (connection/download)*/
358- watchdog_enable_network_feed (_connection->getInterface ());
365+ #if CONNECTION_HANDLER_ENABLED
366+ if (_connection != nullptr ) {
367+ /* Setup callbacks to feed the watchdog during offloaded network operations (connection/download)*/
368+ watchdog_enable_network_feed (_connection->getInterface ());
369+ }
370+ #endif
359371 }
360372#endif
361373
@@ -364,13 +376,20 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Init()
364376
365377ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_ConnectPhy ()
366378{
367- if (_connection->check () == NetworkConnectionState::CONNECTED)
368- {
369- if (!_connection_attempt.isRetry () || (_connection_attempt.isRetry () && _connection_attempt.isExpired ()))
370- return State::SyncTime;
379+ #if CONNECTION_HANDLER_ENABLED
380+ if (_connection == nullptr ) {
381+ return State::SyncTime;
371382 }
372383
384+ if (_connection->check () == NetworkConnectionState::CONNECTED) {
385+ if (!_connection_attempt.isRetry () || (_connection_attempt.isRetry () && _connection_attempt.isExpired ())) {
386+ return State::SyncTime;
387+ }
388+ }
373389 return State::ConnectPhy;
390+ #else
391+ return State::SyncTime;
392+ #endif
374393}
375394
376395ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SyncTime ()
0 commit comments