Skip to content

Commit

Permalink
Merge pull request #23 from aqandu/failureFix/reconnecting
Browse files Browse the repository at this point in the history
Failure fix/reconnecting
  • Loading branch information
tbec authored Oct 4, 2019
2 parents 7cd6dd8 + c35fb48 commit 99efc75
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 15 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,32 @@ meaning just replace `portMAX_DELAY` with `1000 / portTICK_PERIOD_MS`. There's c
- Partition Table -> Partition Table (Factory app, two OTA definitions)
- Component Config -> FAT Filesystem support -> Long filename support (Long filename buffer in heap)

- Application Make menuconfig setup

Make menuconfig > AirU Configuration

CONFIG_MQTT_HOST="air.eng.utah.edu"

CONFIG_MQTT_USERNAME="<private>"

CONFIG_MQTT_PASSWORD="<private>"

CONFIG_INFLUX_MEASUREMENT_NAME="<private>"

CONFIG_MQTT_ROOT_TOPIC="<private>"

CONFIG_MQTT_DATA_PUB_TOPIC="<private>"

CONFIG_MQTT_SUB_ALL_TOPIC="<private>"

CONFIG_DATA_UPLOAD_PERIOD=60

CONFIG_USE_SD=y

CONFIG_SD_DATA_STORE=y

CONFIG_SD_CARD_DEBUG=y




