mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-03 03:31:41 +03:00
component: Remove wifi_provisioning component and esp_prov tool
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps
|
||||
|
||||
examples/provisioning/wifi_prov_mgr:
|
||||
disable:
|
||||
- if: SOC_WIFI_SUPPORTED != 1
|
||||
disable_test:
|
||||
- if: IDF_TARGET != "esp32"
|
||||
temporary: true
|
||||
reason: lack of runners
|
||||
@@ -1,26 +0,0 @@
|
||||
# Provisioning Application Examples
|
||||
|
||||
This primarily consists of a single unified example wifi_prov_mgr
|
||||
|
||||
* wifi_prov_mgr
|
||||
Abstracts out most of the complexity of Wi-Fi provisioning and allows easy switching between the SoftAP (using HTTP) and BLE transports. It also demonstrates how applications can register and use additional custom data endpoints.
|
||||
|
||||
Provisioning applications are available for various platforms:
|
||||
|
||||
* Android:
|
||||
- [BLE Provisioning app on Play Store](https://play.google.com/store/apps/details?id=com.espressif.provble).
|
||||
- [SoftAP Provisioning app on Play Store](https://play.google.com/store/apps/details?id=com.espressif.provsoftap).
|
||||
- Source code on GitHub: [esp-idf-provisioning-android](https://github.com/espressif/esp-idf-provisioning-android).
|
||||
* iOS:
|
||||
- [BLE Provisioning app on app store](https://apps.apple.com/in/app/esp-ble-provisioning/id1473590141)
|
||||
- [SoftAP Provisioning app on app Store](https://apps.apple.com/in/app/esp-softap-provisioning/id1474040630)
|
||||
- Source code on GitHub: [esp-idf-provisioning-ios](https://github.com/espressif/esp-idf-provisioning-ios)
|
||||
* For all other platforms a python based command line tool is provided under "$IDF_PATH/tools/esp_prov"
|
||||
|
||||
The Android and iOS provisioning applications allow the user to configure the device manually or by scanning a QR code. QR codes can be generated by any online QR code generator. QR code payload is encoded with a JSON string containing the device name, proof-of-possession key (if used) and transport type (BLE or softAP), for example:
|
||||
|
||||
```
|
||||
{"ver":"v1","name":"PROV_000318","pop":"a1000318","transport":"softap"}
|
||||
```
|
||||
|
||||
The more details about QR code format, you can refer to [QR Code Scan](https://github.com/espressif/esp-idf-provisioning-android#qr-code-scan).
|
||||
@@ -1,8 +0,0 @@
|
||||
# The following lines of boilerplate have to be in your project's CMakeLists
|
||||
# in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
# "Trim" the build. Include the minimal set of components, main, and anything it depends on.
|
||||
idf_build_set_property(MINIMAL_BUILD ON)
|
||||
project(wifi_prov_mgr)
|
||||
@@ -1,461 +0,0 @@
|
||||
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-S2 | ESP32-S3 |
|
||||
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | -------- |
|
||||
|
||||
# Wi-Fi Provisioning Manager Example
|
||||
|
||||
(See the README.md file in the upper level 'examples' directory for more information about examples.)
|
||||
|
||||
`wifi_prov_mgr` example demonstrates the usage of `wifi_provisioning` manager component for building a provisioning application.
|
||||
|
||||
For this example, BLE is chosen as the default mode of transport, over which the provisioning related communication is to take place. NimBLE has been configured as the default host, but you can also switch to Bluedroid using menuconfig -> Components -> Bluetooth -> Bluetooth Host.
|
||||
|
||||
> Note: Since ESP32-S2 does not support BLE, the SoftAP will be the default mode of transport in that case. Even for ESP32, you can change to SoftAP transport from menuconfig.
|
||||
|
||||
In the provisioning process the device is configured as a Wi-Fi station with specified credentials. Once configured, the device will retain the Wi-Fi configuration, until a flash erase is performed.
|
||||
|
||||
Right after provisioning is complete, BLE is turned off and disabled to free the memory used by the BLE stack. Though, that is specific to this example, and the user can choose to keep BLE stack intact in their own application.
|
||||
|
||||
`wifi_prov_mgr` uses the following components :
|
||||
* `wifi_provisioning` : provides manager, data structures and protocomm endpoint handlers for Wi-Fi configuration
|
||||
* `protocomm` : for protocol based communication and secure session establishment
|
||||
* `protobuf` : Google's protocol buffer library for serialization of protocomm data structures
|
||||
* `bt` : ESP32 BLE stack for transport of protobuf packets
|
||||
|
||||
This example can be used, as it is, for adding a provisioning service to any application intended for IoT.
|
||||
|
||||
> Note: If you use this example code in your own project, in BLE mode, then remember to enable the BT stack and BTDM BLE control settings in your SDK configuration (e.g. by using the `sdkconfig.defaults` file from this project).
|
||||
|
||||
## Transports
|
||||
|
||||
### SoftAP Transport
|
||||
- After successful provisioning, the SoftAP connection is not disconnected by default
|
||||
- Users can directly reconnect to the device for reprovisioning
|
||||
- It's the user's responsibility to manage connection memory and handle it according to application requirements
|
||||
- **HTTP**: `POST http://<server_name>:<port>/prov-ctrl`
|
||||
|
||||
### BLE Transport
|
||||
- By default, BT memory is released after successful provisioning
|
||||
- To keep BLE active after provisioning, enable `WIFI_PROV_KEEP_BLE_ON_AFTER_PROV` in menuconfig
|
||||
- This configuration ensures that BLE advertising is continued even after provisioning is completed.
|
||||
- For both SoftAP and BLE transports:
|
||||
- Enable `EXAMPLE_REPROVISIONING` in menuconfig to allow reprovisioning
|
||||
- Use the `esp_prov.py` tool for reprovisioning
|
||||
- Call `wifi_prov_mgr_disable_auto_stop()` API before initiating reprovisioning (already called in this example)
|
||||
- **BLE**: `GATT` characteristic for protocomm communication
|
||||
|
||||
**NOTE: The underlying transport (HTTP/BLE) must be kept enabled for external commands to be processed**.
|
||||
|
||||
## Reprovisioning
|
||||
|
||||
The example supports reprovisioning of Wi-Fi credentials through both SoftAP and BLE transports. Here are the key considerations for each transport:
|
||||
|
||||
### Commands
|
||||
|
||||
**Internal API**: `wifi_prov_mgr_reset_sm_state_for_reprovision()`
|
||||
- This API is can be called internally by the device firmware to reset WiFi credentials and restart provisioning mode.
|
||||
- For demonstration purposes, this API has been called directly in firmware code, In real-world scenarios following command based reprovisioning is preferred.
|
||||
|
||||
**External Command**:
|
||||
- **Endpoint**: `prov-ctrl`
|
||||
- **Command**: `TypeCmdCtrlReprov` (protobuf)
|
||||
- **Transport**: HTTP/BLE as configured
|
||||
- External clients (like Phone apps) can send this command via the transport layer to trigger the reprovisioning.
|
||||
|
||||
**Usage from esp_prov.py**:
|
||||
```bash
|
||||
python esp_prov.py --transport ble --service_name "PROV_DEVICE" --reprov
|
||||
```
|
||||
|
||||
### Use Cases for Reprovisioning
|
||||
|
||||
This flexibility is particularly useful when:
|
||||
- Network credentials need to be updated (password changes, SSID changes)
|
||||
- Device needs to connect to a different network environment
|
||||
- Troubleshooting connectivity issues requires fresh credential configuration
|
||||
- Moving devices between different locations with different network setups
|
||||
|
||||
For more details on the provisioning process and APIs, refer to the [Wi-Fi Provisioning Manager component documentation](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/provisioning/wifi_provisioning.html).
|
||||
|
||||
|
||||
## How to use example
|
||||
|
||||
### Hardware Required
|
||||
|
||||
Example should be able to run on any commonly available ESP32/ESP32-S2 development board.
|
||||
|
||||
### Application Required
|
||||
|
||||
Provisioning applications are available for various platforms. See below
|
||||
|
||||
#### Platform : Android
|
||||
|
||||
For Android, a provisioning application along with source code is available on GitHub : [esp-idf-provisioning-android](https://github.com/espressif/esp-idf-provisioning-android)
|
||||
|
||||
#### Platform : iOS
|
||||
|
||||
For iOS, a provisioning application along with source code is available on GitHub : [esp-idf-provisioning-ios](https://github.com/espressif/esp-idf-provisioning-ios)
|
||||
|
||||
#### Platform : Linux / Windows / macOS
|
||||
|
||||
To install the dependency packages needed, please refer to the top level [README file](../../README.md#running-test-python-script-pytest).
|
||||
|
||||
`esp_prov` supports BLE and SoftAP transport for Linux, MacOS and Windows platforms. For BLE, however, if dependencies are not met, the script falls back to console mode and requires another application through which the communication can take place. The `esp_prov` console will guide you through the provisioning process of locating the correct BLE GATT services and characteristics, the values to write, and input read values.
|
||||
|
||||
### Configure the project
|
||||
|
||||
```
|
||||
idf.py menuconfig
|
||||
```
|
||||
* Set the BLE/Soft AP transport under "Example Configuration" options. ESP32-S2 will have only SoftAP option (SoftAP option cannot be used if IPv4 is disabled in lwIP)
|
||||
|
||||
### Build and Flash
|
||||
|
||||
Build the project and flash it to the board, then run monitor tool to view serial output:
|
||||
|
||||
```
|
||||
idf.py -p PORT flash monitor
|
||||
```
|
||||
|
||||
(To exit the serial monitor, type ``Ctrl-]``.)
|
||||
|
||||
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
|
||||
|
||||
## Example Output
|
||||
|
||||
```
|
||||
I (445) app: Starting provisioning
|
||||
I (1035) app: Provisioning started
|
||||
I (1045) wifi_prov_mgr: Provisioning started with service name : PROV_261FCC
|
||||
```
|
||||
|
||||
Make sure to note down the BLE device name (starting with `PROV_`) displayed in the serial monitor log (eg. PROV_261FCC). This will depend on the MAC ID and will be unique for every device.
|
||||
|
||||
In a separate terminal run the `esp_prov.py` script under `$IDP_PATH/tools/esp_prov` directory (make sure to replace `myssid` and `mypassword` with the credentials of the AP to which the device is supposed to connect to after provisioning). Assuming default example configuration, which uses the protocomm security scheme 1 with PoP-based (proof-of-possession) authentication :
|
||||
|
||||
```
|
||||
python esp_prov.py --transport ble --service_name PROV_261FCC --sec_ver 1 --pop abcd1234 --ssid myssid --passphrase mypassword
|
||||
```
|
||||
|
||||
For security version 2, the following command can be used:
|
||||
```
|
||||
python esp_prov.py --transport ble --service_name PROV_261FCC --sec_ver 2 --sec2_username wifiprov --sec2_pwd abcd1234 --ssid myssid --passphrase mypassword
|
||||
```
|
||||
|
||||
Above command will perform the provisioning steps, and the monitor log should display something like this :
|
||||
|
||||
```
|
||||
I (39725) app: Received Wi-Fi credentials
|
||||
SSID : myssid
|
||||
Password : mypassword
|
||||
.
|
||||
.
|
||||
.
|
||||
I (45335) esp_netif_handlers: sta ip: 192.168.43.243, mask: 255.255.255.0, gw: 192.168.43.1
|
||||
I (45345) app: Provisioning successful
|
||||
I (45345) app: Connected with IP Address:192.168.43.243
|
||||
I (46355) app: Hello World!
|
||||
I (47355) app: Hello World!
|
||||
I (48355) app: Hello World!
|
||||
I (49355) app: Hello World!
|
||||
.
|
||||
.
|
||||
.
|
||||
I (52315) wifi_prov_mgr: Provisioning stopped
|
||||
.
|
||||
.
|
||||
.
|
||||
I (52355) app: Hello World!
|
||||
I (53355) app: Hello World!
|
||||
I (54355) app: Hello World!
|
||||
I (55355) app: Hello World!
|
||||
```
|
||||
|
||||
**Note:** For generating the credentials for security version 2 (`SRP6a` salt and verifier) for the device-side, the following example command can be used. The output can then directly be used in this example.
|
||||
|
||||
The config option `CONFIG_EXAMPLE_PROV_SEC2_DEV_MODE` should be enabled for the example and in `main/app_main.c`, the macro `EXAMPLE_PROV_SEC2_USERNAME` should be set to the same username used in the salt-verifier generation.
|
||||
|
||||
```log
|
||||
$ python esp_prov.py --transport softap --sec_ver 2 --sec2_gen_cred --sec2_username wifiprov --sec2_pwd abcd1234
|
||||
==== Salt-verifier for security scheme 2 (SRP6a) ====
|
||||
static const char sec2_salt[] = {
|
||||
0x03, 0x6e, 0xe0, 0xc7, 0xbc, 0xb9, 0xed, 0xa8, 0x4c, 0x9e, 0xac, 0x97, 0xd9, 0x3d, 0xec, 0xf4
|
||||
};
|
||||
|
||||
static const char sec2_verifier[] = {
|
||||
0x7c, 0x7c, 0x85, 0x47, 0x65, 0x08, 0x94, 0x6d, 0xd6, 0x36, 0xaf, 0x37, 0xd7, 0xe8, 0x91, 0x43,
|
||||
0x78, 0xcf, 0xfd, 0x61, 0x6c, 0x59, 0xd2, 0xf8, 0x39, 0x08, 0x12, 0x72, 0x38, 0xde, 0x9e, 0x24,
|
||||
.
|
||||
.
|
||||
.
|
||||
0xe6, 0xf6, 0x53, 0xc8, 0x31, 0xa8, 0x78, 0xde, 0x50, 0x40, 0xf7, 0x62, 0xde, 0x36, 0xb2, 0xba
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
### QR Code Scanning
|
||||
|
||||
Enabling `CONFIG_EXAMPLE_PROV_SHOW_QR` will display a QR code on the serial terminal, which can be scanned from the ESP Provisioning phone apps to start the Wi-Fi provisioning process.
|
||||
|
||||
The monitor log should display something like this :
|
||||
|
||||
```
|
||||
I (1462) app: Provisioning started
|
||||
I (1472) app: Scan this QR code from the provisioning application for Provisioning.
|
||||
I (1472) QRCODE: Encoding below text with ECC LVL 0 & QR Code Version 10
|
||||
I (1482) QRCODE: {"ver":"v1","name":"PROV_EA69FC","pop":"abcd1234","transport":"ble"}
|
||||
GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=256 adv_itvl_max=256
|
||||
|
||||
█▀▀▀▀▀█ ▀▀▀█▄█ ▀▀▄ █▄ ▀ █▀▀▀▀▀█
|
||||
█ ███ █ ▀▄█ █▄ ▀▄█ ▄██ █ █ ███ █
|
||||
█ ▀▀▀ █ ▄▀█▀▄▀ ▀█▄▀ ██ █ ▀▀▀ █
|
||||
▀▀▀▀▀▀▀ █▄▀ █▄█▄█ ▀ █ █ ▀ ▀▀▀▀▀▀▀
|
||||
▀▀ ▀▀ ▀ ▀▄ ▀▄ ▄▀▀▀█ ▀▄ ▀ ▀▄▄ ▄▄▀
|
||||
███▄█▄▀ █▀ ▀▀▀▀▄▄█ █▀ █ ▄█▄█▀
|
||||
▀███▀ ▀▄▄██ ▄▄██▄ ▀▀▀▀ ▄▀█ ▀▄▄▀
|
||||
▄███ ▀██▀▀ ▄ ▄█▄▀▀█▄ ▀▄▀▄▄█ ▄
|
||||
▀█▀ █▄▀▀ ▀▀█▀▀ █▀▄▀▄▀ ▄█ ███▄ ██
|
||||
██▀█ ▀▄█ █▄▀▄███▀▄▀█ ▀█ █▀▀ ▀▄▄▀
|
||||
█▄▀▄█▀▀ ▀▄ ▀▄▄█▄▀▀█▄█▄█▀▀█ ▀▄ ▄▀
|
||||
█ ▄█▄ ▀ ▄▀ █▄ ▀█▄█▄▀▀█▀█ ▄█ ▀▄▄█
|
||||
▀▀▀▀ ▀ █▀█▀▀▄▄██▄█▀█ ▀██▀▀▀█▄▄▀
|
||||
█▀▀▀▀▀█ ▄█▀▀▀██ ▄▀▄ █▄█ ▀ █ ▄ ▄
|
||||
█ ███ █ █ ▀▄█▀▀█▀▄█▄▄ ▀██▀▀▀▀▄▄▀▀
|
||||
█ ▀▀▀ █ ▄█ ▀ ▄█▀█ █▀ ▀▀███▄▀█ █▄█
|
||||
▀▀▀▀▀▀▀ ▀ ▀ ▀▀ ▀ ▀▀▀▀▀▀
|
||||
|
||||
|
||||
I (1702) app: If QR code is not visible, copy paste the below URL in a browser.
|
||||
https://espressif.github.io/esp-jumpstart/qrcode.html?data={"ver":"v1","name":"PROV_EA69FC","pop":"abcd1234","transport":"ble"}
|
||||
```
|
||||
|
||||
|
||||
### Wi-Fi Scanning
|
||||
|
||||
Provisioning manager also supports providing real-time Wi-Fi scan results (performed on the device) during provisioning. This allows the client side applications to choose the AP for which the device Wi-Fi station is to be configured. Various information about the visible APs is available, like signal strength (RSSI) and security type, etc. Also, the manager now provides capabilities information which can be used by client applications to determine the security type and availability of specific features (like `wifi_scan`).
|
||||
|
||||
When using the scan based provisioning, we don't need to specify the `--ssid` and `--passphrase` fields explicitly:
|
||||
|
||||
```
|
||||
python esp_prov.py --transport ble --service_name PROV_261FCC --pop abcd1234
|
||||
```
|
||||
|
||||
See below the sample output from `esp_prov` tool on running above command:
|
||||
|
||||
```
|
||||
Connecting...
|
||||
Connected
|
||||
Getting Services...
|
||||
Security scheme determined to be : 1
|
||||
|
||||
==== Starting Session ====
|
||||
==== Session Established ====
|
||||
|
||||
==== Scanning Wi-Fi APs ====
|
||||
++++ Scan process executed in 1.9967520237 sec
|
||||
++++ Scan results : 5
|
||||
|
||||
++++ Scan finished in 2.7374596596 sec
|
||||
==== Wi-Fi Scan results ====
|
||||
S.N. SSID BSSID CHN RSSI AUTH
|
||||
[ 1] MyHomeWiFiAP 788a20841996 1 -45 WPA2_PSK
|
||||
[ 2] MobileHotspot 7a8a20841996 11 -46 WPA2_PSK
|
||||
[ 3] MyHomeWiFiAP 788a208daa26 11 -54 WPA2_PSK
|
||||
[ 4] NeighborsWiFiAP 8a8a20841996 6 -61 WPA2_PSK
|
||||
[ 5] InsecureWiFiAP dca4caf1227c 7 -74 Open
|
||||
|
||||
Select AP by number (0 to rescan) : 1
|
||||
Enter passphrase for MyHomeWiFiAP :
|
||||
|
||||
==== Sending Wi-Fi Credentials to Target ====
|
||||
==== Wi-Fi Credentials sent successfully ====
|
||||
|
||||
==== Applying Wi-Fi Config to Target ====
|
||||
==== Apply config sent successfully ====
|
||||
|
||||
==== Wi-Fi connection state ====
|
||||
==== WiFi state: Connected ====
|
||||
==== Provisioning was successful ====
|
||||
```
|
||||
|
||||
### Interactive Provisioning
|
||||
|
||||
`esp_prov` supports interactive provisioning. You can trigger the script with a simplified command and input the necessary details
|
||||
(`Proof-of-possession` for security scheme 1 and `SRP6a username`, `SRP6a password` for security scheme 2) as the provisioning process advances.
|
||||
|
||||
The command `python esp_prov.py --transport ble --sec_ver 1` gives out the following sample output:
|
||||
|
||||
```
|
||||
Discovering...
|
||||
==== BLE Discovery results ====
|
||||
S.N. Name Address
|
||||
[ 1] PROV_4C33E8 01:02:03:04:05:06
|
||||
[ 1] BT_DEVICE_SBC 0A:0B:0C:0D:0E:0F
|
||||
Select device by number (0 to rescan) : 1
|
||||
Connecting...
|
||||
Getting Services...
|
||||
Proof of Possession required:
|
||||
|
||||
==== Starting Session ====
|
||||
==== Session Established ====
|
||||
|
||||
==== Scanning Wi-Fi APs ====
|
||||
++++ Scan process executed in 3.8695244789123535 sec
|
||||
++++ Scan results : 2
|
||||
|
||||
++++ Scan finished in 4.4132080078125 sec
|
||||
==== Wi-Fi Scan results ====
|
||||
S.N. SSID BSSID CHN RSSI AUTH
|
||||
[ 1] MyHomeWiFiAP 788a20841996 1 -45 WPA2_PSK
|
||||
[ 2] MobileHotspot 7a8a20841996 11 -46 WPA2_PSK
|
||||
|
||||
Select AP by number (0 to rescan) : 1
|
||||
Enter passphrase for myssid :
|
||||
|
||||
==== Sending Wi-Fi Credentials to Target ====
|
||||
==== Wi-Fi Credentials sent successfully ====
|
||||
|
||||
==== Applying Wi-Fi Config to Target ====
|
||||
==== Apply config sent successfully ====
|
||||
|
||||
==== Wi-Fi connection state ====
|
||||
==== WiFi state: Connected ====
|
||||
==== Provisioning was successful ====
|
||||
```
|
||||
|
||||
### Sending Custom Data
|
||||
|
||||
The provisioning manager allows applications to send some custom data during provisioning, which may be
|
||||
required for some other operations like connecting to some cloud service. This is achieved by creating
|
||||
and registering additional endpoints using the below APIs
|
||||
|
||||
```
|
||||
wifi_prov_mgr_endpoint_create();
|
||||
wifi_prov_mgr_endpoint_register();
|
||||
```
|
||||
|
||||
In this particular example, we have added an endpoint named "custom-data" which can be tested
|
||||
by passing the `--custom_data <MyCustomData>` option to the esp\_prov tool. Following output is
|
||||
expected on success:
|
||||
|
||||
```
|
||||
==== Sending Custom data to esp32 ====
|
||||
CustomData response: SUCCESS
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Provisioning failed
|
||||
|
||||
It is possible that the Wi-Fi credentials provided were incorrect, or the device was not able to establish connection to the network, in which the the `esp_prov` script will notify failure (with reason). Serial monitor log will display the failure along with disconnect reason :
|
||||
|
||||
```
|
||||
E (367015) app: Provisioning failed!
|
||||
Reason : Wi-Fi AP password incorrect
|
||||
Please reset to factory and retry provisioning
|
||||
```
|
||||
|
||||
Once credentials have been applied, even though wrong credentials were provided, the device will no longer go into provisioning mode on subsequent reboots until NVS is erased (see following section).
|
||||
|
||||
### Provisioning does not start
|
||||
|
||||
If the serial monitor log shows the following :
|
||||
|
||||
```
|
||||
I (465) app: Already provisioned, starting Wi-Fi STA
|
||||
```
|
||||
|
||||
it means either the device has been provisioned earlier with or without success (e.g. scenario covered in above section), or that the Wi-Fi credentials were already set by some other application flashed previously onto your device. On setting the log level to DEBUG this is clearly evident :
|
||||
|
||||
```
|
||||
D (455) wifi_prov_mgr: Found Wi-Fi SSID : myssid
|
||||
D (465) wifi_prov_mgr: Found Wi-Fi Password : m********d
|
||||
I (465) app: Already provisioned, starting Wi-Fi STA
|
||||
```
|
||||
|
||||
To fix this we simple need to erase the NVS partition from flash. First we need to find out its address and size. This can be seen from the monitor log on the top right after reboot.
|
||||
|
||||
```
|
||||
I (47) boot: Partition Table:
|
||||
I (50) boot: ## Label Usage Type ST Offset Length
|
||||
I (58) boot: 0 nvs WiFi data 01 02 00009000 00006000
|
||||
I (65) boot: 1 phy_init RF data 01 01 0000f000 00001000
|
||||
I (73) boot: 2 factory factory app 00 00 00010000 00124f80
|
||||
I (80) boot: End of partition table
|
||||
```
|
||||
|
||||
Now erase NVS partition by running the following commands :
|
||||
|
||||
```
|
||||
$IDF_PATH/components/esptool_py/esptool/esptool.py erase_region 0x9000 0x6000
|
||||
```
|
||||
|
||||
### Bluetooth Pairing Request during provisioning
|
||||
|
||||
ESP-IDF now has functionality to enforce link encryption requirement while performing GATT write on characteristics of provisioning service. This will however result in a pairing pop-up dialog, if link is not encrypted. This feature is disabled by default. In order to enable this feature, please set `CONFIG_WIFI_PROV_BLE_FORCE_ENCRYPTION=y` in the sdkconfig or select the configuration using "idf.py menuconfig" .
|
||||
|
||||
```
|
||||
Component Config --> Wi-Fi Provisioning Manager --> Force Link Encryption during Characteristic Read/Write
|
||||
|
||||
```
|
||||
Recompiling the application with above changes should suffice to enable this functionality.
|
||||
|
||||
|
||||
### Unsupported platform
|
||||
|
||||
If the platform requirement, for running `esp_prov` is not satisfied, then the script execution will fallback to console mode, in which case the full process (involving user inputs) will look like this :
|
||||
|
||||
```
|
||||
==== Esp_Prov Version: v1.0 ====
|
||||
BLE client is running in console mode
|
||||
This could be due to your platform not being supported or dependencies not being met
|
||||
Please ensure all pre-requisites are met to run the full fledged client
|
||||
BLECLI >> Please connect to BLE device `PROV_261FCC` manually using your tool of choice
|
||||
BLECLI >> Was the device connected successfully? [y/n] y
|
||||
BLECLI >> List available attributes of the connected device
|
||||
BLECLI >> Is the service UUID '0000ffff-0000-1000-8000-00805f9b34fb' listed among available attributes? [y/n] y
|
||||
BLECLI >> Is the characteristic UUID '0000ff53-0000-1000-8000-00805f9b34fb' listed among available attributes? [y/n] y
|
||||
BLECLI >> Is the characteristic UUID '0000ff51-0000-1000-8000-00805f9b34fb' listed among available attributes? [y/n] y
|
||||
BLECLI >> Is the characteristic UUID '0000ff52-0000-1000-8000-00805f9b34fb' listed among available attributes? [y/n] y
|
||||
|
||||
==== Verifying protocol version ====
|
||||
BLECLI >> Write following data to characteristic with UUID '0000ff53-0000-1000-8000-00805f9b34fb' :
|
||||
>> 56302e31
|
||||
BLECLI >> Enter data read from characteristic (in hex) :
|
||||
<< 53554343455353
|
||||
==== Verified protocol version successfully ====
|
||||
|
||||
==== Starting Session ====
|
||||
BLECLI >> Write following data to characteristic with UUID '0000ff51-0000-1000-8000-00805f9b34fb' :
|
||||
>> 10015a25a201220a20ae6d9d5d1029f8c366892252d2d5a0ffa7ce1ee5829312545dd5f2aba057294d
|
||||
BLECLI >> Enter data read from characteristic (in hex) :
|
||||
<< 10015a390801aa0134122048008bfc365fad4753dc75912e0c764d60749cb26dd609595b6fbc72e12614031a1089733af233c7448e7d7fb7963682c6d8
|
||||
BLECLI >> Write following data to characteristic with UUID '0000ff51-0000-1000-8000-00805f9b34fb' :
|
||||
>> 10015a270802b2012212204051088dc294fe4621fac934a8ea22e948fcc3e8ac458aac088ce705c65dbfb9
|
||||
BLECLI >> Enter data read from characteristic (in hex) :
|
||||
<< 10015a270803ba01221a20c8d38059d5206a3d92642973ac6ba8ac2f6ecf2b7a3632964eb35a0f20133adb
|
||||
==== Session Established ====
|
||||
|
||||
==== Sending Wifi credential to esp32 ====
|
||||
BLECLI >> Write following data to characteristic with UUID '0000ff52-0000-1000-8000-00805f9b34fb' :
|
||||
>> 98471ac4019a46765c28d87df8c8ae71c1ae6cfe0bc9c615bc6d2c
|
||||
BLECLI >> Enter data read from characteristic (in hex) :
|
||||
<< 3271f39a
|
||||
==== Wifi Credentials sent successfully ====
|
||||
|
||||
==== Applying config to esp32 ====
|
||||
BLECLI >> Write following data to characteristic with UUID '0000ff52-0000-1000-8000-00805f9b34fb' :
|
||||
>> 5355
|
||||
BLECLI >> Enter data read from characteristic (in hex) :
|
||||
<< 1664db24
|
||||
==== Apply config sent successfully ====
|
||||
|
||||
==== Wifi connection state ====
|
||||
BLECLI >> Write following data to characteristic with UUID '0000ff52-0000-1000-8000-00805f9b34fb' :
|
||||
>> 290d
|
||||
BLECLI >> Enter data read from characteristic (in hex) :
|
||||
<< 505f72a9f8521025c1964d7789c4d7edc56aedebd144e1b667bc7c0975757b80cc091aa9f3e95b06eaefbc30290fa1
|
||||
++++ WiFi state: connected ++++
|
||||
==== Provisioning was successful ====
|
||||
```
|
||||
|
||||
The write data is to be copied from the console output ```>>``` to the platform specific application and the data read from the application is to be pasted at the user input prompt ```<<``` of the console, in the format (hex) indicated in above sample log.
|
||||
@@ -1,3 +0,0 @@
|
||||
idf_component_register(SRCS "app_main.c"
|
||||
PRIV_REQUIRES esp_wifi nvs_flash wifi_provisioning
|
||||
INCLUDE_DIRS ".")
|
||||
@@ -1,114 +0,0 @@
|
||||
menu "Example Configuration"
|
||||
|
||||
choice EXAMPLE_PROV_TRANSPORT
|
||||
bool "Provisioning Transport"
|
||||
default EXAMPLE_PROV_TRANSPORT_SOFTAP if IDF_TARGET_ESP32S2
|
||||
default EXAMPLE_PROV_TRANSPORT_BLE
|
||||
help
|
||||
Wi-Fi provisioning component offers both, SoftAP and BLE transports. Choose any one.
|
||||
|
||||
config EXAMPLE_PROV_TRANSPORT_BLE
|
||||
bool "BLE"
|
||||
select BT_ENABLED
|
||||
depends on !IDF_TARGET_ESP32S2
|
||||
config EXAMPLE_PROV_TRANSPORT_SOFTAP
|
||||
bool "Soft AP"
|
||||
select LWIP_IPV4
|
||||
endchoice
|
||||
|
||||
choice EXAMPLE_PROV_SECURITY_VERSION
|
||||
bool "Protocomm security version"
|
||||
default EXAMPLE_PROV_SECURITY_VERSION_2
|
||||
help
|
||||
Wi-Fi provisioning component offers 3 security versions.
|
||||
The example offers a choice between security version 1 and 2.
|
||||
|
||||
config EXAMPLE_PROV_SECURITY_VERSION_1
|
||||
bool "Security version 1"
|
||||
select ESP_PROTOCOMM_SUPPORT_SECURITY_VERSION_1
|
||||
|
||||
config EXAMPLE_PROV_SECURITY_VERSION_2
|
||||
bool "Security version 2"
|
||||
select ESP_PROTOCOMM_SUPPORT_SECURITY_VERSION_2
|
||||
endchoice
|
||||
|
||||
choice EXAMPLE_PROV_MODE
|
||||
bool "Security version 2 mode"
|
||||
depends on EXAMPLE_PROV_SECURITY_VERSION_2
|
||||
default EXAMPLE_PROV_SEC2_DEV_MODE
|
||||
|
||||
config EXAMPLE_PROV_SEC2_DEV_MODE
|
||||
bool "Security version 2 development mode"
|
||||
depends on EXAMPLE_PROV_SECURITY_VERSION_2
|
||||
help
|
||||
This enables the development mode for
|
||||
security version 2.
|
||||
Please note that this mode is NOT recommended for production purpose.
|
||||
|
||||
config EXAMPLE_PROV_SEC2_PROD_MODE
|
||||
bool "Security version 2 production mode"
|
||||
depends on EXAMPLE_PROV_SECURITY_VERSION_2
|
||||
help
|
||||
This enables the production mode for
|
||||
security version 2.
|
||||
endchoice
|
||||
|
||||
config EXAMPLE_PROV_TRANSPORT
|
||||
int
|
||||
default 1 if EXAMPLE_PROV_TRANSPORT_BLE
|
||||
default 2 if EXAMPLE_PROV_TRANSPORT_SOFTAP
|
||||
|
||||
config EXAMPLE_PROV_ENABLE_APP_CALLBACK
|
||||
bool "Enable provisioning manager app callback"
|
||||
default n
|
||||
help
|
||||
This is for advanced use-cases like modifying Wi-Fi configuration parameters. This
|
||||
executes a blocking app callback when any provisioning event is triggered.
|
||||
|
||||
config EXAMPLE_RESET_PROVISIONED
|
||||
bool
|
||||
default n
|
||||
prompt "Reset provisioned status of the device"
|
||||
help
|
||||
This erases the NVS to reset provisioned status of the device on every reboot.
|
||||
Provisioned status is determined by the Wi-Fi STA configuration, saved on the NVS.
|
||||
|
||||
config EXAMPLE_RESET_PROV_MGR_ON_FAILURE
|
||||
bool
|
||||
default y
|
||||
prompt "Reset provisioned credentials and state machine after session failure"
|
||||
help
|
||||
Enable resetting provisioned credentials and state machine after session failure.
|
||||
This will restart the provisioning service after retries are exhausted.
|
||||
|
||||
config EXAMPLE_PROV_MGR_CONNECTION_CNT
|
||||
int
|
||||
default 5
|
||||
prompt "Max connection attempts before resetting provisioning state machine"
|
||||
depends on EXAMPLE_RESET_PROV_MGR_ON_FAILURE
|
||||
help
|
||||
Set the total number of connection attempts to avoid reconnecting to an inexistent AP or if credentials
|
||||
are misconfigured. Provisioned credentials are erased and internal state machine
|
||||
is reset after this threshold is reached.
|
||||
|
||||
config EXAMPLE_PROV_SHOW_QR
|
||||
bool "Show provisioning QR code"
|
||||
default y
|
||||
help
|
||||
Show the QR code for provisioning.
|
||||
|
||||
config EXAMPLE_PROV_USING_BLUEDROID
|
||||
bool
|
||||
depends on (BT_BLUEDROID_ENABLED && (IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3))
|
||||
select BT_BLE_42_FEATURES_SUPPORTED
|
||||
default y
|
||||
help
|
||||
This enables BLE 4.2 features for Bluedroid.
|
||||
|
||||
config EXAMPLE_REPROVISIONING
|
||||
bool "Re-provisioning"
|
||||
help
|
||||
Enable re-provisioning - allow the device to provision for new credentials
|
||||
after previous successful provisioning.
|
||||
|
||||
endmenu
|
||||
@@ -1,563 +0,0 @@
|
||||
/* Wi-Fi Provisioning Manager Example
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <freertos/event_groups.h>
|
||||
|
||||
#include <esp_log.h>
|
||||
#include <esp_wifi.h>
|
||||
#include <esp_event.h>
|
||||
#include <nvs_flash.h>
|
||||
|
||||
#include <wifi_provisioning/manager.h>
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_BLE
|
||||
#include <wifi_provisioning/scheme_ble.h>
|
||||
#endif /* CONFIG_EXAMPLE_PROV_TRANSPORT_BLE */
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP
|
||||
#include <wifi_provisioning/scheme_softap.h>
|
||||
#endif /* CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP */
|
||||
#include "qrcode.h"
|
||||
|
||||
static const char *TAG = "app";
|
||||
|
||||
#if CONFIG_EXAMPLE_PROV_SECURITY_VERSION_2
|
||||
#if CONFIG_EXAMPLE_PROV_SEC2_DEV_MODE
|
||||
#define EXAMPLE_PROV_SEC2_USERNAME "wifiprov"
|
||||
#define EXAMPLE_PROV_SEC2_PWD "abcd1234"
|
||||
|
||||
/* This salt,verifier has been generated for username = "wifiprov" and password = "abcd1234"
|
||||
* IMPORTANT NOTE: For production cases, this must be unique to every device
|
||||
* and should come from device manufacturing partition.*/
|
||||
static const char sec2_salt[] = {
|
||||
0x03, 0x6e, 0xe0, 0xc7, 0xbc, 0xb9, 0xed, 0xa8, 0x4c, 0x9e, 0xac, 0x97, 0xd9, 0x3d, 0xec, 0xf4
|
||||
};
|
||||
|
||||
static const char sec2_verifier[] = {
|
||||
0x7c, 0x7c, 0x85, 0x47, 0x65, 0x08, 0x94, 0x6d, 0xd6, 0x36, 0xaf, 0x37, 0xd7, 0xe8, 0x91, 0x43,
|
||||
0x78, 0xcf, 0xfd, 0x61, 0x6c, 0x59, 0xd2, 0xf8, 0x39, 0x08, 0x12, 0x72, 0x38, 0xde, 0x9e, 0x24,
|
||||
0xa4, 0x70, 0x26, 0x1c, 0xdf, 0xa9, 0x03, 0xc2, 0xb2, 0x70, 0xe7, 0xb1, 0x32, 0x24, 0xda, 0x11,
|
||||
0x1d, 0x97, 0x18, 0xdc, 0x60, 0x72, 0x08, 0xcc, 0x9a, 0xc9, 0x0c, 0x48, 0x27, 0xe2, 0xae, 0x89,
|
||||
0xaa, 0x16, 0x25, 0xb8, 0x04, 0xd2, 0x1a, 0x9b, 0x3a, 0x8f, 0x37, 0xf6, 0xe4, 0x3a, 0x71, 0x2e,
|
||||
0xe1, 0x27, 0x86, 0x6e, 0xad, 0xce, 0x28, 0xff, 0x54, 0x46, 0x60, 0x1f, 0xb9, 0x96, 0x87, 0xdc,
|
||||
0x57, 0x40, 0xa7, 0xd4, 0x6c, 0xc9, 0x77, 0x54, 0xdc, 0x16, 0x82, 0xf0, 0xed, 0x35, 0x6a, 0xc4,
|
||||
0x70, 0xad, 0x3d, 0x90, 0xb5, 0x81, 0x94, 0x70, 0xd7, 0xbc, 0x65, 0xb2, 0xd5, 0x18, 0xe0, 0x2e,
|
||||
0xc3, 0xa5, 0xf9, 0x68, 0xdd, 0x64, 0x7b, 0xb8, 0xb7, 0x3c, 0x9c, 0xfc, 0x00, 0xd8, 0x71, 0x7e,
|
||||
0xb7, 0x9a, 0x7c, 0xb1, 0xb7, 0xc2, 0xc3, 0x18, 0x34, 0x29, 0x32, 0x43, 0x3e, 0x00, 0x99, 0xe9,
|
||||
0x82, 0x94, 0xe3, 0xd8, 0x2a, 0xb0, 0x96, 0x29, 0xb7, 0xdf, 0x0e, 0x5f, 0x08, 0x33, 0x40, 0x76,
|
||||
0x52, 0x91, 0x32, 0x00, 0x9f, 0x97, 0x2c, 0x89, 0x6c, 0x39, 0x1e, 0xc8, 0x28, 0x05, 0x44, 0x17,
|
||||
0x3f, 0x68, 0x02, 0x8a, 0x9f, 0x44, 0x61, 0xd1, 0xf5, 0xa1, 0x7e, 0x5a, 0x70, 0xd2, 0xc7, 0x23,
|
||||
0x81, 0xcb, 0x38, 0x68, 0xe4, 0x2c, 0x20, 0xbc, 0x40, 0x57, 0x76, 0x17, 0xbd, 0x08, 0xb8, 0x96,
|
||||
0xbc, 0x26, 0xeb, 0x32, 0x46, 0x69, 0x35, 0x05, 0x8c, 0x15, 0x70, 0xd9, 0x1b, 0xe9, 0xbe, 0xcc,
|
||||
0xa9, 0x38, 0xa6, 0x67, 0xf0, 0xad, 0x50, 0x13, 0x19, 0x72, 0x64, 0xbf, 0x52, 0xc2, 0x34, 0xe2,
|
||||
0x1b, 0x11, 0x79, 0x74, 0x72, 0xbd, 0x34, 0x5b, 0xb1, 0xe2, 0xfd, 0x66, 0x73, 0xfe, 0x71, 0x64,
|
||||
0x74, 0xd0, 0x4e, 0xbc, 0x51, 0x24, 0x19, 0x40, 0x87, 0x0e, 0x92, 0x40, 0xe6, 0x21, 0xe7, 0x2d,
|
||||
0x4e, 0x37, 0x76, 0x2f, 0x2e, 0xe2, 0x68, 0xc7, 0x89, 0xe8, 0x32, 0x13, 0x42, 0x06, 0x84, 0x84,
|
||||
0x53, 0x4a, 0xb3, 0x0c, 0x1b, 0x4c, 0x8d, 0x1c, 0x51, 0x97, 0x19, 0xab, 0xae, 0x77, 0xff, 0xdb,
|
||||
0xec, 0xf0, 0x10, 0x95, 0x34, 0x33, 0x6b, 0xcb, 0x3e, 0x84, 0x0f, 0xb9, 0xd8, 0x5f, 0xb8, 0xa0,
|
||||
0xb8, 0x55, 0x53, 0x3e, 0x70, 0xf7, 0x18, 0xf5, 0xce, 0x7b, 0x4e, 0xbf, 0x27, 0xce, 0xce, 0xa8,
|
||||
0xb3, 0xbe, 0x40, 0xc5, 0xc5, 0x32, 0x29, 0x3e, 0x71, 0x64, 0x9e, 0xde, 0x8c, 0xf6, 0x75, 0xa1,
|
||||
0xe6, 0xf6, 0x53, 0xc8, 0x31, 0xa8, 0x78, 0xde, 0x50, 0x40, 0xf7, 0x62, 0xde, 0x36, 0xb2, 0xba
|
||||
};
|
||||
#endif
|
||||
|
||||
static esp_err_t example_get_sec2_salt(const char **salt, uint16_t *salt_len) {
|
||||
#if CONFIG_EXAMPLE_PROV_SEC2_DEV_MODE
|
||||
ESP_LOGI(TAG, "Development mode: using hard coded salt");
|
||||
*salt = sec2_salt;
|
||||
*salt_len = sizeof(sec2_salt);
|
||||
return ESP_OK;
|
||||
#elif CONFIG_EXAMPLE_PROV_SEC2_PROD_MODE
|
||||
ESP_LOGE(TAG, "Not implemented!");
|
||||
return ESP_FAIL;
|
||||
#endif
|
||||
}
|
||||
|
||||
static esp_err_t example_get_sec2_verifier(const char **verifier, uint16_t *verifier_len) {
|
||||
#if CONFIG_EXAMPLE_PROV_SEC2_DEV_MODE
|
||||
ESP_LOGI(TAG, "Development mode: using hard coded verifier");
|
||||
*verifier = sec2_verifier;
|
||||
*verifier_len = sizeof(sec2_verifier);
|
||||
return ESP_OK;
|
||||
#elif CONFIG_EXAMPLE_PROV_SEC2_PROD_MODE
|
||||
/* This code needs to be updated with appropriate implementation to provide verifier */
|
||||
ESP_LOGE(TAG, "Not implemented!");
|
||||
return ESP_FAIL;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Signal Wi-Fi events on this event-group */
|
||||
const int WIFI_CONNECTED_EVENT = BIT0;
|
||||
static EventGroupHandle_t wifi_event_group;
|
||||
|
||||
#define PROV_QR_VERSION "v1"
|
||||
#define PROV_TRANSPORT_SOFTAP "softap"
|
||||
#define PROV_TRANSPORT_BLE "ble"
|
||||
#define QRCODE_BASE_URL "https://espressif.github.io/esp-jumpstart/qrcode.html"
|
||||
|
||||
/* Event handler for catching system events */
|
||||
static void event_handler(void* arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void* event_data)
|
||||
{
|
||||
if (event_base == WIFI_PROV_EVENT) {
|
||||
switch (event_id) {
|
||||
case WIFI_PROV_START:
|
||||
ESP_LOGI(TAG, "Provisioning started");
|
||||
break;
|
||||
case WIFI_PROV_CRED_RECV: {
|
||||
wifi_sta_config_t *wifi_sta_cfg = (wifi_sta_config_t *)event_data;
|
||||
ESP_LOGI(TAG, "Received Wi-Fi credentials"
|
||||
"\n\tSSID : %s\n\tPassword : %s",
|
||||
(const char *) wifi_sta_cfg->ssid,
|
||||
(const char *) wifi_sta_cfg->password);
|
||||
break;
|
||||
}
|
||||
case WIFI_PROV_CRED_FAIL: {
|
||||
wifi_prov_sta_fail_reason_t *reason = (wifi_prov_sta_fail_reason_t *)event_data;
|
||||
ESP_LOGE(TAG, "Provisioning failed!\n\tReason : %s"
|
||||
"\n\tPlease reset to factory and retry provisioning",
|
||||
(*reason == WIFI_PROV_STA_AUTH_ERROR) ?
|
||||
"Wi-Fi station authentication failed" : "Wi-Fi access-point not found");
|
||||
#ifdef CONFIG_EXAMPLE_RESET_PROV_MGR_ON_FAILURE
|
||||
/* Reset the state machine on provisioning failure.
|
||||
* This is enabled by the CONFIG_EXAMPLE_RESET_PROV_MGR_ON_FAILURE configuration.
|
||||
* It allows the provisioning manager to retry the provisioning process
|
||||
* based on the number of attempts specified in wifi_conn_attempts. After attempting
|
||||
* the maximum number of retries, the provisioning manager will reset the state machine
|
||||
* and the provisioning process will be terminated.
|
||||
*/
|
||||
wifi_prov_mgr_reset_sm_state_on_failure();
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case WIFI_PROV_CRED_SUCCESS:
|
||||
ESP_LOGI(TAG, "Provisioning successful");
|
||||
break;
|
||||
case WIFI_PROV_END:
|
||||
/* De-initialize manager once provisioning is finished */
|
||||
esp_err_t err = wifi_prov_mgr_deinit();
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to de-initialize provisioning manager: %s", esp_err_to_name(err));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (event_base == WIFI_EVENT) {
|
||||
switch (event_id) {
|
||||
case WIFI_EVENT_STA_START:
|
||||
esp_wifi_connect();
|
||||
break;
|
||||
case WIFI_EVENT_STA_DISCONNECTED:
|
||||
ESP_LOGI(TAG, "Disconnected. Connecting to the AP again...");
|
||||
esp_wifi_connect();
|
||||
break;
|
||||
#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP
|
||||
case WIFI_EVENT_AP_STACONNECTED:
|
||||
ESP_LOGI(TAG, "SoftAP transport: Connected!");
|
||||
break;
|
||||
case WIFI_EVENT_AP_STADISCONNECTED:
|
||||
ESP_LOGI(TAG, "SoftAP transport: Disconnected!");
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} 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, "Connected with IP Address:" IPSTR, IP2STR(&event->ip_info.ip));
|
||||
/* Signal main application to continue execution */
|
||||
xEventGroupSetBits(wifi_event_group, WIFI_CONNECTED_EVENT);
|
||||
#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_BLE
|
||||
} else if (event_base == PROTOCOMM_TRANSPORT_BLE_EVENT) {
|
||||
switch (event_id) {
|
||||
case PROTOCOMM_TRANSPORT_BLE_CONNECTED:
|
||||
ESP_LOGI(TAG, "BLE transport: Connected!");
|
||||
break;
|
||||
case PROTOCOMM_TRANSPORT_BLE_DISCONNECTED:
|
||||
ESP_LOGI(TAG, "BLE transport: Disconnected!");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
} else if (event_base == PROTOCOMM_SECURITY_SESSION_EVENT) {
|
||||
switch (event_id) {
|
||||
case PROTOCOMM_SECURITY_SESSION_SETUP_OK:
|
||||
ESP_LOGI(TAG, "Secured session established!");
|
||||
break;
|
||||
case PROTOCOMM_SECURITY_SESSION_INVALID_SECURITY_PARAMS:
|
||||
ESP_LOGE(TAG, "Received invalid security parameters for establishing secure session!");
|
||||
break;
|
||||
case PROTOCOMM_SECURITY_SESSION_CREDENTIALS_MISMATCH:
|
||||
ESP_LOGE(TAG, "Received incorrect username and/or PoP for establishing secure session!");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void wifi_init_sta(void)
|
||||
{
|
||||
/* Start Wi-Fi in station mode */
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
}
|
||||
|
||||
static void get_device_service_name(char *service_name, size_t max)
|
||||
{
|
||||
uint8_t eth_mac[6];
|
||||
const char *ssid_prefix = "PROV_";
|
||||
esp_wifi_get_mac(WIFI_IF_STA, eth_mac);
|
||||
snprintf(service_name, max, "%s%02X%02X%02X",
|
||||
ssid_prefix, eth_mac[3], eth_mac[4], eth_mac[5]);
|
||||
}
|
||||
|
||||
/* Handler for the optional provisioning endpoint registered by the application.
|
||||
* The data format can be chosen by applications. Here, we are using plain ascii text.
|
||||
* Applications can choose to use other formats like protobuf, JSON, XML, etc.
|
||||
* Note that memory for the response buffer must be allocated using heap as this buffer
|
||||
* gets freed by the protocomm layer once it has been sent by the transport layer.
|
||||
*/
|
||||
esp_err_t custom_prov_data_handler(uint32_t session_id, const uint8_t *inbuf, ssize_t inlen,
|
||||
uint8_t **outbuf, ssize_t *outlen, void *priv_data)
|
||||
{
|
||||
if (inbuf) {
|
||||
ESP_LOGI(TAG, "Received data: %.*s", inlen, (char *)inbuf);
|
||||
}
|
||||
char response[] = "SUCCESS";
|
||||
*outbuf = (uint8_t *)strdup(response);
|
||||
if (*outbuf == NULL) {
|
||||
ESP_LOGE(TAG, "System out of memory");
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
*outlen = strlen(response) + 1; /* +1 for NULL terminating byte */
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void wifi_prov_print_qr(const char *name, const char *username, const char *pop, const char *transport)
|
||||
{
|
||||
if (!name || !transport) {
|
||||
ESP_LOGW(TAG, "Cannot generate QR code payload. Data missing.");
|
||||
return;
|
||||
}
|
||||
char payload[150] = {0};
|
||||
if (pop) {
|
||||
#if CONFIG_EXAMPLE_PROV_SECURITY_VERSION_1
|
||||
snprintf(payload, sizeof(payload), "{\"ver\":\"%s\",\"name\":\"%s\"" \
|
||||
",\"pop\":\"%s\",\"transport\":\"%s\"}",
|
||||
PROV_QR_VERSION, name, pop, transport);
|
||||
#elif CONFIG_EXAMPLE_PROV_SECURITY_VERSION_2
|
||||
snprintf(payload, sizeof(payload), "{\"ver\":\"%s\",\"name\":\"%s\"" \
|
||||
",\"username\":\"%s\",\"pop\":\"%s\",\"transport\":\"%s\"}",
|
||||
PROV_QR_VERSION, name, username, pop, transport);
|
||||
#endif
|
||||
} else {
|
||||
snprintf(payload, sizeof(payload), "{\"ver\":\"%s\",\"name\":\"%s\"" \
|
||||
",\"transport\":\"%s\"}",
|
||||
PROV_QR_VERSION, name, transport);
|
||||
}
|
||||
#ifdef CONFIG_EXAMPLE_PROV_SHOW_QR
|
||||
ESP_LOGI(TAG, "Scan this QR code from the provisioning application for Provisioning.");
|
||||
esp_qrcode_config_t cfg = ESP_QRCODE_CONFIG_DEFAULT();
|
||||
esp_qrcode_generate(&cfg, payload);
|
||||
#endif /* CONFIG_APP_WIFI_PROV_SHOW_QR */
|
||||
ESP_LOGI(TAG, "If QR code is not visible, copy paste the below URL in a browser.\n%s?data=%s", QRCODE_BASE_URL, payload);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_PROV_ENABLE_APP_CALLBACK
|
||||
void wifi_prov_app_callback(void *user_data, wifi_prov_cb_event_t event, void *event_data)
|
||||
{
|
||||
/**
|
||||
* This is blocking callback, any configurations that needs to be set when a particular
|
||||
* provisioning event is triggered can be set here.
|
||||
*/
|
||||
switch (event) {
|
||||
case WIFI_PROV_SET_STA_CONFIG: {
|
||||
/**
|
||||
* Wi-Fi configurations can be set here before the Wi-Fi is enabled in
|
||||
* STA mode.
|
||||
*/
|
||||
wifi_config_t *wifi_config = (wifi_config_t*)event_data;
|
||||
(void) wifi_config;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const wifi_prov_event_handler_t wifi_prov_event_handler = {
|
||||
.event_cb = wifi_prov_app_callback,
|
||||
.user_data = NULL,
|
||||
};
|
||||
#endif /* EXAMPLE_PROV_ENABLE_APP_CALLBACK */
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
/* Initialize NVS partition */
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
/* NVS partition was truncated
|
||||
* and needs to be erased */
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
|
||||
/* Retry nvs_flash_init */
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
}
|
||||
|
||||
/* Initialize TCP/IP */
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
|
||||
/* Initialize the event loop */
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
wifi_event_group = xEventGroupCreate();
|
||||
|
||||
/* Register our event handler for Wi-Fi, IP and Provisioning related events */
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_PROV_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
|
||||
#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_BLE
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(PROTOCOMM_TRANSPORT_BLE_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
|
||||
#endif
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(PROTOCOMM_SECURITY_SESSION_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL));
|
||||
|
||||
/* Initialize Wi-Fi including netif with default config */
|
||||
esp_netif_create_default_wifi_sta();
|
||||
#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP
|
||||
esp_netif_create_default_wifi_ap();
|
||||
#endif /* CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP */
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
|
||||
/* Configuration for the provisioning manager */
|
||||
wifi_prov_mgr_config_t config = {
|
||||
#ifdef CONFIG_EXAMPLE_RESET_PROV_MGR_ON_FAILURE
|
||||
.wifi_prov_conn_cfg = {
|
||||
.wifi_conn_attempts = CONFIG_EXAMPLE_PROV_MGR_CONNECTION_CNT,
|
||||
},
|
||||
#endif
|
||||
/* What is the Provisioning Scheme that we want ?
|
||||
* wifi_prov_scheme_softap or wifi_prov_scheme_ble */
|
||||
#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_BLE
|
||||
.scheme = wifi_prov_scheme_ble,
|
||||
#endif /* CONFIG_EXAMPLE_PROV_TRANSPORT_BLE */
|
||||
#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP
|
||||
.scheme = wifi_prov_scheme_softap,
|
||||
#endif /* CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP */
|
||||
#ifdef CONFIG_EXAMPLE_PROV_ENABLE_APP_CALLBACK
|
||||
.app_event_handler = wifi_prov_event_handler,
|
||||
#endif /* EXAMPLE_PROV_ENABLE_APP_CALLBACK */
|
||||
|
||||
/* Any default scheme specific event handler that you would
|
||||
* like to choose. Since our example application requires
|
||||
* neither BT nor BLE, we can choose to release the associated
|
||||
* memory once provisioning is complete, or not needed
|
||||
* (in case when device is already provisioned). Choosing
|
||||
* appropriate scheme specific event handler allows the manager
|
||||
* to take care of this automatically. This can be set to
|
||||
* WIFI_PROV_EVENT_HANDLER_NONE when using wifi_prov_scheme_softap*/
|
||||
#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_BLE
|
||||
.scheme_event_handler = WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BTDM
|
||||
#endif /* CONFIG_EXAMPLE_PROV_TRANSPORT_BLE */
|
||||
#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP
|
||||
.scheme_event_handler = WIFI_PROV_EVENT_HANDLER_NONE
|
||||
#endif /* CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP */
|
||||
};
|
||||
|
||||
/* Initialize provisioning manager with the
|
||||
* configuration parameters set above */
|
||||
ESP_ERROR_CHECK(wifi_prov_mgr_init(config));
|
||||
|
||||
bool provisioned = false;
|
||||
#ifdef CONFIG_EXAMPLE_RESET_PROVISIONED
|
||||
wifi_prov_mgr_reset_provisioning();
|
||||
#else
|
||||
/* Let's find out if the device is provisioned */
|
||||
ESP_ERROR_CHECK(wifi_prov_mgr_is_provisioned(&provisioned));
|
||||
|
||||
#endif
|
||||
/* If device is not yet provisioned start provisioning service */
|
||||
if (!provisioned) {
|
||||
ESP_LOGI(TAG, "Starting provisioning");
|
||||
|
||||
/* What is the Device Service Name that we want
|
||||
* This translates to :
|
||||
* - Wi-Fi SSID when scheme is wifi_prov_scheme_softap
|
||||
* - device name when scheme is wifi_prov_scheme_ble
|
||||
*/
|
||||
char service_name[12];
|
||||
get_device_service_name(service_name, sizeof(service_name));
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_PROV_SECURITY_VERSION_1
|
||||
/* What is the security level that we want (0, 1, 2):
|
||||
* - WIFI_PROV_SECURITY_0 is simply plain text communication.
|
||||
* - WIFI_PROV_SECURITY_1 is secure communication which consists of secure handshake
|
||||
* using X25519 key exchange and proof of possession (pop) and AES-CTR
|
||||
* for encryption/decryption of messages.
|
||||
* - WIFI_PROV_SECURITY_2 SRP6a based authentication and key exchange
|
||||
* + AES-GCM encryption/decryption of messages
|
||||
*/
|
||||
wifi_prov_security_t security = WIFI_PROV_SECURITY_1;
|
||||
|
||||
/* Do we want a proof-of-possession (ignored if Security 0 is selected):
|
||||
* - this should be a string with length > 0
|
||||
* - NULL if not used
|
||||
*/
|
||||
const char *pop = "abcd1234";
|
||||
|
||||
/* This is the structure for passing security parameters
|
||||
* for the protocomm security 1.
|
||||
*/
|
||||
wifi_prov_security1_params_t *sec_params = pop;
|
||||
|
||||
const char *username = NULL;
|
||||
|
||||
#elif CONFIG_EXAMPLE_PROV_SECURITY_VERSION_2
|
||||
wifi_prov_security_t security = WIFI_PROV_SECURITY_2;
|
||||
/* The username must be the same one, which has been used in the generation of salt and verifier */
|
||||
|
||||
#if CONFIG_EXAMPLE_PROV_SEC2_DEV_MODE
|
||||
/* This pop field represents the password that will be used to generate salt and verifier.
|
||||
* The field is present here in order to generate the QR code containing password.
|
||||
* In production this password field shall not be stored on the device */
|
||||
const char *username = EXAMPLE_PROV_SEC2_USERNAME;
|
||||
const char *pop = EXAMPLE_PROV_SEC2_PWD;
|
||||
#elif CONFIG_EXAMPLE_PROV_SEC2_PROD_MODE
|
||||
/* The username and password shall not be embedded in the firmware,
|
||||
* they should be provided to the user by other means.
|
||||
* e.g. QR code sticker */
|
||||
const char *username = NULL;
|
||||
const char *pop = NULL;
|
||||
#endif
|
||||
/* This is the structure for passing security parameters
|
||||
* for the protocomm security 2.
|
||||
* If dynamically allocated, sec2_params pointer and its content
|
||||
* must be valid till WIFI_PROV_END event is triggered.
|
||||
*/
|
||||
wifi_prov_security2_params_t sec2_params = {};
|
||||
|
||||
ESP_ERROR_CHECK(example_get_sec2_salt(&sec2_params.salt, &sec2_params.salt_len));
|
||||
ESP_ERROR_CHECK(example_get_sec2_verifier(&sec2_params.verifier, &sec2_params.verifier_len));
|
||||
|
||||
wifi_prov_security2_params_t *sec_params = &sec2_params;
|
||||
#endif
|
||||
/* What is the service key (could be NULL)
|
||||
* This translates to :
|
||||
* - Wi-Fi password when scheme is wifi_prov_scheme_softap
|
||||
* (Minimum expected length: 8, maximum 64 for WPA2-PSK)
|
||||
* - simply ignored when scheme is wifi_prov_scheme_ble
|
||||
*/
|
||||
const char *service_key = NULL;
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_BLE
|
||||
/* This step is only useful when scheme is wifi_prov_scheme_ble. This will
|
||||
* set a custom 128 bit UUID which will be included in the BLE advertisement
|
||||
* and will correspond to the primary GATT service that provides provisioning
|
||||
* endpoints as GATT characteristics. Each GATT characteristic will be
|
||||
* formed using the primary service UUID as base, with different auto assigned
|
||||
* 12th and 13th bytes (assume counting starts from 0th byte). The client side
|
||||
* applications must identify the endpoints by reading the User Characteristic
|
||||
* Description descriptor (0x2901) for each characteristic, which contains the
|
||||
* endpoint name of the characteristic */
|
||||
uint8_t custom_service_uuid[] = {
|
||||
/* LSB <---------------------------------------
|
||||
* ---------------------------------------> MSB */
|
||||
0xb4, 0xdf, 0x5a, 0x1c, 0x3f, 0x6b, 0xf4, 0xbf,
|
||||
0xea, 0x4a, 0x82, 0x03, 0x04, 0x90, 0x1a, 0x02,
|
||||
};
|
||||
|
||||
/* If your build fails with linker errors at this point, then you may have
|
||||
* forgotten to enable the BT stack or BTDM BLE settings in the SDK (e.g. see
|
||||
* the sdkconfig.defaults in the example project) */
|
||||
wifi_prov_scheme_ble_set_service_uuid(custom_service_uuid);
|
||||
#endif /* CONFIG_EXAMPLE_PROV_TRANSPORT_BLE */
|
||||
|
||||
/* An optional endpoint that applications can create if they expect to
|
||||
* get some additional custom data during provisioning workflow.
|
||||
* The endpoint name can be anything of your choice.
|
||||
* This call must be made before starting the provisioning.
|
||||
*/
|
||||
wifi_prov_mgr_endpoint_create("custom-data");
|
||||
|
||||
/* Do not stop and de-init provisioning even after success,
|
||||
* so that we can restart it later. */
|
||||
#ifdef CONFIG_EXAMPLE_REPROVISIONING
|
||||
wifi_prov_mgr_disable_auto_stop(1000);
|
||||
#endif
|
||||
/* Start provisioning service */
|
||||
ESP_ERROR_CHECK(wifi_prov_mgr_start_provisioning(security, (const void *) sec_params, service_name, service_key));
|
||||
|
||||
/* The handler for the optional endpoint created above.
|
||||
* This call must be made after starting the provisioning, and only if the endpoint
|
||||
* has already been created above.
|
||||
*/
|
||||
wifi_prov_mgr_endpoint_register("custom-data", custom_prov_data_handler, NULL);
|
||||
|
||||
/* Uncomment the following to wait for the provisioning to finish and then release
|
||||
* the resources of the manager. Since in this case de-initialization is triggered
|
||||
* by the default event loop handler, we don't need to call the following */
|
||||
// wifi_prov_mgr_wait();
|
||||
// wifi_prov_mgr_deinit();
|
||||
/* Print QR code for provisioning */
|
||||
#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_BLE
|
||||
wifi_prov_print_qr(service_name, username, pop, PROV_TRANSPORT_BLE);
|
||||
#else /* CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP */
|
||||
wifi_prov_print_qr(service_name, username, pop, PROV_TRANSPORT_SOFTAP);
|
||||
#endif /* CONFIG_EXAMPLE_PROV_TRANSPORT_BLE */
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Already provisioned, starting Wi-Fi STA");
|
||||
|
||||
/* We don't need the manager as device is already provisioned,
|
||||
* so let's release it's resources */
|
||||
ESP_ERROR_CHECK(wifi_prov_mgr_deinit());
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
|
||||
/* Start Wi-Fi station */
|
||||
wifi_init_sta();
|
||||
}
|
||||
|
||||
/* Wait for Wi-Fi connection */
|
||||
xEventGroupWaitBits(wifi_event_group, WIFI_CONNECTED_EVENT, true, true, portMAX_DELAY);
|
||||
|
||||
/* Start main application now */
|
||||
#if CONFIG_EXAMPLE_REPROVISIONING
|
||||
while (1) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
ESP_LOGI(TAG, "Hello World!");
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
/* Resetting provisioning state machine to enable re-provisioning */
|
||||
/* NOTE: This API is used only for demonstration purposes in this example.
|
||||
* In real-world firmware applications, you should NOT call this API directly.
|
||||
* Instead, the external provisioning entity should trigger reprovisioning by sending
|
||||
* a command through the provisioning control endpoint, which will internally
|
||||
* trigger same behaviour to reset the provisioning state.
|
||||
*/
|
||||
wifi_prov_mgr_reset_sm_state_for_reprovision();
|
||||
|
||||
/* Wait for Wi-Fi connection */
|
||||
xEventGroupWaitBits(wifi_event_group, WIFI_CONNECTED_EVENT, true, true, portMAX_DELAY);
|
||||
}
|
||||
#else
|
||||
while (1) {
|
||||
ESP_LOGI(TAG, "Hello World!");
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
dependencies:
|
||||
qrcode: "^0.1.0"
|
||||
@@ -1,5 +0,0 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
|
||||
nvs, data, nvs, , 0x6000,
|
||||
phy_init, data, phy, , 0x1000,
|
||||
factory, app, factory, , 0x150000,
|
||||
|
@@ -1,111 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2018-2025 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
from pytest_embedded_idf.utils import idf_parametrize
|
||||
|
||||
try:
|
||||
import esp_prov
|
||||
except ImportError:
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'tools'))
|
||||
import esp_prov
|
||||
|
||||
import pytest
|
||||
from pytest_embedded import Dut
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
# Have esp_prov throw exception
|
||||
esp_prov.config_throw_except = True
|
||||
|
||||
|
||||
def test_wifi_prov_mgr(dut: Dut, sec_ver: int) -> None:
|
||||
# Check if BT memory is released before provisioning starts
|
||||
dut.expect('wifi_prov_scheme_ble: BT memory released', timeout=60)
|
||||
|
||||
# Parse BLE devname
|
||||
devname = dut.expect(b'Provisioning started with service name : PROV_(.{6})')[0].decode('utf-8').split(' : ')[1]
|
||||
logging.info('BLE Device Alias for DUT : {}'.format(devname))
|
||||
|
||||
logging.info('Starting Provisioning')
|
||||
verbose = False
|
||||
protover = 'v1.1'
|
||||
provmode = 'ble'
|
||||
ap_ssid = 'myssid'
|
||||
ap_password = 'mypassword'
|
||||
|
||||
logging.info('Getting security')
|
||||
if sec_ver == 1:
|
||||
pop = 'abcd1234'
|
||||
sec2_username = None
|
||||
sec2_password = None
|
||||
security = esp_prov.get_security(sec_ver, sec2_username, sec2_password, pop, verbose)
|
||||
elif sec_ver == 2:
|
||||
pop = None
|
||||
sec2_username = 'wifiprov'
|
||||
sec2_password = 'abcd1234'
|
||||
security = esp_prov.get_security(sec_ver, sec2_username, sec2_password, pop, verbose)
|
||||
|
||||
if security is None:
|
||||
raise RuntimeError('Failed to get security')
|
||||
|
||||
logging.info('Getting transport')
|
||||
transport = esp_prov.get_transport(provmode, devname)
|
||||
if transport is None:
|
||||
raise RuntimeError('Failed to get transport')
|
||||
|
||||
logging.info('Verifying protocol version')
|
||||
if not esp_prov.version_match(transport, protover):
|
||||
raise RuntimeError('Mismatch in protocol version')
|
||||
|
||||
logging.info('Verifying scan list capability')
|
||||
if not esp_prov.has_capability(transport, 'wifi_scan'):
|
||||
raise RuntimeError('Capability not present')
|
||||
|
||||
logging.info('Starting Session')
|
||||
if not esp_prov.establish_session(transport, security):
|
||||
raise RuntimeError('Failed to start session')
|
||||
|
||||
logging.info('Sending Custom Data')
|
||||
if not esp_prov.custom_data(transport, security, 'My Custom Data'):
|
||||
raise RuntimeError('Failed to send custom data')
|
||||
|
||||
logging.info('Sending Wifi credential to DUT')
|
||||
if not esp_prov.send_wifi_config(transport, security, ap_ssid, ap_password):
|
||||
raise RuntimeError('Failed to send Wi-Fi config')
|
||||
|
||||
logging.info('Applying config')
|
||||
if not esp_prov.apply_wifi_config(transport, security):
|
||||
raise RuntimeError('Failed to send apply config')
|
||||
|
||||
if not esp_prov.wait_wifi_connected(transport, security):
|
||||
raise RuntimeError('Provisioning failed')
|
||||
|
||||
# Check if BTDM memory is released after provisioning finishes
|
||||
dut.expect('wifi_prov_scheme_ble: BTDM memory released', timeout=30)
|
||||
|
||||
|
||||
@pytest.mark.generic
|
||||
@pytest.mark.parametrize(
|
||||
'config',
|
||||
[
|
||||
'security1',
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@pytest.mark.xfail(reason='Runner unable to connect to target over Bluetooth', run=False)
|
||||
@idf_parametrize('target', ['esp32'], indirect=['target'])
|
||||
def test_examples_wifi_prov_mgr_sec1(dut: Dut) -> None:
|
||||
test_wifi_prov_mgr(dut, 1)
|
||||
|
||||
|
||||
@pytest.mark.generic
|
||||
@pytest.mark.xfail(reason='Runner unable to connect to target over Bluetooth', run=False)
|
||||
@idf_parametrize('target', ['esp32'], indirect=['target'])
|
||||
def test_examples_wifi_prov_mgr_sec2(dut: Dut) -> None:
|
||||
test_wifi_prov_mgr(dut, 2)
|
||||
@@ -1 +0,0 @@
|
||||
CONFIG_EXAMPLE_PROV_SECURITY_VERSION_1=y
|
||||
@@ -1,11 +0,0 @@
|
||||
# Override some defaults so BT stack is enabled and
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
|
||||
## For Bluedroid as binary is larger than default size
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
|
||||
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
|
||||
Reference in New Issue
Block a user