@@ -40,7 +40,7 @@ static unsigned long getTime() {
40
40
if (!getTimeConnection) return 0 ;
41
41
unsigned long time = getTimeConnection->getTime ();
42
42
if (!NTPUtils::isTimeValid (time)) {
43
- debugMessage (" Bogus NTP time from API, fallback to UDP method" , 0 );
43
+ debugMessage (DebugLevel::Error, " Bogus NTP time from API, fallback to UDP method" );
44
44
time = NTPUtils (getTimeConnection->getUDP ()).getTime ();
45
45
}
46
46
#ifdef ARDUINO_ARCH_SAMD
@@ -109,18 +109,18 @@ int ArduinoIoTCloudClass::begin(Client& net, String brokerAddress, uint16_t brok
109
109
byte deviceIdBytes[72 ];
110
110
111
111
if (!ECCX08.begin ()) {
112
- debugMessage (" Cryptography processor failure. Make sure you have a compatible board." , 0 );
112
+ debugMessage (DebugLevel::Error, " Cryptography processor failure. Make sure you have a compatible board." );
113
113
return 0 ;
114
114
}
115
115
116
116
if (!ECCX08.readSlot (deviceIdSlot, deviceIdBytes, sizeof (deviceIdBytes))) {
117
- debugMessage (" Cryptography processor read failure." , 0 );
117
+ debugMessage (DebugLevel::Error, " Cryptography processor read failure." );
118
118
return 0 ;
119
119
}
120
120
_device_id = (char *)deviceIdBytes;
121
121
122
122
if (!ECCX08Cert.beginReconstruction (keySlot, compressedCertSlot, serialNumberAndAuthorityKeyIdentifierSlot)) {
123
- debugMessage (" Cryptography certificate reconstruction failure." , 0 );
123
+ debugMessage (DebugLevel::Error, " Cryptography certificate reconstruction failure." );
124
124
return 0 ;
125
125
}
126
126
@@ -131,7 +131,7 @@ int ArduinoIoTCloudClass::begin(Client& net, String brokerAddress, uint16_t brok
131
131
ECCX08Cert.setIssuerCommonName (" Arduino" );
132
132
133
133
if (!ECCX08Cert.endReconstruction ()) {
134
- debugMessage (" Cryptography certificate reconstruction failure." , 0 );
134
+ debugMessage (DebugLevel::Error, " Cryptography certificate reconstruction failure." );
135
135
return 0 ;
136
136
}
137
137
@@ -386,49 +386,43 @@ void ArduinoIoTCloudClass::connectionCheck()
386
386
}
387
387
}
388
388
389
- char msgBuffer[120 ];
390
-
391
-
392
389
switch (iotStatus) {
393
390
case IOT_STATUS_CLOUD_IDLE:
394
391
setIoTConnectionState (IOT_STATUS_CLOUD_CONNECTING);
395
392
break ;
396
393
case IOT_STATUS_CLOUD_ERROR:
397
- debugMessage (" Cloud Error. Retrying..." , 0 );
394
+ debugMessage (DebugLevel::Error, " Cloud Error. Retrying..." );
398
395
setIoTConnectionState (IOT_STATUS_CLOUD_RECONNECTING);
399
396
break ;
400
397
case IOT_STATUS_CLOUD_CONNECTED:
401
- debugMessage ( " ." , 4 , false , true );
398
+ debugMessageNoTimestamp (DebugLevel::Verbose, " ." );
402
399
if (!_mqttClient->connected ()){
403
400
setIoTConnectionState (IOT_STATUS_CLOUD_DISCONNECTED);
404
401
}
405
402
break ;
406
403
case IOT_STATUS_CLOUD_DISCONNECTED:
407
404
setIoTConnectionState (IOT_STATUS_CLOUD_RECONNECTING);
408
405
break ;
409
- case IOT_STATUS_CLOUD_RECONNECTING:
410
- int arduinoIoTReconnectionAttempt;
411
- arduinoIoTReconnectionAttempt = reconnect (*_net);
412
- sprintf (msgBuffer, " ArduinoCloud.reconnect(): %d" , arduinoIoTReconnectionAttempt);
413
- debugMessage (msgBuffer, 2 );
414
- if (arduinoIoTReconnectionAttempt == 1 ) {
406
+ case IOT_STATUS_CLOUD_RECONNECTING: {
407
+ int const ret_code_reconnect = reconnect (*_net);
408
+ debugMessage (DebugLevel::Info, " ArduinoCloud.reconnect(): %d" , ret_code_reconnect);
409
+ if (ret_code_reconnect == CONNECT_SUCCESS) {
415
410
setIoTConnectionState (IOT_STATUS_CLOUD_CONNECTED);
416
411
CloudSerial.begin (9600 );
417
412
CloudSerial.println (" Hello from Cloud Serial!" );
418
413
}
414
+ }
419
415
break ;
420
416
case IOT_STATUS_CLOUD_CONNECTING:
421
417
int const ret_code_connect = connect ();
422
- sprintf (msgBuffer, " ArduinoCloud.connect(): %d" , ret_code_connect);
423
- debugMessage (msgBuffer, 4 );
418
+ debugMessage (DebugLevel::Verbose, " ArduinoCloud.connect(): %d" , ret_code_connect);
424
419
if (ret_code_connect == CONNECT_SUCCESS) {
425
420
setIoTConnectionState (IOT_STATUS_CLOUD_CONNECTED);
426
421
CloudSerial.begin (9600 );
427
422
CloudSerial.println (" Hello from Cloud Serial!" );
428
423
}
429
424
else if (ret_code_connect == CONNECT_FAILURE_SUBSCRIBE) {
430
- sprintf (msgBuffer, " ERROR - Please verify your THING ID" );
431
- debugMessage (msgBuffer, 0 );
425
+ debugMessage (DebugLevel::Info, " ERROR - Please verify your THING ID" );
432
426
}
433
427
break ;
434
428
}
@@ -438,34 +432,30 @@ void ArduinoIoTCloudClass::setIoTConnectionState(ArduinoIoTConnectionStatus _new
438
432
{
439
433
switch (_newState){
440
434
case IOT_STATUS_CLOUD_ERROR:
441
- debugMessage (" Arduino, we have a problem." , 0 );
435
+ debugMessage (DebugLevel::Error, " Arduino, we have a problem." );
442
436
break ;
443
437
case IOT_STATUS_CLOUD_CONNECTING:
444
- debugMessage (" Connecting to Arduino IoT Cloud..." , 0 );
438
+ debugMessage (DebugLevel::Error, " Connecting to Arduino IoT Cloud..." );
445
439
break ;
446
440
case IOT_STATUS_CLOUD_RECONNECTING:
447
- debugMessage (" Reconnecting to Arduino IoT Cloud..." , 0 );
441
+ debugMessage (DebugLevel::Error, " Reconnecting to Arduino IoT Cloud..." );
448
442
break ;
449
443
case IOT_STATUS_CLOUD_CONNECTED:
450
- debugMessage (" Connected to Arduino IoT Cloud" , 0 );
444
+ debugMessage (DebugLevel::Error, " Connected to Arduino IoT Cloud" );
451
445
break ;
452
446
case IOT_STATUS_CLOUD_DISCONNECTED:
453
- debugMessage (" Disconnected from Arduino IoT Cloud" , 0 );
447
+ debugMessage (DebugLevel::Error, " Disconnected from Arduino IoT Cloud" );
454
448
break ;
455
449
}
456
450
iotStatus = _newState;
457
451
}
458
452
459
453
void ArduinoIoTCloudClass::printDebugInfo ()
460
454
{
461
- char msgBuffer[120 ];
462
- debugMessage (" ***** Arduino IoT Cloud - configuration info *****" , 2 );
463
- sprintf (msgBuffer, " Device ID: %s" , getDeviceId ().c_str ());
464
- debugMessage (msgBuffer, 2 );
465
- sprintf (msgBuffer, " Thing ID: %s" , getThingId ().c_str ());
466
- debugMessage (msgBuffer, 2 );
467
- sprintf (msgBuffer, " MQTT Broker: %s:%d" , _brokerAddress.c_str (), _brokerPort);
468
- debugMessage (msgBuffer, 2 );
455
+ debugMessage (DebugLevel::Info, " ***** Arduino IoT Cloud - configuration info *****" );
456
+ debugMessage (DebugLevel::Info, " Device ID: %s" , getDeviceId ().c_str ());
457
+ debugMessage (DebugLevel::Info, " Thing ID: %s" , getThingId ().c_str ());
458
+ debugMessage (DebugLevel::Info, " MQTT Broker: %s:%d" , _brokerAddress.c_str (), _brokerPort);
469
459
}
470
460
471
461
ArduinoIoTCloudClass ArduinoCloud;
0 commit comments