4 changes: 3 additions & 1 deletion main/include/wifi_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ extern "C" {
#define JSON_MAC_ADR_SIZE 29
#define JSON_REG_INFO_SIZE (JSON_REG_NAME_SIZE + JSON_REG_EMAIL_SIZE + JSON_MAP_VIS_SIZE + JSON_MAC_ADR_SIZE)

/* Integer ERROR code definition */
#define ERR_WIFI_DISCONECTED -2


typedef enum update_reason_code_t {
Expand Down Expand Up @@ -326,7 +328,7 @@ bool wifi_manager_connected_to_access_point();
/**
* @brief Ping www.google.com. If successful, we have Internet.
*/
bool wifi_manager_check_connection();
int wifi_manager_check_connection();

/**
* @brief set bit to check internet connection with ping test
Expand Down
3 changes: 2 additions & 1 deletion main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ void data_task()
esp_app_desc_t *app_desc = esp_ota_get_app_description();

while (1) {
vTaskDelay(CONFIG_DATA_UPLOAD_PERIOD*1000 / portTICK_PERIOD_MS);

vTaskDelay(60000 / portTICK_PERIOD_MS);
PMS_Poll(&pm_dat);
Expand Down Expand Up @@ -293,7 +294,7 @@ void app_main()
/* Panic task */
xTaskCreate(&panic_task, "panic", 2096, NULL, 10, NULL);

vTaskDelay(1000/portTICK_PERIOD_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS); /* the initialization functions below need to wait until the event groups are created in the above tasks */

/*
* These initializations need to be after the tasks, because necessary mutexs get
Expand Down
2 changes: 1 addition & 1 deletion main/mqtt_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ static esp_err_t mqtt_event_handler(esp_mqtt_event_handle_t event)

case MQTT_EVENT_DISCONNECTED:
ESP_LOGI(TAG, "MQTT_EVENT_DISCONNECTED");
esp_mqtt_client_destroy(client);
client_connected = false;
esp_mqtt_client_destroy(client);

// Set the WIFI_MANAGER_HAVE_INTERNET_BIT: is it MQTT or internet problem?
wifi_manager_check_connection_async();
Expand Down
20 changes: 14 additions & 6 deletions main/wifi_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ void wifi_manager( void * pvParameters ){
wifi_manager_save_sta_config();

ESP_LOGI(TAG, "Got IP address, ping Google DNS 8.8.8.8 to test internet access");
if(wifi_manager_check_connection()){
if(wifi_manager_check_connection() == 1){
ESP_LOGI(TAG, "Ping success! Got internet access.");
xEventGroupClearBits(wifi_manager_event_group, WIFI_MANAGER_REQUEST_RECONNECT);
}
Expand Down Expand Up @@ -1015,10 +1015,18 @@ void wifi_manager( void * pvParameters ){

else if ((uxBits & WIFI_MANAGER_REQUEST_PING_TEST)){
ESP_LOGI(TAG, "WIFI_MANAGER_REQUEST_PING_TEST");
wifi_manager_check_connection();
if (wifi_manager_check_connection() == ERR_WIFI_DISCONECTED) {
wifi_manager_fetch_wifi_sta_config();
if(strlen((char*)wifi_manager_config_sta->sta.ssid) > 0) {
wifi_manager_connect_async();
} else {
ESP_LOGW(TAG, "%s: [%d] - Not going to automatically connect to wifi", __func__, __LINE__);
// Not going retry since... esp would stop working until the next reboot
// Do something else but retry connecting
}
}
xEventGroupClearBits(wifi_manager_event_group, WIFI_MANAGER_REQUEST_PING_TEST);
}

// else if ((uxBits & WIFI_MANAGER_REQUEST_RECONNECT))
// {
// xEventGroupClearBits(wifi_manager_event_group, WIFI_MANAGER_REQUEST_RECONNECT);
Expand Down Expand Up @@ -1114,7 +1122,7 @@ void wifi_manager_check_connection_async()
xEventGroupSetBits(wifi_manager_event_group, WIFI_MANAGER_REQUEST_PING_TEST);
}

bool wifi_manager_check_connection()
int wifi_manager_check_connection()
{
EventBits_t uxBits;
if(wifi_manager_connected_to_access_point()){
Expand All @@ -1123,7 +1131,7 @@ bool wifi_manager_check_connection()
wifi_manager_ping_test();

// Wait up to PING_TEST_TIMEOUT_MS for ping test callback to set WIFI_MANAGER_HAVE_INTERNET_BIT
bool ret = (WIFI_MANAGER_HAVE_INTERNET_BIT & \
int ret = (WIFI_MANAGER_HAVE_INTERNET_BIT & \
xEventGroupWaitBits(wifi_manager_event_group, WIFI_MANAGER_HAVE_INTERNET_BIT, pdFALSE, pdTRUE, MS2TICK(PING_TEST_TIMEOUT_MS)));

// Ping test failed. Start the reconnect timer
Expand All @@ -1145,6 +1153,6 @@ bool wifi_manager_check_connection()
return ret;
}
else{
return false;
return ERR_WIFI_DISCONECTED;
}
}
12 changes: 6 additions & 6 deletions sdkconfig.old
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR=
#
# Bootloader config
#
CONFIG_LOG_BOOTLOADER_LEVEL_NONE=
CONFIG_LOG_BOOTLOADER_LEVEL_NONE=y
CONFIG_LOG_BOOTLOADER_LEVEL_ERROR=
CONFIG_LOG_BOOTLOADER_LEVEL_WARN=
CONFIG_LOG_BOOTLOADER_LEVEL_INFO=y
CONFIG_LOG_BOOTLOADER_LEVEL_INFO=
CONFIG_LOG_BOOTLOADER_LEVEL_DEBUG=
CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE=
CONFIG_LOG_BOOTLOADER_LEVEL=3
CONFIG_LOG_BOOTLOADER_LEVEL=0
CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_8V=
CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V=y
CONFIG_BOOTLOADER_FACTORY_RESET=
Expand Down Expand Up @@ -456,13 +456,13 @@ CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y
#
# Log output
#
CONFIG_LOG_DEFAULT_LEVEL_NONE=
CONFIG_LOG_DEFAULT_LEVEL_NONE=y
CONFIG_LOG_DEFAULT_LEVEL_ERROR=
CONFIG_LOG_DEFAULT_LEVEL_WARN=
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
CONFIG_LOG_DEFAULT_LEVEL_INFO=
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=
CONFIG_LOG_DEFAULT_LEVEL_VERBOSE=
CONFIG_LOG_DEFAULT_LEVEL=3
CONFIG_LOG_DEFAULT_LEVEL=0
CONFIG_LOG_COLORS=y

#
Expand Down

0 comments on commit 99efc75

Please sign in to comment.