Skip to content

Commit dee3570

Browse files
committed
Remove WaitDeviceConfig state
1 parent f04f0b0 commit dee3570

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

src/ArduinoIoTCloudTCP.cpp

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ void ArduinoIoTCloudTCP::update()
270270
case State::ConnectMqttBroker: next_state = handle_ConnectMqttBroker(); break;
271271
case State::SendDeviceProperties: next_state = handle_SendDeviceProperties(); break;
272272
case State::SubscribeDeviceTopic: next_state = handle_SubscribeDeviceTopic(); break;
273-
case State::WaitDeviceConfig: next_state = handle_WaitDeviceConfig(); break;
274273
case State::CheckDeviceConfig: next_state = handle_CheckDeviceConfig(); break;
275274
case State::SubscribeThingTopics: next_state = handle_SubscribeThingTopics(); break;
276275
case State::RequestLastValues: next_state = handle_RequestLastValues(); break;
@@ -366,18 +365,21 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SendDeviceProperties()
366365
DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s announce device to the Cloud %d", __FUNCTION__, _time_service.getTime());
367366
/* TODO check if write fails */
368367
sendDevicePropertiesToCloud();
369-
return State::WaitDeviceConfig;
368+
return State::SubscribeDeviceTopic;
370369
}
371370

372-
ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_WaitDeviceConfig()
371+
ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SubscribeDeviceTopic()
373372
{
374373
if (!_mqttClient.connected())
375374
{
376375
return State::Disconnect;
377376
}
378377

379378
bool const is_retry_attempt = (_last_device_subscribe_cnt > 0);
380-
if (is_retry_attempt && (millis() > _next_device_subscribe_attempt_tick))
379+
if (is_retry_attempt && (millis() < _next_device_subscribe_attempt_tick))
380+
return State::SubscribeDeviceTopic;
381+
382+
if (is_retry_attempt)
381383
{
382384
/* Configuration not received or device not attached to a valid thing. Try to resubscribe */
383385
if (_mqttClient.unsubscribe(_deviceTopicIn))
@@ -386,19 +388,6 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_WaitDeviceConfig()
386388
}
387389
}
388390

389-
if (!is_retry_attempt || (is_retry_attempt && (millis() > _next_device_subscribe_attempt_tick)))
390-
return State::SubscribeDeviceTopic;
391-
392-
return State::WaitDeviceConfig;
393-
}
394-
395-
ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SubscribeDeviceTopic()
396-
{
397-
if (!_mqttClient.connected())
398-
{
399-
return State::Disconnect;
400-
}
401-
402391
DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s request device configuration %d", __FUNCTION__, _time_service.getTime());
403392

404393
if (!_mqttClient.subscribe(_deviceTopicIn))
@@ -423,7 +412,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SubscribeDeviceTopic()
423412
_next_device_subscribe_attempt_tick = millis() + subscribe_retry_delay;
424413
DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s %d next configuration request in %d ms", __FUNCTION__, _last_device_subscribe_cnt, subscribe_retry_delay);
425414

426-
return State::WaitDeviceConfig;
415+
return State::SubscribeDeviceTopic;
427416
}
428417

429418
ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_CheckDeviceConfig()
@@ -445,7 +434,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_CheckDeviceConfig()
445434
_next_device_subscribe_attempt_tick = millis() + attach_retry_delay;
446435

447436
DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s device not attached, next configuration request in %d ms", __FUNCTION__, attach_retry_delay);
448-
return State::WaitDeviceConfig;
437+
return State::SubscribeDeviceTopic;
449438
}
450439

451440
DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s device attached to a new valid thing_id %s %d", __FUNCTION__, getThingId().c_str(), _time_service.getTime());
@@ -657,6 +646,7 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
657646
/* Topic for OTA properties and device configuration */
658647
if (_deviceTopicIn == topic) {
659648
CBORDecoder::decode(_device_property_container, (uint8_t*)bytes, length);
649+
_last_device_subscribe_cnt = 0;
660650
_state = State::CheckDeviceConfig;
661651
}
662652

src/ArduinoIoTCloudTCP.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass
113113
ConnectMqttBroker,
114114
SendDeviceProperties,
115115
SubscribeDeviceTopic,
116-
WaitDeviceConfig,
117116
CheckDeviceConfig,
118117
SubscribeThingTopics,
119118
RequestLastValues,
@@ -199,7 +198,6 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass
199198
State handle_SyncTime();
200199
State handle_ConnectMqttBroker();
201200
State handle_SendDeviceProperties();
202-
State handle_WaitDeviceConfig();
203201
State handle_CheckDeviceConfig();
204202
State handle_SubscribeDeviceTopic();
205203
State handle_SubscribeThingTopics();

0 commit comments

Comments
 (0)