Skip to content

Const cleanup #487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions src/AIoTC_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,24 @@
* CONSTANTS
******************************************************************************/

#define AIOT_CONFIG_INTERVAL_RETRY_DELAY_ms (10000UL)
#define AIOT_CONFIG_RECONNECTION_RETRY_DELAY_ms (1000UL)
#define AIOT_CONFIG_MAX_RECONNECTION_RETRY_DELAY_ms (32000UL)
#define AIOT_CONFIG_DEVICE_TOPIC_SUBSCRIBE_RETRY_DELAY_ms (2000UL)
#define AIOT_CONFIG_MAX_DEVICE_TOPIC_SUBSCRIBE_RETRY_DELAY_ms (32000UL)
#define AIOT_CONFIG_DEVICE_TOPIC_MAX_RETRY_CNT (10UL)
#define AIOT_CONFIG_DEVICE_TOPIC_ATTACH_RETRY_DELAY_ms (20000UL)
#define AIOT_CONFIG_MAX_DEVICE_TOPIC_ATTACH_RETRY_DELAY_ms (1280000UL)
#define AIOT_CONFIG_THING_TOPICS_SUBSCRIBE_RETRY_DELAY_ms (1000UL)
#define AIOT_CONFIG_THING_TOPICS_SUBSCRIBE_MAX_RETRY_CNT (10UL)
#define AIOT_CONFIG_TIMEOUT_FOR_LASTVALUES_SYNC_ms (30000UL)
#define AIOT_CONFIG_LASTVALUES_SYNC_MAX_RETRY_CNT (10UL)

#define AIOT_CONFIG_RP2040_OTA_HTTP_HEADER_RECEIVE_TIMEOUT_ms (10*1000UL)
#define AIOT_CONFIG_RP2040_OTA_HTTP_DATA_RECEIVE_TIMEOUT_ms (4*60*1000UL)
#if defined(HAS_LORA)
#define AIOT_CONFIG_LPWAN_UPDATE_RETRY_DELAY_ms (10000UL)
#endif

#if defined(HAS_TCP)
#define AIOT_CONFIG_RECONNECTION_RETRY_DELAY_ms (1000UL)
#define AIOT_CONFIG_MAX_RECONNECTION_RETRY_DELAY_ms (32000UL)

#define AIOT_CONFIG_THING_ID_REQUEST_RETRY_DELAY_ms (2000UL)
#define AIOT_CONFIG_MAX_THING_ID_REQUEST_RETRY_DELAY_ms (32000UL)
#define AIOT_CONFIG_THING_ID_REQUEST_MAX_RETRY_CNT (10UL)

#define AIOT_CONFIG_DEVICE_REGISTERED_RETRY_DELAY_k (10UL)
#define AIOT_CONFIG_MAX_DEVICE_REGISTERED_RETRY_DELAY_k (4UL)

#define AIOT_CONFIG_TIMEOUT_FOR_LASTVALUES_SYNC_ms (30000UL)
#define AIOT_CONFIG_LASTVALUES_SYNC_MAX_RETRY_CNT (10UL)
#endif

#define AIOT_CONFIG_LIB_VERSION "2.0.3"

Expand Down
16 changes: 9 additions & 7 deletions src/ArduinoIoTCloudDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ _registered(false) {
}

void ArduinoCloudDevice::begin() {
_attachAttempt.begin(AIOT_CONFIG_DEVICE_TOPIC_SUBSCRIBE_RETRY_DELAY_ms,
AIOT_CONFIG_MAX_DEVICE_TOPIC_SUBSCRIBE_RETRY_DELAY_ms);
_attachAttempt.begin(AIOT_CONFIG_THING_ID_REQUEST_RETRY_DELAY_ms,
AIOT_CONFIG_MAX_THING_ID_REQUEST_RETRY_DELAY_ms);
}

void ArduinoCloudDevice::update() {
Expand Down Expand Up @@ -93,8 +93,8 @@ void ArduinoCloudDevice::handleMessage(Message *m) {

ArduinoCloudDevice::State ArduinoCloudDevice::handleInit() {
/* Reset attempt struct for the nex retry after disconnection */
_attachAttempt.begin(AIOT_CONFIG_DEVICE_TOPIC_SUBSCRIBE_RETRY_DELAY_ms,
AIOT_CONFIG_MAX_DEVICE_TOPIC_SUBSCRIBE_RETRY_DELAY_ms);
_attachAttempt.begin(AIOT_CONFIG_THING_ID_REQUEST_RETRY_DELAY_ms,
AIOT_CONFIG_MAX_THING_ID_REQUEST_RETRY_DELAY_ms);

_attached = false;
_registered = false;
Expand All @@ -120,7 +120,7 @@ ArduinoCloudDevice::State ArduinoCloudDevice::handleSendCapabilities() {

ArduinoCloudDevice::State ArduinoCloudDevice::handleConnected() {
/* Max retry than disconnect */
if (_attachAttempt.getRetryCount() > AIOT_CONFIG_DEVICE_TOPIC_MAX_RETRY_CNT) {
if (_attachAttempt.getRetryCount() > AIOT_CONFIG_THING_ID_REQUEST_MAX_RETRY_CNT) {
return State::Disconnected;
}

Expand All @@ -130,8 +130,10 @@ ArduinoCloudDevice::State ArduinoCloudDevice::handleConnected() {
* counter, but recompute delay.
* Wait: 4s -> 80s -> 160s -> 320s -> 640s -> 1280s -> 1280s ...
*/
_attachAttempt.reconfigure(AIOT_CONFIG_DEVICE_TOPIC_ATTACH_RETRY_DELAY_ms,
AIOT_CONFIG_MAX_DEVICE_TOPIC_ATTACH_RETRY_DELAY_ms);
_attachAttempt.reconfigure(AIOT_CONFIG_THING_ID_REQUEST_RETRY_DELAY_ms *
AIOT_CONFIG_DEVICE_REGISTERED_RETRY_DELAY_k,
AIOT_CONFIG_MAX_THING_ID_REQUEST_RETRY_DELAY_ms *
AIOT_CONFIG_MAX_DEVICE_REGISTERED_RETRY_DELAY_k);
}
return State::SendCapabilities;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ArduinoIoTCloudLPWAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ArduinoIoTCloudLPWAN::ArduinoIoTCloudLPWAN()
: _state{State::ConnectPhy}
, _retryEnable{false}
, _maxNumRetry{5}
, _intervalRetry{AIOT_CONFIG_INTERVAL_RETRY_DELAY_ms}
, _intervalRetry{AIOT_CONFIG_LPWAN_UPDATE_RETRY_DELAY_ms}
, _thing_property_container()
, _last_checked_property_index{0}
{
Expand Down
3 changes: 0 additions & 3 deletions src/ArduinoIoTCloudTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,6 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_ConnectMqttBroker()
/* Subscribe to message topic to receive commands */
_mqttClient.subscribe(_messageTopicIn);

/* Reconfigure timers for next state */
_connection_attempt.begin(AIOT_CONFIG_DEVICE_TOPIC_SUBSCRIBE_RETRY_DELAY_ms, AIOT_CONFIG_MAX_DEVICE_TOPIC_SUBSCRIBE_RETRY_DELAY_ms);

DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s connected to %s:%d", __FUNCTION__, _brokerAddress.c_str(), _brokerPort);
return State::Connected;
}
Expand Down
Loading