So in softAP + station mode, ESP8266 softAP will adjust its channel configuration to be as same as ESP8266 station.
This limitation may cause some inconvenience in softAP + station mode users need to pay attention, for example:
Case 1.
(1) If user connect ESP8266 station to a router(e.g. router is in channel 6).
(2) Then set ESP8266 softAP by wifi_softap_set_config.
(3) The API may return true, but channel will always be channel 6. Because we have only one hardware channel.
Case 2.
(1) If user set ESP8266 softAP a channel number(e.g. channel 5) by wifi_softap_set_config.
(2) Some stations connected to ESP8266 softAP.
(3) Then connect ESP8266 station to a router of which channel number is different (e.g. channel 6).
(4) ESP8266 softAP has to adjust its channel to be as same as ESP8266 station, in this case, is channel 6.
(5) So the stations that connected to ESP8266 softAP in step 2 will be disconnected because of the channel change.
Case 3.
(1) Other stations are connected to the ESP8266 softAP.
(2) If the ESP8266‘s station interface has been scanning or trying to connect to a target router, the ESP8266 softAP-end connection may break.
This is because the ESP8266 station will try to find its target router in different channels, which means it will keep changing channels, and as a result, the ESP8266 channel is changing, too. Therefore, the ESP8266 softAP-end connection may break.
In cases like this, users can set a timer to call wifi_station_disconnect to stop the ESP8266 station from continuously trying to connect to the router. Or they can call wifi_station_set_reconnect_policy or wifi_station_set_auto_connect to disable the ESP8266 station from reconnecting to the router.
wifi_station_set_reconnect_policy(false); // if the ESP8266 station connected to the router, and then the connection broke, ESP8266 will not try to reconnect to the router.
wifi_station_set_auto_connect(false); //the ESP8266 station will not try to connect to the router automatically when power on until wifi_station_connect is called.
wifi_station_disconnect(); // ESP8266 station disconnects to the router, or ESP8266 station stops trying to connect to the target router.
虽然 ESP8266 支持 softAP + station 共存模式,但它实际上只有一个硬件信道。
因此在 softAP + station 模式时, ESP8266 softAP 动态调整它的信道值与 ESP8266 station 一致。
这个限制会导致 softAP + station 模式时一些行为上的不便,用户需要注意。例如:
情况一
(1)如果 ESP8266 station 连接到一个路由(假设路由信道号为 6)。
(2)通过接口 wifi_softap_set_config 设置 ESP8266 softAP。
(3)如果设置值合法有效 API 会返回 true,但信道号设置后仍然会被 ESP8266 自动调节成与 ESP8266 station 接口一致,在这个例子里也就是信道号为 6。因为 ESP8266 在硬件上就只有一个信道。
情况二
(1)先使用接口 wifi_softap_set_config 设置了 ESP8266 softAP (例如信道号为 5)。
(2)其他 station 连接到 ESP8266 softAP。
(3)将 ESP8266 station 连接到路由 ( 假设路由信道号为 6)。
(4) ESP8266 softAP 会调整信道号与 ESP8266 station 一致(信道 6)。
(5)由于信道改变,之前连接到 ESP8266 softAP 的 station 的 WiFi 连接会断开。
情况三
(1)其他 station 与 ESP8266 softAP 建立连接。
(2)如果 ESP8266 station 一直尝试在扫描或连接某个路由,可能导致 ESP8266 softAP 端的连接断开。
因为 ESP8266 station 会在各个信道查找目标路由,意味着它其实在不停的切换信道,ESP8266 softAP 的信道也因此在不停更改。这有可能导致 ESP8266 softAP 端的连接断开。
在这种情况下,用户可以设置一个定时器,定时调用 wifi_station_disconnect 停止 ESP8266 station 不断连接路由的尝试,或者调用 wifi_station_set_reconnect_policy 和 wifi_station_set_auto_connect 禁止 ESP8266 station 尝试重连路由。
wifi_station_set_reconnect_policy(false); // 如果 ESP8266 station 已经连接到某路由,但又从该路由上断开连接了,ESP8266 station 不会自动尝试重新连接该路由。
wifi_station_set_auto_connect(false); //ESP8266 station 在上电时不会自动尝试连接路由,需要调用 wifi_station_connect 才会进行连接路由。
wifi_station_disconnect(); // ESP8266 station 断开与某路由的连接,或者 ESP8266 station 停止尝试连接某路由。
Thanks for your interest in ESP8266 !