• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

components/custom_provisioning/11-Mar-2024-701547

main/11-Mar-2024-829514

CMakeLists.txtD11-Mar-2024237 75

MakefileD11-Mar-2024184 92

README.mdD11-Mar-20245.4 KiB145103

README.md

1# SoftAP + HTTPD based Provisioning Example featuring Custom configuration (Legacy)
2
3> Note: It is recommended to use the new `wifi_prov_mgr` example which is based on the simpler `wifi_provisioning` APIs. Check this example only if you wish to use lower level provisioning and protocomm APIs and want more control over the handlers.
4
5(See the README.md file in the upper level 'examples' directory for more information about examples.)
6
7(Please see the README.md under `softap_prov` example before this.)
8
9`custom_config` example demonstrates the implementation and integration of various IDF components for building a provisioning application.
10
11This is same as `softap_prov` example, with added feature for configuration of some custom data (just like Wi-Fi configuration) during provisioning. The custom data provided during provisioning is simply printed on the serial monitor. The rest of the program functions just like `softap_prov`, ie. the device is configured as Wi-Fi station with supplied AP credentials.
12
13
14`custom_config` uses the following components :
15* `wifi_provisioning` : provides data structures and protocomm endpoint handlers for Wi-Fi configuration
16* `protocomm` : for protocol based communication and secure session establishment
17* `protobuf` : Google's protocol buffer library for serialization of protocomm data structures
18
19Also, it uses a component provided with this example `custom_provisioning` which provides data structures and protocomm endpoint handlers for custom data configuration
20
21## How to use example
22
23### Hardware Required
24
25Example should be able to run on any commonly available ESP32 development board.
26
27### Application Required
28
29To provision the device running this example, the `esp_prov.py` script needs to be run (found under `$IDF_PATH/tools/esp_prov`). This feature of `esp_prov` should work on all platforms, given the dependencies are satisfied.
30
31### Configure the project
32
33```
34idf.py menuconfig
35```
36
37* Under Example Configuration set the following :
38    * SoftAP SSID (Defaults to PROV_<MACID>)
39    * SoftAP Password (Defaults to PROV_PASS)
40    * Security Version (default 0)
41    * Proof of Possession (by default not needed for security version 0)
42
43### Build and Flash
44
45Build the project and flash it to the board, then run monitor tool to view serial output:
46
47```
48idf.py -p PORT flash monitor
49```
50
51(To exit the serial monitor, type ``Ctrl-]``.)
52
53See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
54
55## Example Output
56
57```
58I (1562) app: SoftAP started
59I (1572) app_prov: SoftAP Provisioning started with SSID 'PROV_261FCC', Password 'PROV_PASS'
60```
61
62Make sure to connect the client computer to the SoftAP network, whose SSID and Password are displayed in the serial monitor log. On successful connection the monitor log will show :
63
64```
65I (519482) tcpip_adapter: softAP assign IP to station,IP is: 192.168.4.2
66```
67
68In a separate terminal run the `esp_prov.py` script under `$IDP_PATH/tools/esp_prov` directory (please replace the values corresponding to the parameters `--custom_info` and `--custom_ver` with your desired values for the custom configuration). Assuming default example configuration, the script should be run as follows :
69
70```
71python esp_prov.py --transport softap --service_name "192.168.4.1:80" --sec_ver 0 --ssid myssid --passphrase mypassword --custom_config --custom_info "some string" --custom_ver 4321
72```
73
74Above command will perform the provisioning steps, and the monitor log should display something like this :
75
76```
77I (92734) app_prov_handler: Custom config received :
78    Info : some string
79    Version : 4321
80.
81.
82.
83I (634572) app_prov_handler: WiFi Credentials Received :
84    ssid     : myssid
85    password : mypassword
86.
87.
88.
89I (634652) app_prov_handler: WiFi Credentials Applied
90I (634652) app_prov: STA Start
91.
92.
93.
94I (688270) app_prov_handler: Connecting state
95.
96.
97.
98I (637732) app_prov: STA Got IP
99I (637732) app: got ip:192.168.43.220
100.
101.
102.
103I (654562) app_prov_handler: Connected state
104```
105
106After sometime the provisioning app will exit, SoftAP will be turned off and HTTP server will be stopped
107
108```
109I (667732) app_prov: Stopping provisioning
110I (668732) app_prov: Provisioning stopped
111I (668742) app: SoftAP stopped
112```
113
114## Troubleshooting
115
116### Provisioning failed
117
118It 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) and the provisioning app will continue running, allowing the user to retry the process. Serial monitor log will display the failure along with disconnect reason :
119
120```
121E (39291) app_prov: STA Disconnected
122E (39291) app_prov: Disconnect reason : 201
123I (39291) app_prov: STA AP Not found
124I (42021) app_prov_handler: Disconnected state
125```
126
127### Provisioning does not start
128
129If the serial monitor log is different, as shown below :
130
131```
132I (539) app_prov: Found ssid myssid
133I (539) app_prov: Found password mypassword
134I (549) app: Starting WiFi station
135```
136
137It means the Wi-Fi credentials were already set by some other application flashed previously to your device. To erase these credentials either do full erase and then flash the example
138
139```
140make erase_flash
141idf.py -p PORT flash monitor
142```
143
144Or, enable `Reset Provisioning` option under `Example Configuration` under menuconfig. But this will erase the saved Wi-Fi credentials every time the device boots, so this is not the preferred solution.
145