@@ -40,17 +40,16 @@ const static int CONNECT_SUCCESS = 1;
40
40
const static int CONNECT_FAILURE = 0 ;
41
41
const static int CONNECT_FAILURE_SUBSCRIBE = -1 ;
42
42
43
- static ConnectionHandler *getTimeConnection = NULL ;
44
-
45
43
static unsigned long getTime () {
46
- if (!getTimeConnection ) {
44
+ if (!ArduinoCloud. getConnection () ) {
47
45
return 0 ;
48
46
}
49
- unsigned long time = getTimeConnection->getTime ();
47
+ ConnectionHandler * connection = ArduinoCloud.getConnection ();
48
+ unsigned long time = connection->getTime ();
50
49
Debug.print (DBG_DEBUG, " NTP time: %lu" , time);
51
50
if (!NTPUtils::isTimeValid (time)) {
52
51
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 ();
54
53
}
55
54
#ifdef ARDUINO_ARCH_SAMD
56
55
rtc.setEpoch (time);
@@ -148,6 +147,8 @@ int ArduinoIoTCloudClass::begin(Client& net, String brokerAddress, uint16_t brok
148
147
Debug.print (DBG_ERROR, " Cryptography certificate reconstruction failure." );
149
148
return 0 ;
150
149
}
150
+
151
+ ArduinoBearSSL.onGetTime (getTime);
151
152
#endif /* BOARD_HAS_ECCX08 */
152
153
153
154
if (_sslClient) {
@@ -163,7 +164,6 @@ int ArduinoIoTCloudClass::begin(Client& net, String brokerAddress, uint16_t brok
163
164
}
164
165
#elif defined(BOARD_ESP)
165
166
_sslClient = new WiFiClientSecure ();
166
- Debug.print (DBG_VERBOSE, " new WiFiClientSecure()" );
167
167
#endif
168
168
169
169
#ifdef BOARD_HAS_ECCX08
@@ -178,16 +178,6 @@ int ArduinoIoTCloudClass::begin(Client& net, String brokerAddress, uint16_t brok
178
178
_mqttClient->setUsernamePassword (_device_id, _password);
179
179
#endif
180
180
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
191
181
mqttClientBegin ();
192
182
193
183
Thing.begin ();
0 commit comments