Skip to content

Commit

Permalink
Reduced wait times at sereveral points, too reduce wait times
Browse files Browse the repository at this point in the history
  • Loading branch information
christof.strackSAG authored and christof.strackSAG committed Feb 15, 2020
1 parent 7e3f7ee commit 3055b4d
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 23 deletions.
7 changes: 4 additions & 3 deletions source/AppController.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ static void AppController_Setup(void * param1, uint32_t param2) {
#endif
}
//delay start
vTaskDelay(pdMS_TO_TICKS(4000));
vTaskDelay(pdMS_TO_TICKS(2000));


if (RETCODE_OK == retcode) {
Expand Down Expand Up @@ -440,7 +440,8 @@ Retcode_T AppController_SyncTime() {
vTaskDelay(pdMS_TO_TICKS(1500));
} while (0UL == sntpTimeStampFromServer && sntpAttemps < 3); // only try to sync time 3 times
if (0UL == sntpTimeStampFromServer) {
sntpTimeStampFromServer = 1572566400UL; // use default time 1. Nov 2019 00:00:00 UTC
//sntpTimeStampFromServer = 1572566400UL; // use default time 1. Nov 2019 00:00:00 UTC
sntpTimeStampFromServer = 1580515200UL; // use default time 1. Feb 2020 00:00:00 UTC
SNTP_SetTime(sntpTimeStampFromServer);
LOG_AT_WARNING(
("MQTTOperation: Using fixed timestamp 1. Nov 2019 00:00:00 UTC, SNTP sync not possible\r\n"));
Expand All @@ -463,7 +464,7 @@ void AppController_Init(void * cmdProcessorHandle, uint32_t param2) {
Retcode_T retcode = RETCODE_OK;
BCDS_UNUSED(param2);

vTaskDelay(pdMS_TO_TICKS(2000));
vTaskDelay(pdMS_TO_TICKS(1000));
LOG_AT_INFO(("AppController_Init: XDK System Startup\r\n"));

// start status LED indicator
Expand Down
2 changes: 1 addition & 1 deletion source/AppController.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ typedef enum {
#define DEFAULT_LIGHT true /**< Ambient Light Data Enable */
#define DEFAULT_NOISE false /**< Noise Data Enable */

#define REBOOT_DELAY 5000 /**< Delay reboot so that device can send back "reboot is in progress" */
#define REBOOT_DELAY 3000 /**< Delay reboot so that device can send back "reboot is in progress" */


/* Sensor type and macro definitions */
Expand Down
2 changes: 1 addition & 1 deletion source/MQTTOperation.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,14 +566,14 @@ static Retcode_T MQTTOperation_ValidateWLANConnectivity(bool force) {
retcode = MQTTOperation_SubscribeTopics();
}
}

if (RETCODE_OK != retcode) {
LOG_AT_ERROR(("MQTTOperation: MQTT connection to the broker failed, try again : [%hu] ... \r\n", connectAttemps ));
vTaskDelay(pdMS_TO_TICKS(3000));
} else {
//reset connection counter
connectAttemps = 0L;
}

}

// test if we have to reboot
Expand Down
57 changes: 40 additions & 17 deletions source/MQTTRegistration.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static xTimerHandle clientRegistrationTimerHandle = NULL; // timer handle for da
// Subscribe topics variables
static char appIncomingMsgTopicBuffer[SIZE_SMALL_BUF];/**< Incoming message topic buffer */
static char appIncomingMsgPayloadBuffer[SIZE_LARGE_BUF];/**< Incoming message payload buffer */

static uint16_t connectAttemps = 0UL;
static AssetDataBuffer assetStreamBuffer;

/* global variables ********************************************************* */
Expand Down Expand Up @@ -144,7 +144,7 @@ static void MQTTRegistration_ClientReceive(MQTT_SubscribeCBParam_TZ param) {
MQTTCfgParser_SetMqttUser(username);
MQTTCfgParser_SetMqttPassword(password);
MQTTCfgParser_FLWriteConfig();
MQTTRegistration_StartRestartTimer(REBOOT_DELAY);
MQTTRegistration_StartRestartTimer(2000);
}

}
Expand All @@ -156,7 +156,7 @@ static void MQTTRegistration_StartRestartTimer(int period) {
NULL, // optional identifier
MQTTRegistration_RestartCallback // static callback function
);
xTimerStart(timerHandle, MILLISECONDS(10));
xTimerStart(timerHandle, MILLISECONDS(5));
}

