From e4aa3a628c0c6e2eaee194f2154c4f3017a2fc78 Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Tue, 21 Dec 2021 15:07:49 +0900 Subject: [PATCH] lte_awsiot: Fix error handling for lte_awsiot The previous code did not handle LTE termination when the AWS connection failed, so when lte_awsiot was run again after the AWS connection failed, it failed to initialize. Fixed this problem by changing the error handling of lte_awsiot. --- .../lte_awsiot/subscribe_publish_sample.c | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/examples/lte_awsiot/subscribe_publish_sample.c b/examples/lte_awsiot/subscribe_publish_sample.c index eb268baef..4a8302459 100644 --- a/examples/lte_awsiot/subscribe_publish_sample.c +++ b/examples/lte_awsiot/subscribe_publish_sample.c @@ -131,7 +131,7 @@ static void parseInputArgsForConnectParams(int argc, char **argv) { } -int main(int argc, char FAR **argv) +static int awsiot_main(int argc, FAR char *argv[]) { bool infinitePublishFlag = true; @@ -145,9 +145,6 @@ int main(int argc, char FAR **argv) IoT_Error_t rc = FAILURE; - if (app_awsiot_connect_to_lte()) - return ERROR; - AWS_IoT_Client client; IoT_Client_Init_Params mqttInitParams = iotClientInitParamsDefault; IoT_Client_Connect_Params connectParams = iotClientConnectParamsDefault; @@ -276,7 +273,22 @@ int main(int argc, char FAR **argv) } aws_iot_mqtt_disconnect(&client); - app_awsiot_disconnect_from_lte(); return rc; } + +int main(int argc, FAR char *argv[]) +{ + int ret = 0; + + if (app_awsiot_connect_to_lte()) + { + return ERROR; + } + + ret = awsiot_main(argc, argv); + + app_awsiot_disconnect_from_lte(); + + return ret; +}