@@ -40,17 +40,16 @@ const static int CONNECT_SUCCESS = 1;
4040const static int CONNECT_FAILURE = 0 ;
4141const static int CONNECT_FAILURE_SUBSCRIBE = -1 ;
4242
43- static ConnectionHandler *getTimeConnection = NULL ;
44-
4543static unsigned long getTime () {
46- if (!getTimeConnection ) {
44+ if (!ArduinoCloud. getConnection () ) {
4745 return 0 ;
4846 }
49- unsigned long time = getTimeConnection->getTime ();
47+ ConnectionHandler * connection = ArduinoCloud.getConnection ();
48+ unsigned long time = connection->getTime ();
5049 Debug.print (DBG_DEBUG, " NTP time: %lu" , time);
5150 if (!NTPUtils::isTimeValid (time)) {
5251 Debug.print (DBG_ERROR, " Bogus NTP time from API, fallback to UDP method" );
53- time = NTPUtils (getTimeConnection ->getUDP ()).getTime ();
52+ time = NTPUtils (connection ->getUDP ()).getTime ();
5453 }
5554 #ifdef ARDUINO_ARCH_SAMD
5655 rtc.setEpoch (time);
@@ -148,6 +147,8 @@ int ArduinoIoTCloudClass::begin(Client& net, String brokerAddress, uint16_t brok
148147 Debug.print (DBG_ERROR, " Cryptography certificate reconstruction failure." );
149148 return 0 ;
150149 }
150+
151+ ArduinoBearSSL.onGetTime (getTime);
151152#endif /* BOARD_HAS_ECCX08 */
152153
153154 if (_sslClient) {
@@ -163,7 +164,6 @@ int ArduinoIoTCloudClass::begin(Client& net, String brokerAddress, uint16_t brok
163164 }
164165#elif defined(BOARD_ESP)
165166 _sslClient = new WiFiClientSecure ();
166- Debug.print (DBG_VERBOSE, " new WiFiClientSecure()" );
167167#endif
168168
169169#ifdef BOARD_HAS_ECCX08
@@ -178,16 +178,6 @@ int ArduinoIoTCloudClass::begin(Client& net, String brokerAddress, uint16_t brok
178178 _mqttClient->setUsernamePassword (_device_id, _password);
179179#endif
180180
181- // Bind ArduinoBearSSL callback using static "non-method" function
182- if (_connection != NULL ) {
183- getTimeConnection = _connection;
184- #ifdef BOARD_HAS_ECCX08
185- ArduinoBearSSL.onGetTime (getTime);
186- #endif
187- }
188-
189- // TODO: Find a better way to allow callback into object method
190- // Begin function for the MQTTClient
191181 mqttClientBegin ();
192182
193183 Thing.begin ();
0 commit comments