feat(esp_wifi): Add support of Network Introduction Protocol in DPP
This commit is contained in:
@@ -3,24 +3,24 @@
|
||||
|
||||
# Device Provisioning Protocol (Enrollee) Example
|
||||
|
||||
This example shows how to configure ESP32 as an enrollee using Device Provisioning Protocol(DPP) also known as Wi-Fi Easy Connect.
|
||||
This example shows how to configure ESP devices as an enrollee using Device Provisioning Protocol(DPP) also known as Wi-Fi Easy Connect.
|
||||
|
||||
DPP provides a simple and secure way to onboard ESP32 to a network.
|
||||
We now support Responder-Enrollee mode of DPP with PSK mode of authentication.
|
||||
DPP provides a simple and secure way to onboard ESP devices to a network.
|
||||
We now support DPP in Responder-Enrollee mode with AKM types PSK and DPP.
|
||||
|
||||
You need a Wi-Fi Easy Connect with Initiator mode capable device to make use of this example. Some Android 10+ devices have this capability. (Vendor specific)
|
||||
|
||||
To run the example with an Android 10+ device follow below steps -
|
||||
1. Compile and flash the example on ESP32, a QR code will appear on your console.
|
||||
1. Compile and flash the example on ESP device, a QR code will appear on your console.
|
||||
2. Connect your phone to the network, say named "Example-AP".
|
||||
3. Now go to Settings->WiFi & Internet->Wi-Fi->Example-AP->Advanced->Add Device.
|
||||
4. Scan QR Code using the scanner, which will make ESP32 connect to Example-AP.
|
||||
4. Scan QR Code using the scanner, which will make ESP device connect to Example-AP.
|
||||
|
||||
Optional configuration available
|
||||
|
||||
*Note:*
|
||||
- QR Code should be displayed as dark on a white/light background to work properly.
|
||||
- If displayed QR Code had line gaps, try switching to a new font or a diiferent Terminal program. See below QR Code for for checking beforehand.
|
||||
- If displayed QR Code had line gaps, try switching to a new font or a different Terminal program. See below QR Code for checking beforehand.
|
||||
|
||||
### Example output
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "nvs_flash.h"
|
||||
#include "qrcode.h"
|
||||
|
||||
#ifdef CONFIG_ESP_DPP_LISTEN_CHANNEL
|
||||
#ifdef CONFIG_ESP_DPP_LISTEN_CHANNEL_LIST
|
||||
#define EXAMPLE_DPP_LISTEN_CHANNEL_LIST CONFIG_ESP_DPP_LISTEN_CHANNEL_LIST
|
||||
#else
|
||||
#define EXAMPLE_DPP_LISTEN_CHANNEL_LIST "6"
|
||||
@@ -49,6 +49,7 @@ static EventGroupHandle_t s_dpp_event_group;
|
||||
#define DPP_CONNECTED_BIT BIT0
|
||||
#define DPP_CONNECT_FAIL_BIT BIT1
|
||||
#define DPP_AUTH_FAIL_BIT BIT2
|
||||
#define WIFI_MAX_RETRY_NUM 3
|
||||
|
||||
static void event_handler(void *arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void *event_data)
|
||||
@@ -57,7 +58,7 @@ static void event_handler(void *arg, esp_event_base_t event_base,
|
||||
ESP_ERROR_CHECK(esp_supp_dpp_start_listen());
|
||||
ESP_LOGI(TAG, "Started listening for DPP Authentication");
|
||||
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
|
||||
if (s_retry_num < 5) {
|
||||
if (s_retry_num < WIFI_MAX_RETRY_NUM) {
|
||||
esp_wifi_connect();
|
||||
s_retry_num++;
|
||||
ESP_LOGI(TAG, "retry to connect to the AP");
|
||||
@@ -65,6 +66,8 @@ static void event_handler(void *arg, esp_event_base_t event_base,
|
||||
xEventGroupSetBits(s_dpp_event_group, DPP_CONNECT_FAIL_BIT);
|
||||
}
|
||||
ESP_LOGI(TAG, "connect to the AP fail");
|
||||
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_CONNECTED) {
|
||||
ESP_LOGI(TAG, "Successfully connected to the AP ssid : %s ", s_dpp_wifi_config.sta.ssid);
|
||||
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
|
||||
ip_event_got_ip_t *event = (ip_event_got_ip_t *) event_data;
|
||||
ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
|
||||
@@ -86,10 +89,8 @@ void dpp_enrollee_event_cb(esp_supp_dpp_event_t event, void *data)
|
||||
break;
|
||||
case ESP_SUPP_DPP_CFG_RECVD:
|
||||
memcpy(&s_dpp_wifi_config, data, sizeof(s_dpp_wifi_config));
|
||||
esp_wifi_set_config(ESP_IF_WIFI_STA, &s_dpp_wifi_config);
|
||||
ESP_LOGI(TAG, "DPP Authentication successful, connecting to AP : %s",
|
||||
s_dpp_wifi_config.sta.ssid);
|
||||
s_retry_num = 0;
|
||||
esp_wifi_set_config(ESP_IF_WIFI_STA, &s_dpp_wifi_config);
|
||||
esp_wifi_connect();
|
||||
break;
|
||||
case ESP_SUPP_DPP_FAIL:
|
||||
@@ -155,9 +156,9 @@ void dpp_enrollee_init(void)
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
ESP_ERROR_CHECK(esp_supp_dpp_init(dpp_enrollee_event_cb));
|
||||
ESP_ERROR_CHECK(dpp_enrollee_bootstrap());
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
|
||||
/* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum
|
||||
|
||||
Reference in New Issue
Block a user