当前位置:网站首页>ESP8266_ SmartConfig
ESP8266_ SmartConfig
2022-06-11 09:37:00 【Little tiger_ IOT】
1、WiFi Distribution network mode
This article introduces and analyzes several WiFi Distribution network mode , I recommend it , At present, the mainstream WiFi The distribution network has equipment hotspots 、 Bluetooth distribution network 、 One key distribution network (SmartConfig);
- Equipment hotspot distribution network : Hot spots created by mobile phones and devices , Put those who can access the Internet WiFi Name and password are sent to the device ;
- Bluetooth distribution network : The mobile phone is connected to the device via Bluetooth , Put those who can access the Internet WiFi Name and password are sent to the device ;
- One key distribution network : Mobile phones are still connected to Internet WiFi, radio broadcast WiFi Name and password , The device is on sniffer Mode monitor , obtain WiFi Name and password ;
2、SmartConfig Distribution network
- The device has reached the sniffer Pattern ( Also known as hybrid mode , That is, the data message is not filtered ), Listen to all the... In the environment 802.11 message ;
- The device needs to be in the supported channel ( Usually 1-13) Upper polling listening ( Because the device does not know the channel between the user's mobile phone and the target router );
- Catch a match Data message of distribution network rules Stop channel polling after , Attempt to receive all messages on this channel ;
- If the current channel fails to receive or times out, go back to step 2;
- Close when the data message is received sniffer Pattern , go back to station Pattern And start trying to connect to the router , The narrow distribution network process is completed .
3、ESP8266 Of SmartConfig Interface
Set up SmartConfig Pattern , Turn on SmartConfig, There are callback functions according to different stages of the distribution network , Then close SmartConfig;
3.1、smartconfig_set_type
Because we use wechat Airkiss function , So choose SC_TYPE_AIRKISS;
ESPTOUCH It is one developed by Lexin APP, For distribution network , Here there is no ;
3.2、smartconfig_start
Just follow the instructions , First set up STA The pattern calls this API, The parameters of the callback function are different at different stages of the distribution network , So we can switch case Perform corresponding operations according to the status , And officially API There are also sample references under the document ;
3.3、smartconfig_stop
close SmartConfig Pattern , Free memory , In the access to IP Then call ;

4、 Code
According to the last time MQTT The program of , What I want to add is ,Flash Medium SSID Connect with password AP Failure 10 After that , Get into SmartConfig Distribution network , And then in “ Anxinko Technology ” Distribution network on official account , And put the new SSID And password update to Flash, In this way, the power distribution network will not be needed next time ; Of course , Like just WiFi If you are disconnected, you can restart without the network ( It would be nice if it could be restored automatically , Dig a hole )
Realize the above functions It just needs to be modified wifi.c Code for , Count as wifi Functions are added SmartConfig Let's expand , Header file to include #include "smartconfig.h" , The original wifi_check_ip The contents to be added in are as follows , Settings not obtained IP 10 After that, enter the one key distribution network ;
// Timing function : Check IP Acquisition
static void ICACHE_FLASH_ATTR wifi_check_ip(void *arg)
{
static u8 fail_num = 0;
// Not obtained IP Address -------------------------------------------------------------
else{
fail_num++;
if(fail_num >= 10){
fail_num = 0;
INFO("--------------START SmartConfig------------------\r\n");
//wifi_set_opmode(STATION_MODE); // Set to STA Pattern
smartconfig_set_type(SC_TYPE_AIRKISS); // ESP8266 Distribution network mode 【AIRKISS】
smartconfig_start(smartconfig_done); // Get into 【 Intelligent distribution network mode 】, And set the callback function
return;
}
}
}then add to SmartConfig Callback function for , The focus is on how to update SSID And password to Flash, And call user_main.c in WiFi Callback function after connection , To enter SNTP、TCP、MQTT And so on , Don't forget to restart the timer , Don't forget to put the default SSID Information error correction ;
// SmartConfig When the state changes , Enter this callback function
// Parameters 1:sc_status status / Parameters 2: No type pointer 【 In different states ,[void *pdata] The parameters passed in are different 】
void ICACHE_FLASH_ATTR smartconfig_done(sc_status status, void *pdata)
{
switch(status)
{
// CmartConfig wait for
case SC_STATUS_WAIT:
os_printf("\r\nSC_STATUS_WAIT\r\n");
break;
// Find out 【WIFI The signal 】(8266 Wait for the distribution network in this state )
case SC_STATUS_FIND_CHANNEL:
os_printf("\r\nSC_STATUS_FIND_CHANNEL\r\n");
os_printf("\r\n---- Please Use WeChat to SmartConfig ------\r\n\r\n");
break;
// Getting 【SSID】【PSWD】(8266 Capturing and decrypting 【SSID+PSWD】)
case SC_STATUS_GETTING_SSID_PSWD:
os_printf("\r\nSC_STATUS_GETTING_SSID_PSWD\r\n");
// Distribution network mode
sc_type *type = pdata;
if (*type == SC_TYPE_ESPTOUCH){
os_printf("\r\nSC_TYPE:SC_TYPE_ESPTOUCH\r\n");
}else{
os_printf("\r\nSC_TYPE:SC_TYPE_AIRKISS\r\n");
}
break;
// Successful acquisition 【SSID】【PSWD】, preservation STA Parameters , And connect WIFI
case SC_STATUS_LINK:
os_printf("\r\nSC_STATUS_LINK\r\n");
struct station_config *sta_conf = pdata; // obtain 【STA Parameters 】 The pointer
// take 【SSID】【PASS】 Save to 【 external Flash】 in
os_strncpy(sysCfg.sta_ssid, sta_conf->ssid, 32); // 【STA_SSID】WIFI name
os_strncpy(sysCfg.sta_pwd, sta_conf->password, 64); // 【STA_PASS】WIFI password
CFG_Save(); // Burn the updated system parameters to Flash in
// Connect WiFi
wifi_station_set_config(sta_conf); // Set up STA Parameters 【Flash】
wifi_station_disconnect(); // To break off STA Connect
wifi_station_connect(); // ESP8266 Connect WIFI
break;
// ESP8266 As STA, Successfully connected to WIFI
case SC_STATUS_LINK_OVER:
os_printf("\r\nSC_STATUS_LINK_OVER\r\n");
smartconfig_stop(); // stop it SmartConfig, Free memory
if(wifiCb){ // Determine if... Is set [wifiConnectCb] function
wifiStatus = wifi_station_get_connect_status(); // Get access status
wifiCb(wifiStatus); // wifiCb(wifiStatus)=wifiConnectCb(wifiStatus)
}
// Turn on the timer again -------------------------------------------------------
os_timer_setfn(&WiFiLinker, (os_timer_func_t *)wifi_check_ip, NULL);
os_timer_arm(&WiFiLinker, 1000, 0); // 1s timing
break;
}
}边栏推荐
- Where is it safer to open an account for soda ash futures? How much do you need to buy at least?
- [scheme development] scheme of infrared thermometer
- Flask (III) -- variable rules
- Package details
- The difference and relation between machine learning and statistics
- 【ROS】noedic-moveit安装与UR5模型导入
- Type-C docking station adaptive power supply patent protection case
- Type-C蓝牙音箱单口可充可OTG方案
- Modularnotfounderror: no module named 'find_ version’
- Shandong University project training (IV) -- wechat applet scans web QR code to realize web login
猜你喜欢

【ROS】noedic-moveit安装与UR5模型导入

Install jupyter in the specified environment

Talk about reading the source code

Output image is bigger (1228800b) than maximum frame size specified in properties (1048576b)

Day41 process pool and thread pool

Type-C蓝牙音箱单口可充可OTG方案

js中关键字this的理解

keyboard entry.

ESP8266_通过MQTT协议连接阿里云

Typescript -- preliminary study of variable declaration
随机推荐
Opencv oak-d-w wide angle camera test
市场上的服装ERP体系到底是哪些类型?
Day39 process object and other method mutexes
Success and failure of ERP software from the perspective of enterprise evaluation
POJ3250「Bad Hair Day」
js基础--Array对象
1493. 删掉一个元素以后全为 1 的最长子数组
Method (common method), method execution memory analysis, method overloading mechanism, method recursion
ESP8266_SmartConfig
1400. construct K palindrome strings
OpenCV OAK相机对比及介绍
考研數學 【數列極限證明題】題型方法總結
Detailed explanation of this and static
Tissu. JS définit dynamiquement la taille de la police
What is WSGI?
企业决议时,哪个部分应该主导ERP项目?
P4147 "jade toad Palace"
关于原型及原型链
P1169 "chessboard making"
Simulation of map and set