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.
This commit is contained in:
parent
6a328992d7
commit
2ee1c6fd3e
4 changed files with 44 additions and 20 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue