@@ -30,6 +30,11 @@ const static int compressedCertSlot = 10;
30
30
const static int serialNumberAndAuthorityKeyIdentifierSlot = 11 ;
31
31
const static int thingIdSlot = 12 ;
32
32
33
+ constexpr static int CONNECT_FAILURE_SUBSCRIBE = -1 ;
34
+ constexpr static int CONNECT_FAILURE = 0 ;
35
+ constexpr static int CONNECT_SUCCESS = 1 ;
36
+
37
+
33
38
static ConnectionManager *getTimeConnection = NULL ;
34
39
35
40
static unsigned long getTime () {
@@ -182,16 +187,23 @@ int ArduinoIoTCloudClass::connect()
182
187
// Username: device id
183
188
// Password: empty
184
189
if (!_mqttClient->connect (_brokerAddress.c_str (), _brokerPort)) {
185
- return 0 ;
190
+ return CONNECT_FAILURE;
191
+ }
192
+
193
+ bool is_subscribe_error = false ;
194
+
195
+ if (_mqttClient->subscribe (_stdinTopic ) == 0 ) is_subscribe_error = true ;
196
+ if (_mqttClient->subscribe (_dataTopicIn ) == 0 ) is_subscribe_error = true ;
197
+ if (_mqttClient->subscribe (_shadowTopicIn) == 0 ) is_subscribe_error = true ;
198
+
199
+ if (is_subscribe_error) {
200
+ return CONNECT_FAILURE_SUBSCRIBE;
186
201
}
187
- _mqttClient->subscribe (_stdinTopic);
188
- _mqttClient->subscribe (_dataTopicIn);
189
- _mqttClient->subscribe (_shadowTopicIn);
190
202
191
203
_syncStatus = ArduinoIoTSynchronizationStatus::SYNC_STATUS_WAIT_FOR_CLOUD_VALUES;
192
204
_lastSyncRequestTickTime = 0 ;
193
205
194
- return 1 ;
206
+ return CONNECT_SUCCESS ;
195
207
}
196
208
197
209
bool ArduinoIoTCloudClass::disconnect ()
@@ -402,15 +414,17 @@ void ArduinoIoTCloudClass::connectionCheck()
402
414
}
403
415
break ;
404
416
case IOT_STATUS_CLOUD_CONNECTING:
405
- int arduinoIoTConnectionAttempt;
406
- arduinoIoTConnectionAttempt = connect ();
407
- sprintf (msgBuffer, " ArduinoCloud.connect(): %d" , arduinoIoTConnectionAttempt);
417
+ int const ret_code_connect = connect ();
418
+ sprintf (msgBuffer, " ArduinoCloud.connect(): %d" , ret_code_connect);
408
419
debugMessage (msgBuffer, 4 );
409
- if (arduinoIoTConnectionAttempt == 1 ) {
420
+ if (ret_code_connect == CONNECT_SUCCESS ) {
410
421
setIoTConnectionState (IOT_STATUS_CLOUD_CONNECTED);
411
422
CloudSerial.begin (9600 );
412
423
CloudSerial.println (" Hello from Cloud Serial!" );
413
424
}
425
+ else if (ret_code_connect == CONNECT_FAILURE_SUBSCRIBE) {
426
+ Serial.println (" ERROR - Please verify your THING ID" );
427
+ }
414
428
#ifdef ARDUINO_ARCH_SAMD
415
429
unsigned long const epoch = getTime ();
416
430
if (epoch!=0 )
0 commit comments