# 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 mode of transport, over which the provisioning related communication is to take place, between the device (to be provisioned) and the client (owner of the device).
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.
## How to use example
### Hardware Required
Example should be able to run on any commonly available ESP32 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 provision the device running this example, the `esp_prov.py` script needs to be run (found under `$IDF_PATH/tools/esp_prov`). Make sure to satisfy all the dependencies prior to running the script.
Presently, `esp_prov` supports BLE transport only for Linux platform. For Windows/macOS it falls back to console mode and requires another application (for BLE) through which the communication can take place.
There are various applications, specific to Windows and macOS platform which can be used. 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
```
make menuconfig
```
* Set serial port under Serial Flasher Options.
### Build and Flash
Build the project and flash it to the board, then run monitor tool to view serial output:
```
make -j4 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 protocomm security scheme 1 and proof of possession PoP based authentication :
```
python esp_prov.py --transport ble --service_name PROV_261FCC --sec_ver 1 --pop 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) tcpip_adapter: 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!
```
### 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 credential to esp32 ====
==== Wi-Fi Credentials sent successfully ====
==== Applying config to esp32 ====
==== Apply config sent successfully ====
==== Wi-Fi connection state ====
++++ WiFi state: connected ++++
==== Provisioning was successful ====
```
## 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
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
嵌入式优质项目,资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松copy复刻,拿到资料包后可轻松复现出一样的项目。 本人单片机开发经验充足,深耕嵌入式领域,有任何使用问题欢迎随时与我联系,我会及时为你解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明,项目具体内容可查看下方的资源详情。 【附带帮助】: 若还需要嵌入式物联网单片机相关领域开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步。 【本人专注嵌入式领域】: 有任何使用问题欢迎随时与我联系,我会及时解答,第一时间为你提供帮助,CSDN博客端可私信,为你解惑,欢迎交流。 【建议小白】: 在所有嵌入式开发中硬件部分若不会画PCB/电路,可选择根据引脚定义将其代替为面包板+杜邦线+外设模块的方式,只需轻松简单连线,下载源码烧录进去便可轻松复刻出一样的项目 【适合场景】: 相关项目设计中,皆可应用在项目开发、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面中 可借鉴此优质项目实现复刻,也可以基于此项目进行扩展来开发出更多功能
资源推荐
资源详情
资源评论
收起资源包目录
基于esp32的mqtt通信平台设计.zip (毕设/课设/竞赛/实训/项目开发) (2000个子文件)
libmbedtls.a 3.3MB
libdriver.a 2.39MB
liblwip.a 2.17MB
libnghttp.a 1.48MB
libexpat.a 1.15MB
libesp32.a 1.06MB
libnvs_flash.a 777KB
libmdns.a 662KB
libfreertos.a 501KB
libcoap.a 441KB
libfatfs.a 409KB
libprotobuf-c.a 318KB
libbootloader_support.a 305KB
libopenssl.a 280KB
libesp_http_server.a 278KB
libsdmmc.a 250KB
libvfs.a 242KB
libmqtt.a 229KB
libwear_levelling.a 227KB
libsoc.a 227KB
libsoc.a 219KB
libheap.a 202KB
libesp_http_client.a 187KB
libethernet.a 175KB
libmicro-ecc.a 151KB
libmicro-ecc.a 151KB
libnewlib.a 135KB
libtcpip_adapter.a 130KB
libefuse.a 129KB
libefuse.a 121KB
libpthread.a 119KB
libesp_ringbuf.a 115KB
libapp_update.a 82KB
libcxx.a 69KB
libesp_adc_cal.a 39KB
libulp.a 37KB
libesp_https_server.a 33KB
libjsmn.a 21KB
libsmartconfig_ack.a 21KB
libespcoredump.a 19KB
libxtensa-debug-module.a 12KB
libbt.a 2KB
libaws_iot.a 8B
libidf_test.a 8B
mqtt_tcp.bin 743KB
partitions_singleapp.bin 3KB
gattc_multi_connect.c 46KB
hid_device_le_prf.c 42KB
gatts_demo.c 33KB
main.c 32KB
ble_compatibility_test.c 31KB
example_ble_server_throughput.c 29KB
ble_spp_server_demo.c 27KB
nmea_parser.c 27KB
example_ble_sec_gattc_demo.c 26KB
spp_client_demo.c 26KB
gatts_table_creat_demo.c 25KB
example_ble_client_throughput.c 25KB
example_ble_sec_gatts_demo.c 24KB
esp_modem.c 24KB
gattc_demo.c 22KB
udp_multicast_example_main.c 19KB
main.c 19KB
peer.c 19KB
esp_http_client_example.c 19KB
file_server.c 19KB
main.c 18KB
mcpwm_bldc_control_hall_sensor_example.c 18KB
sim800.c 17KB
bg96.c 16KB
blufi_example_main.c 16KB
mcpwm_basic_config_example.c 16KB
spi_master_example_main.c 16KB
mesh_main.c 16KB
cmd_nvs.c 15KB
espnow_example_main.c 15KB
cmd_sniffer.c 14KB
cmd_i2ctools.c 14KB
main.c 14KB
mesh_main.c 14KB
app_prov.c 13KB
thing_shadow_sample.c 13KB
cmd_wifi.c 13KB
esp_slave.c 13KB
native_ota_example.c 13KB
sh2lib.c 13KB
app_prov.c 13KB
app_prov.c 13KB
tests.c 13KB
iperf.c 13KB
ble_hidd_demo_main.c 13KB
app_mesh.c 12KB
i2c_example_main.c 12KB
deep_sleep_example_main.c 12KB
infrared_nec_main.c 12KB
subscribe_publish_sample.c 12KB
https_mbedtls_example_main.c 11KB
app_main.c 11KB
cmd_system.c 11KB
example_spp_initiator_demo.c 10KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
阿齐Archie
- 粉丝: 1w+
- 资源: 2303
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功