WiFi: Espressif's Killer Feature - MisterRager/Codelab-Indicator-Lights GitHub Wiki
Connecting to WiFi
WiFi credentials are read from wifi_credentials.local
with a fallback to wifi_credentials.default
in platformio.ini
:
platformio.ini:
build_flags = ! cat wifi_credentials.local || cat wifi_credentials.default
wifi_credentials.default:
-DCONFIG_WIFI_SSID="\"**REMOVED**\"" -DCONFIG_WIFI_PASSWORD="\"**REMOVED**\""
The escaped quotes (\"
) are necessary due to the macro expansion used to include the configuration values. Replace the **REMOVED**
between them to set the ssid and password.
Once those are in place, it's just one call to connect to the WiFi using FreeRTOS tasks:
#include "system/wifi.h"
...
void app_main()
{
connect_wifi();
}
Watch the serial console for connection information:
β[0;32mI (48) ConnectWiFi: Registering network ready callback [1074598760]β[0m
β[0;32mI (98) ConnectWiFi: Start task: Connect to WiFiβ[0m
I (98) wifi: wifi driver task: 3ffb1c4c, prio:23, stack:3584, core=0
I (98) wifi: wifi firmware version: 9415913
I (108) wifi: config NVS flash: enabled
I (108) wifi: config nano formating: disabled
β[0;32mI (108) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSEβ[0m
β[0;32mI (118) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSEβ[0m
I (168) wifi: Init dynamic tx buffer num: 32
I (168) wifi: Init data frame dynamic rx buffer num: 32
I (168) wifi: Init management frame dynamic rx buffer num: 32
I (168) wifi: Init static rx buffer size: 1600
I (168) wifi: Init static rx buffer num: 10
I (178) wifi: Init dynamic rx buffer num: 32
β[0;32mI (178) ConnectWiFi: Done waiting, start init!β[0m
β[0;32mI (188) ConnectWiFi: Setting WiFi configuration SSID Lucifer...β[0m
β[0;32mI (188) ConnectWiFi: WiFi is configred. Start!β[0m
β[0;32mI (268) phy: phy_version: 4008, c9ae59f, Jan 25 2019, 16:54:06, 0, 0β[0m
I (268) wifi: mode : sta (30:ae:a4:49:ab:b8)
β[0;32mI (268) ConnectWiFi: WiFi is set!β[0m
β[0;32mI (268) ConnectWiFi: Event: STA Startβ[0m
β[0;32mI (268) ConnectWiFi: Exit WiFi Connect Taskβ[0m
I (1608) wifi: n:11 0, o:1 0, ap:255 255, sta:11 0, prof:1
I (2448) wifi: state: init -> auth (b0)
I (2448) wifi: state: auth -> assoc (0)
I (2458) wifi: state: assoc -> run (10)
I (2468) wifi: connected with Lucifer, channel 11
I (2468) wifi: pm start, type: 1
β[0;32mI (3098) event: sta ip: 10.111.222.208, mask: 255.255.255.0, gw: 10.111.222.1β[0m
β[0;32mI (3098) ConnectWiFi: Event: Got IPβ[0m
β[0;32mI (3098) ConnectWiFi: Toggle Bits for IP for listener [0]β[0m
β[0;32mI (3108) Main: Ready!β[0m