static void MQTTRegistration_RestartCallback(xTimerHandle xTimer) {
Expand Down Expand Up @@ -242,11 +242,18 @@ void MQTTRegistration_Init(MQTT_Setup_TZ MqttSetupInfo_P,
}

if (RETCODE_OK == retcode) {
retcode = MQTT_ConnectToBroker_Z(&MqttConnectInfo,
MQTT_CONNECT_TIMEOUT_IN_MS, &MqttCredentials);
if (RETCODE_OK != retcode) {
LOG_AT_ERROR(("MQTTRegistration: MQTT connection to the broker failed \n\r"));
}
/*Connect to mqtt broker */
do {
retcode = MQTT_ConnectToBroker_Z(&MqttConnectInfo,
MQTT_CONNECT_TIMEOUT_IN_MS, &MqttCredentials);
if (RETCODE_OK != retcode) {
LOG_AT_ERROR(
("MQTTRegistration: MQTT connection to the broker failed \n\r"));
connectAttemps++;
}
} while (RETCODE_OK != retcode && connectAttemps < 10);

connectAttemps = 0UL;
}

if (RETCODE_OK == retcode) {
Expand Down Expand Up @@ -303,6 +310,13 @@ static Retcode_T MQTTRegistration_ValidateWLANConnectivity(bool force) {

nwStatus = WlanNetworkConnect_GetIpStatus();
if (WLANNWCT_IPSTATUS_CT_AQRD != nwStatus || force) {

// increase connect attemps
connectAttemps = connectAttemps + 1;
// before resetting connection try to disconnect
// ignore return code
//retcode = Mqtt_DisconnectFromBroker_Z();
MQTTOperation_DeInit();
if (MqttSetupInfo.IsSecure == true) {
static bool isSntpDisabled = false;
if (false == isSntpDisabled) {
Expand All @@ -325,18 +339,27 @@ static Retcode_T MQTTRegistration_ValidateWLANConnectivity(bool force) {
if (RETCODE_OK == retcode) {
retcode = MQTT_ConnectToBroker_Z(&MqttConnectInfo,
MQTT_CONNECT_TIMEOUT_IN_MS, &MqttCredentials);
if (RETCODE_OK != retcode) {
LOG_AT_ERROR(("MQTTRegistration: MQTT connection to the broker failed\n\r"));
}
if (RETCODE_OK == retcode) {
retcode = MQTT_SubsribeToTopic_Z(&MqttSubscribeInfo,
MQTT_SUBSCRIBE_TIMEOUT_IN_MS); }
}

if (RETCODE_OK == retcode) {
retcode = MQTT_SubsribeToTopic_Z(&MqttSubscribeInfo,
MQTT_SUBSCRIBE_TIMEOUT_IN_MS);
if (RETCODE_OK != retcode) {
LOG_AT_ERROR(("MQTTRegistration: MQTT subscribe command failed\n\r"));
}
if (RETCODE_OK != retcode) {
LOG_AT_ERROR(("MQTTRegistration: MQTT connection to the broker failed, try again : [%hu] ... \r\n", connectAttemps ));
vTaskDelay(pdMS_TO_TICKS(3000));
} else {
//reset connection counter
connectAttemps = 0L;
}
}

// test if we have to reboot
if (connectAttemps > 10) {
LOG_AT_WARNING(("MQTTOperation: Now calling SoftReset and reboot to recover\r\n"));
//MQTTOperation_DeInit();
// wait one minute before reboot
vTaskDelay(pdMS_TO_TICKS(30000));
BSP_Board_SoftReset();
}
return retcode;
}
2 changes: 1 addition & 1 deletion source/MQTTRegistration.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#define MQTT_REGISTRATION_BROKERNAME "mqtt.cumulocity.com"
#define MQTT_REGISTRATION_USERNAME "management/devicebootstrap"
#define MQTT_REGISTRATION_PASSWORD "Fhdt1bb1f"
#define MQTT_REGISTRATION_TICKRATE 10000
#define MQTT_REGISTRATION_TICKRATE 2000

#define MILLISECONDS(x) ((portTickType) x / portTICK_RATE_MS)
#define SECONDS(x) ((portTickType) (x * 1000) / portTICK_RATE_MS)
Expand Down

0 comments on commit 3055b4d

Please sign in to comment.