@@ -40,7 +40,7 @@ static unsigned long getTime() {
4040 if (!getTimeConnection) return 0 ;
4141 unsigned long time = getTimeConnection->getTime ();
4242 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" );
4444 time = NTPUtils (getTimeConnection->getUDP ()).getTime ();
4545 }
4646 #ifdef ARDUINO_ARCH_SAMD
@@ -109,18 +109,18 @@ int ArduinoIoTCloudClass::begin(Client& net, String brokerAddress, uint16_t brok
109109 byte deviceIdBytes[72 ];
110110
111111 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." );
113113 return 0 ;
114114 }
115115
116116 if (!ECCX08.readSlot (deviceIdSlot, deviceIdBytes, sizeof (deviceIdBytes))) {
117- debugMessage (" Cryptography processor read failure." , 0 );
117+ debugMessage (DebugLevel::Error, " Cryptography processor read failure." );
118118 return 0 ;
119119 }
120120 _device_id = (char *)deviceIdBytes;
121121
122122 if (!ECCX08Cert.beginReconstruction (keySlot, compressedCertSlot, serialNumberAndAuthorityKeyIdentifierSlot)) {
123- debugMessage (" Cryptography certificate reconstruction failure." , 0 );
123+ debugMessage (DebugLevel::Error, " Cryptography certificate reconstruction failure." );
124124 return 0 ;
125125 }
126126
@@ -131,7 +131,7 @@ int ArduinoIoTCloudClass::begin(Client& net, String brokerAddress, uint16_t brok
131131 ECCX08Cert.setIssuerCommonName (" Arduino" );
132132
133133 if (!ECCX08Cert.endReconstruction ()) {
134- debugMessage (" Cryptography certificate reconstruction failure." , 0 );
134+ debugMessage (DebugLevel::Error, " Cryptography certificate reconstruction failure." );
135135 return 0 ;
136136 }
137137
@@ -386,49 +386,43 @@ void ArduinoIoTCloudClass::connectionCheck()
386386 }
387387 }
388388
389- char msgBuffer[120 ];
390-
391-
392389 switch (iotStatus) {
393390 case IOT_STATUS_CLOUD_IDLE:
394391 setIoTConnectionState (IOT_STATUS_CLOUD_CONNECTING);
395392 break ;
396393 case IOT_STATUS_CLOUD_ERROR:
397- debugMessage (" Cloud Error. Retrying..." , 0 );
394+ debugMessage (DebugLevel::Error, " Cloud Error. Retrying..." );
398395 setIoTConnectionState (IOT_STATUS_CLOUD_RECONNECTING);
399396 break ;
400397 case IOT_STATUS_CLOUD_CONNECTED:
401- debugMessage ( " ." , 4 , false , true );
398+ debugMessageNoTimestamp (DebugLevel::Verbose, " ." );
402399 if (!_mqttClient->connected ()){
403400 setIoTConnectionState (IOT_STATUS_CLOUD_DISCONNECTED);
404401 }
405402 break ;
406403 case IOT_STATUS_CLOUD_DISCONNECTED:
407404 setIoTConnectionState (IOT_STATUS_CLOUD_RECONNECTING);
408405 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) {
415410 setIoTConnectionState (IOT_STATUS_CLOUD_CONNECTED);
416411 CloudSerial.begin (9600 );
417412 CloudSerial.println (" Hello from Cloud Serial!" );
418413 }
414+ }
419415 break ;
420416 case IOT_STATUS_CLOUD_CONNECTING:
421417 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);
424419 if (ret_code_connect == CONNECT_SUCCESS) {
425420 setIoTConnectionState (IOT_STATUS_CLOUD_CONNECTED);
426421 CloudSerial.begin (9600 );
427422 CloudSerial.println (" Hello from Cloud Serial!" );
428423 }
429424 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" );
432426 }
433427 break ;
434428 }
@@ -438,34 +432,30 @@ void ArduinoIoTCloudClass::setIoTConnectionState(ArduinoIoTConnectionStatus _new
438432{
439433 switch (_newState){
440434 case IOT_STATUS_CLOUD_ERROR:
441- debugMessage (" Arduino, we have a problem." , 0 );
435+ debugMessage (DebugLevel::Error, " Arduino, we have a problem." );
442436 break ;
443437 case IOT_STATUS_CLOUD_CONNECTING:
444- debugMessage (" Connecting to Arduino IoT Cloud..." , 0 );
438+ debugMessage (DebugLevel::Error, " Connecting to Arduino IoT Cloud..." );
445439 break ;
446440 case IOT_STATUS_CLOUD_RECONNECTING:
447- debugMessage (" Reconnecting to Arduino IoT Cloud..." , 0 );
441+ debugMessage (DebugLevel::Error, " Reconnecting to Arduino IoT Cloud..." );
448442 break ;
449443 case IOT_STATUS_CLOUD_CONNECTED:
450- debugMessage (" Connected to Arduino IoT Cloud" , 0 );
444+ debugMessage (DebugLevel::Error, " Connected to Arduino IoT Cloud" );
451445 break ;
452446 case IOT_STATUS_CLOUD_DISCONNECTED:
453- debugMessage (" Disconnected from Arduino IoT Cloud" , 0 );
447+ debugMessage (DebugLevel::Error, " Disconnected from Arduino IoT Cloud" );
454448 break ;
455449 }
456450 iotStatus = _newState;
457451}
458452
459453void ArduinoIoTCloudClass::printDebugInfo ()
460454{
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);
469459}
470460
471461ArduinoIoTCloudClass ArduinoCloud;
0 commit comments