From 2ee1c6fd3e880de60826822820d3ab211de8221c Mon Sep 17 00:00:00 2001 From: Anurag Kar Date: Fri, 8 Feb 2019 15:58:57 +0530 Subject: [PATCH] provisioning examples : typos fixed and minor change in timer callback execution Note : Examples have been updated to prevent invocation of bluedroid/wifi APIs from inside timer callback when stopping provisioning. Workaround is to spawn new task from inside the timer callback. --- .../provisioning/ble_prov/main/app_prov.c | 4 ++-- .../provisioning/console_prov/main/app_prov.c | 18 ++++++++++----- .../custom_config/main/app_prov.c | 20 ++++++++++++----- .../provisioning/softap_prov/main/app_prov.c | 22 +++++++++++++------ 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/examples/provisioning/ble_prov/main/app_prov.c b/examples/provisioning/ble_prov/main/app_prov.c index b574513ce..1f927dca8 100644 --- a/examples/provisioning/ble_prov/main/app_prov.c +++ b/examples/provisioning/ble_prov/main/app_prov.c @@ -188,7 +188,7 @@ esp_err_t app_prov_event_handler(void *ctx, system_event_t *event) case SYSTEM_EVENT_STA_GOT_IP: ESP_LOGI(TAG, "STA Got IP"); - /* Station got IP. That means configuraion is successful. + /* Station got IP. That means configuration is successful. * Schedule timer to stop provisioning app after 30 seconds. */ g_prov->wifi_state = WIFI_PROV_STA_CONNECTED; if (g_prov && g_prov->timer) { @@ -341,7 +341,7 @@ esp_err_t app_prov_start_ble_provisioning(int security, const protocomm_security return ESP_ERR_NO_MEM; } - /* Initialise app data */ + /* Initialize app data */ g_prov->pop = pop; g_prov->security = security; diff --git a/examples/provisioning/console_prov/main/app_prov.c b/examples/provisioning/console_prov/main/app_prov.c index 7eccb8b5f..83c4e4e05 100644 --- a/examples/provisioning/console_prov/main/app_prov.c +++ b/examples/provisioning/console_prov/main/app_prov.c @@ -101,8 +101,8 @@ static void app_prov_stop_service(void) protocomm_delete(g_prov->pc); } -/* Callback to be invoked by timer */ -static void _stop_prov_cb(void * arg) +/* Task spawned by timer callback */ +static void stop_prov_task(void * arg) { ESP_LOGI(TAG, "Stopping provisioning"); app_prov_stop_service(); @@ -116,6 +116,14 @@ static void _stop_prov_cb(void * arg) free(g_prov); g_prov = NULL; ESP_LOGI(TAG, "Provisioning stopped"); + + vTaskDelete(NULL); +} + +/* Callback to be invoked by timer */ +static void _stop_prov_cb(void * arg) +{ + xTaskCreate(&stop_prov_task, "stop_prov", 2048, NULL, tskIDLE_PRIORITY, NULL); } /* Event handler for starting/stopping provisioning. @@ -146,7 +154,7 @@ esp_err_t app_prov_event_handler(void *ctx, system_event_t *event) case SYSTEM_EVENT_STA_GOT_IP: ESP_LOGI(TAG, "STA Got IP"); - /* Station got IP. That means configuraion is successful. + /* Station got IP. That means configuration is successful. * Schedule timer to stop provisioning app after 30 seconds. */ g_prov->wifi_state = WIFI_PROV_STA_CONNECTED; if (g_prov && g_prov->timer) { @@ -299,7 +307,7 @@ esp_err_t app_prov_start_console_provisioning(int security, const protocomm_secu return ESP_ERR_NO_MEM; } - /* Initialise app data */ + /* Initialize app data */ g_prov->pop = pop; g_prov->security = security; @@ -308,7 +316,7 @@ esp_err_t app_prov_start_console_provisioning(int security, const protocomm_secu .callback = _stop_prov_cb, .arg = NULL, .dispatch_method = ESP_TIMER_TASK, - .name = "stop_softap_tm" + .name = "stop_console_tm" }; esp_err_t err = esp_timer_create(&timer_conf, &g_prov->timer); if (err != ESP_OK) { diff --git a/examples/provisioning/custom_config/main/app_prov.c b/examples/provisioning/custom_config/main/app_prov.c index 947ce3650..6ed3df19a 100644 --- a/examples/provisioning/custom_config/main/app_prov.c +++ b/examples/provisioning/custom_config/main/app_prov.c @@ -116,8 +116,8 @@ static void app_prov_stop_service(void) protocomm_delete(g_prov->pc); } -/* Callback to be invoked by timer */ -static void _stop_softap_cb(void * arg) +/* Task spawned by timer callback */ +static void stop_prov_task(void * arg) { ESP_LOGI(TAG, "Stopping provisioning"); app_prov_stop_service(); @@ -132,6 +132,14 @@ static void _stop_softap_cb(void * arg) free(g_prov); g_prov = NULL; ESP_LOGI(TAG, "Provisioning stopped"); + + vTaskDelete(NULL); +} + +/* Callback to be invoked by timer */ +static void _stop_prov_cb(void * arg) +{ + xTaskCreate(&stop_prov_task, "stop_prov", 2048, NULL, tskIDLE_PRIORITY, NULL); } /* Event handler for starting/stopping provisioning. @@ -162,7 +170,7 @@ esp_err_t app_prov_event_handler(void *ctx, system_event_t *event) case SYSTEM_EVENT_STA_GOT_IP: ESP_LOGI(TAG, "STA Got IP"); - /* Station got IP. That means configuraion is successful. + /* Station got IP. That means configuration is successful. * Schedule timer to stop provisioning app after 30 seconds. */ g_prov->wifi_state = WIFI_PROV_STA_CONNECTED; if (g_prov && g_prov->timer) { @@ -174,7 +182,7 @@ esp_err_t app_prov_event_handler(void *ctx, system_event_t *event) * to reconnect and get STA connection status from the device. * Otherwise, the AP will be turned off before the user can * reconnect and thus the user app will see connection timed out, - * signalling a failure in provisioning. */ + * signaling a failure in provisioning. */ esp_timer_start_once(g_prov->timer, 30000*1000U); } break; @@ -303,7 +311,7 @@ esp_err_t app_prov_configure_sta(wifi_config_t *wifi_cfg) static esp_err_t start_wifi_ap(const char *ssid, const char *pass) { - /* Initialise WiFi with default configuration */ + /* Initialize WiFi with default configuration */ wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); esp_err_t err = esp_wifi_init(&cfg); if (err != ESP_OK) { @@ -372,7 +380,7 @@ esp_err_t app_prov_start_softap_provisioning(const char *ssid, const char *pass, /* Create timer object as a member of app data */ esp_timer_create_args_t timer_conf = { - .callback = _stop_softap_cb, + .callback = _stop_prov_cb, .arg = NULL, .dispatch_method = ESP_TIMER_TASK, .name = "stop_softap_tm" diff --git a/examples/provisioning/softap_prov/main/app_prov.c b/examples/provisioning/softap_prov/main/app_prov.c index da0036f8d..79c1e0da0 100644 --- a/examples/provisioning/softap_prov/main/app_prov.c +++ b/examples/provisioning/softap_prov/main/app_prov.c @@ -102,8 +102,8 @@ static void app_prov_stop_service(void) protocomm_delete(g_prov->pc); } -/* Callback to be invoked by timer */ -static void _stop_softap_cb(void * arg) +/* Task spawned by timer callback */ +static void stop_prov_task(void * arg) { ESP_LOGI(TAG, "Stopping provisioning"); app_prov_stop_service(); @@ -118,6 +118,14 @@ static void _stop_softap_cb(void * arg) free(g_prov); g_prov = NULL; ESP_LOGI(TAG, "Provisioning stopped"); + + vTaskDelete(NULL); +} + +/* Callback to be invoked by timer */ +static void _stop_prov_cb(void * arg) +{ + xTaskCreate(&stop_prov_task, "stop_prov", 2048, NULL, tskIDLE_PRIORITY, NULL); } /* Event handler for starting/stopping provisioning. @@ -148,7 +156,7 @@ esp_err_t app_prov_event_handler(void *ctx, system_event_t *event) case SYSTEM_EVENT_STA_GOT_IP: ESP_LOGI(TAG, "STA Got IP"); - /* Station got IP. That means configuraion is successful. + /* Station got IP. That means configuration is successful. * Schedule timer to stop provisioning app after 30 seconds. */ g_prov->wifi_state = WIFI_PROV_STA_CONNECTED; if (g_prov && g_prov->timer) { @@ -160,7 +168,7 @@ esp_err_t app_prov_event_handler(void *ctx, system_event_t *event) * to reconnect and get STA connection status from the device. * Otherwise, the AP will be turned off before the user can * reconnect and thus the user app will see connection timed out, - * signalling a failure in provisioning. */ + * signaling a failure in provisioning. */ esp_timer_start_once(g_prov->timer, 30000*1000U); } break; @@ -290,7 +298,7 @@ esp_err_t app_prov_configure_sta(wifi_config_t *wifi_cfg) static esp_err_t start_wifi_ap(const char *ssid, const char *pass) { - /* Initialise WiFi with default configuration */ + /* Initialize WiFi with default configuration */ wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); esp_err_t err = esp_wifi_init(&cfg); if (err != ESP_OK) { @@ -353,13 +361,13 @@ esp_err_t app_prov_start_softap_provisioning(const char *ssid, const char *pass, return ESP_ERR_NO_MEM; } - /* Initialise app data */ + /* Initialize app data */ g_prov->pop = pop; g_prov->security = security; /* Create timer object as a member of app data */ esp_timer_create_args_t timer_conf = { - .callback = _stop_softap_cb, + .callback = _stop_prov_cb, .arg = NULL, .dispatch_method = ESP_TIMER_TASK, .name = "stop_softap_tm"