ESP8266 - Allow `network.STA_IF` to `connect` on specific channel
Same request as in https://forum.micropython.org/viewtopic.php?f=16&t=12065
Also see https://www.bakke.online/index.php/2017/06/24/esp8266-wifi-power-reduction-avoiding-network-scan/
I'd also like to do this for power saving on a battery powered device.
I believe micropython isn't able to do this yet, because it's missing from connect:
(call does not allow channel as kwarg)
https://github.com/micropython/micropython/blob/89b320737652829edbab921e86d7ad3962d86d9e/ports/esp8266/modnetwork.c#L111-L117
Additionally, it's also not possible to set this from esp_config:
(setter only for AP, not STA):
https://github.com/micropython/micropython/blob/89b320737652829edbab921e86d7ad3962d86d9e/ports/esp8266/modnetwork.c#L395-L399
(getter only for AP, not STA):
https://github.com/micropython/micropython/blob/89b320737652829edbab921e86d7ad3962d86d9e/ports/esp8266/modnetwork.c#L465-L468
esp8266: WLAN.config('channel') to use wifi_get/set_channel().
ESP8266: WLAN.config("channel") to use wifi_get_channel().
WLAN.config('channel')now useswifi_get_channel()to return current wifi channel, rather than the "configured" channel.- Fixes #11463 : WLAN.config('channel') returns incorrect channel for AP_IF if STA has connected to an external AP running on a different channel.
- This provides the same behaviour as ESP32 from PR #8991 (Does not trigger bug in Issue #11491).
- May also be used on the STA_IF interface.
ESP8266: WLAN.config(channel=X) to use wifi_set_channel().
- May also be used on the STA_IF interface.
This also significantly simplifies setting the channel for espnow users on the ESP8266 and allows channel setting code to be portable across ESP32 and ESP8266 platforms, eg. if using the STA_IF interface portable code to set the channel required:
if sys.platform == "esp8266":
# On ESP8266, use the AP interface to set the channel
ap_save = ap.active()
ap.active(True)
ap.config(channel=6)
ap.active(ap_save)
else:
sta.config(channel=6) # On ESP32 use STA interface
With this PR the equivalent code is:
sta.config(channel=6)