mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
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
f3a6c63920
commit
f4f3b6088a
@ -188,7 +188,7 @@ esp_err_t app_prov_event_handler(void *ctx, system_event_t *event)
|
|||||||
|
|
||||||
case SYSTEM_EVENT_STA_GOT_IP:
|
case SYSTEM_EVENT_STA_GOT_IP:
|
||||||
ESP_LOGI(TAG, "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. */
|
* Schedule timer to stop provisioning app after 30 seconds. */
|
||||||
g_prov->wifi_state = WIFI_PROV_STA_CONNECTED;
|
g_prov->wifi_state = WIFI_PROV_STA_CONNECTED;
|
||||||
if (g_prov && g_prov->timer) {
|
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;
|
return ESP_ERR_NO_MEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialise app data */
|
/* Initialize app data */
|
||||||
g_prov->pop = pop;
|
g_prov->pop = pop;
|
||||||
g_prov->security = security;
|
g_prov->security = security;
|
||||||
|
|
||||||
|
@ -101,8 +101,8 @@ static void app_prov_stop_service(void)
|
|||||||
protocomm_delete(g_prov->pc);
|
protocomm_delete(g_prov->pc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Callback to be invoked by timer */
|
/* Task spawned by timer callback */
|
||||||
static void _stop_prov_cb(void * arg)
|
static void stop_prov_task(void * arg)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "Stopping provisioning");
|
ESP_LOGI(TAG, "Stopping provisioning");
|
||||||
app_prov_stop_service();
|
app_prov_stop_service();
|
||||||
@ -116,6 +116,14 @@ static void _stop_prov_cb(void * arg)
|
|||||||
free(g_prov);
|
free(g_prov);
|
||||||
g_prov = NULL;
|
g_prov = NULL;
|
||||||
ESP_LOGI(TAG, "Provisioning stopped");
|
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.
|
/* 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:
|
case SYSTEM_EVENT_STA_GOT_IP:
|
||||||
ESP_LOGI(TAG, "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. */
|
* Schedule timer to stop provisioning app after 30 seconds. */
|
||||||
g_prov->wifi_state = WIFI_PROV_STA_CONNECTED;
|
g_prov->wifi_state = WIFI_PROV_STA_CONNECTED;
|
||||||
if (g_prov && g_prov->timer) {
|
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;
|
return ESP_ERR_NO_MEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialise app data */
|
/* Initialize app data */
|
||||||
g_prov->pop = pop;
|
g_prov->pop = pop;
|
||||||
g_prov->security = security;
|
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,
|
.callback = _stop_prov_cb,
|
||||||
.arg = NULL,
|
.arg = NULL,
|
||||||
.dispatch_method = ESP_TIMER_TASK,
|
.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);
|
esp_err_t err = esp_timer_create(&timer_conf, &g_prov->timer);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
|
@ -116,8 +116,8 @@ static void app_prov_stop_service(void)
|
|||||||
protocomm_delete(g_prov->pc);
|
protocomm_delete(g_prov->pc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Callback to be invoked by timer */
|
/* Task spawned by timer callback */
|
||||||
static void _stop_softap_cb(void * arg)
|
static void stop_prov_task(void * arg)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "Stopping provisioning");
|
ESP_LOGI(TAG, "Stopping provisioning");
|
||||||
app_prov_stop_service();
|
app_prov_stop_service();
|
||||||
@ -132,6 +132,14 @@ static void _stop_softap_cb(void * arg)
|
|||||||
free(g_prov);
|
free(g_prov);
|
||||||
g_prov = NULL;
|
g_prov = NULL;
|
||||||
ESP_LOGI(TAG, "Provisioning stopped");
|
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.
|
/* 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:
|
case SYSTEM_EVENT_STA_GOT_IP:
|
||||||
ESP_LOGI(TAG, "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. */
|
* Schedule timer to stop provisioning app after 30 seconds. */
|
||||||
g_prov->wifi_state = WIFI_PROV_STA_CONNECTED;
|
g_prov->wifi_state = WIFI_PROV_STA_CONNECTED;
|
||||||
if (g_prov && g_prov->timer) {
|
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.
|
* to reconnect and get STA connection status from the device.
|
||||||
* Otherwise, the AP will be turned off before the user can
|
* Otherwise, the AP will be turned off before the user can
|
||||||
* reconnect and thus the user app will see connection timed out,
|
* 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);
|
esp_timer_start_once(g_prov->timer, 30000*1000U);
|
||||||
}
|
}
|
||||||
break;
|
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)
|
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();
|
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||||
esp_err_t err = esp_wifi_init(&cfg);
|
esp_err_t err = esp_wifi_init(&cfg);
|
||||||
if (err != ESP_OK) {
|
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 */
|
/* Create timer object as a member of app data */
|
||||||
esp_timer_create_args_t timer_conf = {
|
esp_timer_create_args_t timer_conf = {
|
||||||
.callback = _stop_softap_cb,
|
.callback = _stop_prov_cb,
|
||||||
.arg = NULL,
|
.arg = NULL,
|
||||||
.dispatch_method = ESP_TIMER_TASK,
|
.dispatch_method = ESP_TIMER_TASK,
|
||||||
.name = "stop_softap_tm"
|
.name = "stop_softap_tm"
|
||||||
|
@ -102,8 +102,8 @@ static void app_prov_stop_service(void)
|
|||||||
protocomm_delete(g_prov->pc);
|
protocomm_delete(g_prov->pc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Callback to be invoked by timer */
|
/* Task spawned by timer callback */
|
||||||
static void _stop_softap_cb(void * arg)
|
static void stop_prov_task(void * arg)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "Stopping provisioning");
|
ESP_LOGI(TAG, "Stopping provisioning");
|
||||||
app_prov_stop_service();
|
app_prov_stop_service();
|
||||||
@ -118,6 +118,14 @@ static void _stop_softap_cb(void * arg)
|
|||||||
free(g_prov);
|
free(g_prov);
|
||||||
g_prov = NULL;
|
g_prov = NULL;
|
||||||
ESP_LOGI(TAG, "Provisioning stopped");
|
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.
|
/* 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:
|
case SYSTEM_EVENT_STA_GOT_IP:
|
||||||
ESP_LOGI(TAG, "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. */
|
* Schedule timer to stop provisioning app after 30 seconds. */
|
||||||
g_prov->wifi_state = WIFI_PROV_STA_CONNECTED;
|
g_prov->wifi_state = WIFI_PROV_STA_CONNECTED;
|
||||||
if (g_prov && g_prov->timer) {
|
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.
|
* to reconnect and get STA connection status from the device.
|
||||||
* Otherwise, the AP will be turned off before the user can
|
* Otherwise, the AP will be turned off before the user can
|
||||||
* reconnect and thus the user app will see connection timed out,
|
* 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);
|
esp_timer_start_once(g_prov->timer, 30000*1000U);
|
||||||
}
|
}
|
||||||
break;
|
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)
|
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();
|
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||||
esp_err_t err = esp_wifi_init(&cfg);
|
esp_err_t err = esp_wifi_init(&cfg);
|
||||||
if (err != ESP_OK) {
|
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;
|
return ESP_ERR_NO_MEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialise app data */
|
/* Initialize app data */
|
||||||
g_prov->pop = pop;
|
g_prov->pop = pop;
|
||||||
g_prov->security = security;
|
g_prov->security = security;
|
||||||
|
|
||||||
/* Create timer object as a member of app data */
|
/* Create timer object as a member of app data */
|
||||||
esp_timer_create_args_t timer_conf = {
|
esp_timer_create_args_t timer_conf = {
|
||||||
.callback = _stop_softap_cb,
|
.callback = _stop_prov_cb,
|
||||||
.arg = NULL,
|
.arg = NULL,
|
||||||
.dispatch_method = ESP_TIMER_TASK,
|
.dispatch_method = ESP_TIMER_TASK,
|
||||||
.name = "stop_softap_tm"
|
.name = "stop_softap_tm"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user