Skip to content
Closed
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
21 changes: 14 additions & 7 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -766,13 +766,18 @@
EventBits_t events = xEventGroupWaitBits(
mender_client_events, MENDER_CLIENT_EVENT_CONNECT | MENDER_CLIENT_EVENT_DISCONNECT | MENDER_CLIENT_EVENT_RESTART, pdTRUE, pdFALSE, portMAX_DELAY);
if (MENDER_CLIENT_EVENT_CONNECT == (events & MENDER_CLIENT_EVENT_CONNECT)) {
/* Connect to the network */
ESP_LOGI(TAG, "Connecting to the network");
if (ESP_OK != example_connect()) {
xEventGroupSetBits(mender_client_events, MENDER_CLIENT_EVENT_DISCONNECTED);
ESP_LOGE(TAG, "Unable to connect network");
if (!connected) {
/* Connect to the network */
ESP_LOGI(TAG, "Connecting to the network");
if (ESP_OK != example_connect()) {

Check failure on line 772 in main/main.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 3 if|for|do|while|switch statements.

See more on https://sonarcloud.io/project/issues?id=joelguittet_mender-esp32-example&issues=AZ1fPlkV7oj27A--t1Lo&open=AZ1fPlkV7oj27A--t1Lo&pullRequest=28
xEventGroupSetBits(mender_client_events, MENDER_CLIENT_EVENT_DISCONNECTED);
ESP_LOGE(TAG, "Unable to connect network");
} else {
connected = true;
xEventGroupSetBits(mender_client_events, MENDER_CLIENT_EVENT_CONNECTED);
ESP_LOGI(TAG, "Connected to the network");
}
} else {
connected = true;
xEventGroupSetBits(mender_client_events, MENDER_CLIENT_EVENT_CONNECTED);
ESP_LOGI(TAG, "Connected to the network");
}
Expand All @@ -782,7 +787,7 @@
/* Reconnection requested while not disconnected yet */
xEventGroupSetBits(mender_client_events, MENDER_CLIENT_EVENT_CONNECTED);
ESP_LOGI(TAG, "Connected to the network");
} else {
} else if (connected) {
/* Disconnect the network */
ESP_LOGI(TAG, "Disconnecting network");
if (ESP_OK != example_disconnect()) {
Expand All @@ -791,6 +796,8 @@
connected = false;
ESP_LOGI(TAG, "Disconnected of the network");
}
} else {
ESP_LOGW(TAG, "Already disconnected of the network");
}
}
if (MENDER_CLIENT_EVENT_RESTART == (events & MENDER_CLIENT_EVENT_RESTART)) {
Expand Down