Skip to content

Commit 0bb3a2b

Browse files
authored
Fixing issue with sketches missing a Topic name (i.e.: Getting Started) (#51)
* - handling empty `_shadowTopicIn` - preventing `_syncStatus` from being set to value other than `SYNC_STATUS_SYNCHRONIZED` when empty shadow topic * fix getting started problem * - applied fix suggestions by @ilcato * Fixed bracing style to K&R employed in the rest of the file * Moving initialisation of member variables with default values in constructor
1 parent adbc6c2 commit 0bb3a2b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/ArduinoIoTCloud.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ ArduinoIoTCloudClass::ArduinoIoTCloudClass() :
6363
_bearSslClient(NULL),
6464
_mqttClient (NULL),
6565
connection (NULL),
66+
_stdinTopic (""),
67+
_stdoutTopic (""),
68+
_shadowTopicOut (""),
69+
_shadowTopicIn (""),
70+
_dataTopicOut (""),
71+
_dataTopicIn (""),
72+
_otaTopic (""),
6673
_lastSyncRequestTickTime(0)
6774
{
6875
}
@@ -191,13 +198,14 @@ int ArduinoIoTCloudClass::connect()
191198
if (!_mqttClient->connect(_brokerAddress.c_str(), _brokerPort)) {
192199
return CONNECT_FAILURE;
193200
}
194-
195201
if(_mqttClient->subscribe(_stdinTopic ) == 0) return CONNECT_FAILURE_SUBSCRIBE;
196202
if(_mqttClient->subscribe(_dataTopicIn ) == 0) return CONNECT_FAILURE_SUBSCRIBE;
197-
if(_mqttClient->subscribe(_shadowTopicIn) == 0) return CONNECT_FAILURE_SUBSCRIBE;
203+
if(_shadowTopicIn != "") {
204+
if(_mqttClient->subscribe(_shadowTopicIn) == 0) return CONNECT_FAILURE_SUBSCRIBE;
198205

199-
_syncStatus = ArduinoIoTSynchronizationStatus::SYNC_STATUS_WAIT_FOR_CLOUD_VALUES;
200-
_lastSyncRequestTickTime = 0;
206+
_syncStatus = ArduinoIoTSynchronizationStatus::SYNC_STATUS_WAIT_FOR_CLOUD_VALUES;
207+
_lastSyncRequestTickTime = 0;
208+
}
201209

202210
return CONNECT_SUCCESS;
203211
}

0 commit comments

Comments
 (0)