# smartconfig **Repository Path**: iYUN2/smartconfig ## Basic Information - **Project Name**: smartconfig - **Description**: smartconfig 的js源码,通过node main.js 运行配网,并提供ESP32C3的smartconfig代码,ESP32C3运行smartconfig等待配网,js通过广播将ssid和密码通知给esp32c3 - **Primary Language**: JavaScript - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2023-11-26 - **Last Updated**: 2023-11-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 开发环境 vscode ## 操作步骤 保证电脑上已经安装node,然后用vscode打开文件夹jsCode,在vscode内新建一个terminal,在terminal内运行`node main.js`,terminal内打印信息如下: ``` Microsoft Windows [版本 10.0.22000.1219] (c) Microsoft Corporation。保留所有权利。 D:\ESP32\idf\myCode\smart_config\jsCode>node main.js [ 201, 296, 68, 72, 297, 176, 114, 298, 215, 135, 299, 179, 45, 300, 279, 180, 301, 216, 114, 302, 128, 104, 303, 153, 73, 304, 264, 223, 305, 218, 235, 306, 74, 254, 307, 46, 174, 308, 288, 219, 309, 271, 158, 310, 268, 47, 311, 173, 79, 312, 216 ] server listening 192.168.1.16:18266 server got: 1c7cdfa1b39234c0a8010f from 192.168.1.15:58498 res: { "acked": true, "rinfo": { "address": "192.168.1.15", "family": "IPv4", "port": 58498, "size": 11 }, "bssid": "7cdfa1b39234", "ip": "192.168.1.15" } D:\ESP32\idf\myCode\smart_config\jsCode> ``` 从打印消息中可以看到配网成功。可以在源码js中查看smartconfig的组包过程,将ssid和密码的ascii码加入crc纠错码后得到uint16数据流,利用这个数据流调制包长度,包内容时字符“1” ## MCU代码 ESP32侧代码较简单,利用启动smartconfig后利用event_handle注册回调函数,代码简单,这里不详细解释 # smartconfig Example This example shows how ESP32 connects to a target AP with ESPTOUCH. ## How to use example ### Hardware Required Download ESPTOUCH APP from app store: [Android source code](https://github.com/EspressifApp/EsptouchForAndroid) [iOS source code](https://github.com/EspressifApp/EsptouchForIOS) is available. ### Configure the project ``` idf.py menuconfig ``` ### 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 * Make sure your phone connect to the target AP (2.4GHz). * Open ESPTOUCH app and input password. There will be success message after few sec. Here is an example of smartconfig console output. ``` I (372) wifi: mode : sta (24:0a:c4:00:44:86) I (422) smartconfig: SC version: V2.6.6 I (3802) wifi: ic_enable_sniffer I (3802) sc: SC_STATUS_FIND_CHANNEL I (234592) smartconfig: TYPE: ESPTOUCH I (234592) smartconfig: T|PHONE MAC:68:3e:34:88:59:bf I (234592) smartconfig: T|AP MAC:a4:56:02:47:30:07 I (234592) sc: SC_STATUS_GETTING_SSID_PSWD I (239922) smartconfig: T|pswd: 123456789 I (239922) smartconfig: T|ssid: IOT_DEMO_TEST I (239922) smartconfig: T|bssid: a4:56:02:47:30:07 I (239922) wifi: ic_disable_sniffer I (239922) sc: SC_STATUS_LINK I (239932) sc: SSID:IOT_DEMO_TEST I (239932) sc: PASSWORD:123456789 I (240062) wifi: n:1 0, o:1 0, ap:255 255, sta:1 0, prof:1 I (241042) wifi: state: init -> auth (b0) I (241042) wifi: state: auth -> assoc (0) I (241052) wifi: state: assoc -> run (10) I (241102) wifi: connected with IOT_DEMO_TEST, channel 1 I (244892) event: ip: 192.168.0.152, mask: 255.255.255.0, gw: 192.168.0.1 I (244892) sc: WiFi Connected to ap I (247952) sc: SC_STATUS_LINK_OVER I (247952) sc: Phone ip: 192.168.0.31 I (247952) sc: smartconfig over ```