From a426907f1c2d29e1b786b96b5a5e3f2ade9c84bb Mon Sep 17 00:00:00 2001 From: Derek Gustafson Date: Mon, 9 Feb 2026 16:38:17 -0800 Subject: [PATCH 1/2] Replaced hardcoded wifi credentials with WifiManager for ESP wifi companions --- docs/faq.md | 5 +++-- examples/companion_radio/main.cpp | 22 +++++++++++++++---- examples/companion_radio/ui-new/UITask.cpp | 4 ++-- variants/heltec_tracker_v2/platformio.ini | 5 +++-- variants/heltec_v2/platformio.ini | 5 +++-- variants/heltec_v3/platformio.ini | 9 ++++---- variants/heltec_v4/platformio.ini | 9 ++++---- variants/lilygo_tlora_v2_1/platformio.ini | 5 +++-- variants/nibble_screen_connect/platformio.ini | 5 +++-- variants/rak11310/platformio.ini | 5 +++-- variants/rak3112/platformio.ini | 5 +++-- variants/rpi_picow/platformio.ini | 5 +++-- variants/station_g2/platformio.ini | 5 +++-- variants/thinknode_m2/platformio.ini | 7 ++++-- variants/thinknode_m5/platformio.ini | 7 ++++-- variants/waveshare_rp2040_lora/platformio.ini | 9 ++++---- variants/xiao_c3/platformio.ini | 5 +++-- variants/xiao_rp2040/platformio.ini | 5 +++-- variants/xiao_s3_wio/platformio.ini | 5 +++-- 19 files changed, 81 insertions(+), 46 deletions(-) diff --git a/docs/faq.md b/docs/faq.md index efed5a864..f76c6b5c5 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -700,7 +700,8 @@ where `&type` is: ### 7.6. Q: How do I connect to the companion via WIFI, e.g. using a heltec v3? **A:** -WiFi firmware requires you to compile it yourself, as you need to set the wifi ssid and password. -Edit WIFI_SSID and WIFI_PWD in `./variants/heltec_v3/platformio.ini` and then flash it to your device. +WiFi firmware now utilizes WIFI Manager which automatically creates an AP of "MC-AP" with password "mypwd000" when unable to connect to WIFI. + +To customize the default AP name and password, edit WIFI_MANAGER and WIFI_PWD in `./variants/heltec_v3/platformio.ini` and then flash it to your device. A custom password with fewer than 8 characters will be right-padded with zeros to a length of 8. --- diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index 7e636acee..c050759d6 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -35,7 +35,9 @@ static uint32_t _atoi(const char* sp) { #endif #ifdef ESP32 - #ifdef WIFI_SSID + #if defined(WIFI_MANAGER) + #include // https://github.com/tzapu/WiFiManager + WiFiManager wifiManager; #include SerialWifiInterface serial_interface; #ifndef TCP_PORT @@ -193,9 +195,21 @@ void setup() { #endif ); -#ifdef WIFI_SSID - WiFi.begin(WIFI_SSID, WIFI_PWD); - serial_interface.begin(TCP_PORT); +#if defined(WIFI_MANAGER) + + // AP password must have a minimum 8 characters + String ap_passwd = WIFI_PWD; + while (ap_passwd.length() < 8) { + ap_passwd += "0"; + } + if (wifiManager.autoConnect(WIFI_MANAGER, ap_passwd.c_str())) + { + serial_interface.begin(TCP_PORT); + } else { + MESH_DEBUG_PRINTLN("WifiManager failed to connect. Restarting."); + delay(2000); + ESP.restart(); + } #elif defined(BLE_PIN_CODE) serial_interface.begin(BLE_NAME_PREFIX, the_mesh.getNodePrefs()->node_name, the_mesh.getBLEPin()); #elif defined(SERIAL_RX) diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index 8077627f8..b8df58059 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -2,7 +2,7 @@ #include #include "../MyMesh.h" #include "target.h" -#ifdef WIFI_SSID +#if defined(WIFI_MANAGER) #include #endif @@ -195,7 +195,7 @@ class HomeScreen : public UIScreen { sprintf(tmp, "MSG: %d", _task->getMsgCount()); display.drawTextCentered(display.width() / 2, 20, tmp); - #ifdef WIFI_SSID + #if defined(WIFI_MANAGER) IPAddress ip = WiFi.localIP(); snprintf(tmp, sizeof(tmp), "IP: %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); display.setTextSize(1); diff --git a/variants/heltec_tracker_v2/platformio.ini b/variants/heltec_tracker_v2/platformio.ini index 36de671e2..90264ca49 100644 --- a/variants/heltec_tracker_v2/platformio.ini +++ b/variants/heltec_tracker_v2/platformio.ini @@ -183,8 +183,8 @@ build_flags = -D MAX_GROUP_CHANNELS=40 -D DISPLAY_CLASS=ST7735Display -D WIFI_DEBUG_LOGGING=1 - -D WIFI_SSID='"myssid"' - -D WIFI_PWD='"mypwd"' + -D WIFI_MANAGER='"MC-AP"' + -D WIFI_PWD='"mypwd000"' -D OFFLINE_QUEUE_SIZE=256 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 @@ -197,6 +197,7 @@ build_src_filter = ${Heltec_tracker_v2.build_src_filter} lib_deps = ${Heltec_tracker_v2.lib_deps} densaugeo/base64 @ ~1.4.0 + tzapu/WiFiManager@^2.0.17 [env:heltec_tracker_v2_sensor] extends = Heltec_tracker_v2 diff --git a/variants/heltec_v2/platformio.ini b/variants/heltec_v2/platformio.ini index f8cc93608..849f99bdf 100644 --- a/variants/heltec_v2/platformio.ini +++ b/variants/heltec_v2/platformio.ini @@ -181,8 +181,8 @@ build_flags = -D MAX_CONTACTS=160 -D MAX_GROUP_CHANNELS=8 -D WIFI_DEBUG_LOGGING=1 - -D WIFI_SSID='"myssid"' - -D WIFI_PWD='"mypwd"' + -D WIFI_MANAGER='"MC-AP"' + -D WIFI_PWD='"mypwd000"' -D OFFLINE_QUEUE_SIZE=256 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 @@ -195,3 +195,4 @@ build_src_filter = ${Heltec_lora32_v2.build_src_filter} lib_deps = ${Heltec_lora32_v2.lib_deps} densaugeo/base64 @ ~1.4.0 + tzapu/WiFiManager@^2.0.17 diff --git a/variants/heltec_v3/platformio.ini b/variants/heltec_v3/platformio.ini index 6b61eff5d..5d5b899db 100644 --- a/variants/heltec_v3/platformio.ini +++ b/variants/heltec_v3/platformio.ini @@ -187,8 +187,8 @@ build_flags = -D MAX_GROUP_CHANNELS=40 -D DISPLAY_CLASS=SSD1306Display -D WIFI_DEBUG_LOGGING=1 - -D WIFI_SSID='"myssid"' - -D WIFI_PWD='"mypwd"' + -D WIFI_MANAGER='"MC-AP"' + -D WIFI_PWD='"mypwd000"' -D OFFLINE_QUEUE_SIZE=256 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 @@ -340,8 +340,8 @@ build_flags = -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 -D WIFI_DEBUG_LOGGING=1 - -D WIFI_SSID='"myssid"' - -D WIFI_PWD='"mypwd"' + -D WIFI_MANAGER='"MC-AP"' + -D WIFI_PWD='"mypwd000"' -D OFFLINE_QUEUE_SIZE=256 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 @@ -351,6 +351,7 @@ build_src_filter = ${Heltec_lora32_v3.build_src_filter} lib_deps = ${Heltec_lora32_v3.lib_deps} densaugeo/base64 @ ~1.4.0 + tzapu/WiFiManager@^2.0.17 [env:Heltec_WSL3_sensor] extends = Heltec_lora32_v3 diff --git a/variants/heltec_v4/platformio.ini b/variants/heltec_v4/platformio.ini index ba7590094..ae5fa8d26 100644 --- a/variants/heltec_v4/platformio.ini +++ b/variants/heltec_v4/platformio.ini @@ -206,8 +206,8 @@ build_flags = -D MAX_GROUP_CHANNELS=40 -D DISPLAY_CLASS=SSD1306Display -D WIFI_DEBUG_LOGGING=1 - -D WIFI_SSID='"myssid"' - -D WIFI_PWD='"mypwd"' + -D WIFI_MANAGER='"MC-AP"' + -D WIFI_PWD='"mypwd000"' ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 build_src_filter = ${heltec_v4_oled.build_src_filter} @@ -369,8 +369,8 @@ build_flags = -D MAX_GROUP_CHANNELS=40 -D DISPLAY_CLASS=ST7789LCDDisplay -D WIFI_DEBUG_LOGGING=1 - -D WIFI_SSID='"myssid"' - -D WIFI_PWD='"mypwd"' + -D WIFI_MANAGER='"MC-AP"' + -D WIFI_PWD='"mypwd000"' ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 build_src_filter = ${heltec_v4_tft.build_src_filter} @@ -382,6 +382,7 @@ build_src_filter = ${heltec_v4_tft.build_src_filter} lib_deps = ${heltec_v4_tft.lib_deps} densaugeo/base64 @ ~1.4.0 + tzapu/WiFiManager@^2.0.17 [env:heltec_v4_tft_sensor] extends = heltec_v4_tft diff --git a/variants/lilygo_tlora_v2_1/platformio.ini b/variants/lilygo_tlora_v2_1/platformio.ini index f27f57fd9..058e08dc9 100644 --- a/variants/lilygo_tlora_v2_1/platformio.ini +++ b/variants/lilygo_tlora_v2_1/platformio.ini @@ -133,8 +133,8 @@ build_flags = -I examples/companion_radio/ui-new -D MAX_CONTACTS=160 -D MAX_GROUP_CHANNELS=8 - -D WIFI_SSID='"ssid"' - -D WIFI_PWD='"password"' + -D WIFI_MANAGER='"MC-AP"' + -D WIFI_PWD='"mypwd000"' -D WIFI_DEBUG_LOGGING=1 -D OFFLINE_QUEUE_SIZE=256 build_src_filter = ${LilyGo_TLora_V2_1_1_6.build_src_filter} @@ -145,6 +145,7 @@ build_src_filter = ${LilyGo_TLora_V2_1_1_6.build_src_filter} lib_deps = ${LilyGo_TLora_V2_1_1_6.lib_deps} densaugeo/base64 @ ~1.4.0 + tzapu/WiFiManager@^2.0.17 ; ; Repeater Bridges diff --git a/variants/nibble_screen_connect/platformio.ini b/variants/nibble_screen_connect/platformio.ini index 0d3d46523..855ff2679 100644 --- a/variants/nibble_screen_connect/platformio.ini +++ b/variants/nibble_screen_connect/platformio.ini @@ -145,8 +145,8 @@ build_flags = -D MAX_CONTACTS=300 -D MAX_GROUP_CHANNELS=8 -D WIFI_DEBUG_LOGGING=1 - -D WIFI_SSID='"myssid"' - -D WIFI_PWD='"mypwd"' + -D WIFI_MANAGER='"MC-AP"' + -D WIFI_PWD='"mypwd000"' -D OFFLINE_QUEUE_SIZE=256 build_src_filter = ${nibble_screen_connect_base.build_src_filter} + @@ -157,4 +157,5 @@ build_src_filter = ${nibble_screen_connect_base.build_src_filter} lib_deps = ${nibble_screen_connect_base.lib_deps} densaugeo/base64 @ ~1.4.0 + tzapu/WiFiManager@^2.0.17 diff --git a/variants/rak11310/platformio.ini b/variants/rak11310/platformio.ini index df99ea843..0c0ed8b68 100644 --- a/variants/rak11310/platformio.ini +++ b/variants/rak11310/platformio.ini @@ -110,14 +110,15 @@ lib_deps = ${rak11310.lib_deps} ; -D MAX_CONTACTS=100 ; -D MAX_GROUP_CHANNELS=8 ; -D WIFI_DEBUG_LOGGING=1 -; -D WIFI_SSID='"myssid"' -; -D WIFI_PWD='"mypwd"' +; -D WIFI_MANAGER='"MC-AP"' +; -D WIFI_PWD='"mypwd000"' ; ; -D MESH_PACKET_LOGGING=1 ; ; -D MESH_DEBUG=1 ; build_src_filter = ${rak11310.build_src_filter} ; +<../examples/companion_radio/*.cpp> ; lib_deps = ${rak11310.lib_deps} ; densaugeo/base64 @ ~1.4.0 +; tzapu/WiFiManager@^2.0.17 [env:rak11310_terminal_chat] extends = rak11310 diff --git a/variants/rak3112/platformio.ini b/variants/rak3112/platformio.ini index 29ebdff27..de4af9610 100644 --- a/variants/rak3112/platformio.ini +++ b/variants/rak3112/platformio.ini @@ -187,8 +187,8 @@ build_flags = -D MAX_GROUP_CHANNELS=40 -D DISPLAY_CLASS=SSD1306Display -D WIFI_DEBUG_LOGGING=1 - -D WIFI_SSID='"myssid"' - -D WIFI_PWD='"mypwd"' + -D WIFI_MANAGER='"MC-AP"' + -D WIFI_PWD='"mypwd000"' -D OFFLINE_QUEUE_SIZE=256 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 @@ -201,6 +201,7 @@ build_src_filter = ${rak3112.build_src_filter} lib_deps = ${rak3112.lib_deps} densaugeo/base64 @ ~1.4.0 + tzapu/WiFiManager@^2.0.17 [env:RAK3112_sensor] extends = rak3112 diff --git a/variants/rpi_picow/platformio.ini b/variants/rpi_picow/platformio.ini index ec5cdb839..5cb60e879 100644 --- a/variants/rpi_picow/platformio.ini +++ b/variants/rpi_picow/platformio.ini @@ -85,14 +85,15 @@ lib_deps = ${rpi_picow.lib_deps} ; -D MAX_CONTACTS=100 ; -D MAX_GROUP_CHANNELS=8 ; -D WIFI_DEBUG_LOGGING=1 -; -D WIFI_SSID='"myssid"' -; -D WIFI_PWD='"mypwd"' + -D WIFI_MANAGER='"MC-AP"' + -D WIFI_PWD='"mypwd000"' ; ; -D MESH_PACKET_LOGGING=1 ; ; -D MESH_DEBUG=1 ; build_src_filter = ${rpi_picow.build_src_filter} ; +<../examples/companion_radio/*.cpp> ; lib_deps = ${rpi_picow.lib_deps} ; densaugeo/base64 @ ~1.4.0 +; tzapu/WiFiManager@^2.0.17 [env:PicoW_terminal_chat] extends = rpi_picow diff --git a/variants/station_g2/platformio.ini b/variants/station_g2/platformio.ini index 91ef5f7a5..30f8c157f 100644 --- a/variants/station_g2/platformio.ini +++ b/variants/station_g2/platformio.ini @@ -225,8 +225,8 @@ build_flags = -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 -D WIFI_DEBUG_LOGGING=1 - -D WIFI_SSID='"myssid"' - -D WIFI_PWD='"mypwd"' + -D WIFI_MANAGER='"MC-AP"' + -D WIFI_PWD='"mypwd000"' -D OFFLINE_QUEUE_SIZE=256 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 @@ -237,3 +237,4 @@ build_src_filter = ${Station_G2.build_src_filter} lib_deps = ${Station_G2.lib_deps} densaugeo/base64 @ ~1.4.0 + tzapu/WiFiManager@^2.0.17 diff --git a/variants/thinknode_m2/platformio.ini b/variants/thinknode_m2/platformio.ini index b2ebca732..ffe1c78bd 100644 --- a/variants/thinknode_m2/platformio.ini +++ b/variants/thinknode_m2/platformio.ini @@ -177,8 +177,10 @@ build_flags = -D MAX_GROUP_CHANNELS=40 -D OFFLINE_QUEUE_SIZE=256 -D WIFI_DEBUG_LOGGING=1 - -D WIFI_SSID='"myssid"' - -D WIFI_PWD='"mypwd"' + -D WIFI_MANAGER='"MC-AP"' + -D WIFI_PWD='"mypwd000"' +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 build_src_filter = ${ThinkNode_M2.build_src_filter} + + @@ -188,6 +190,7 @@ lib_deps = ${ThinkNode_M2.lib_deps} densaugeo/base64 @ ~1.4.0 end2endzone/NonBlockingRTTTL@^1.3.0 + tzapu/WiFiManager@^2.0.17 [env:ThinkNode_M2_companion_radio_serial] extends = ThinkNode_M2 diff --git a/variants/thinknode_m5/platformio.ini b/variants/thinknode_m5/platformio.ini index fb2ba3ac2..d4ce78dff 100644 --- a/variants/thinknode_m5/platformio.ini +++ b/variants/thinknode_m5/platformio.ini @@ -192,8 +192,10 @@ build_flags = -D MAX_GROUP_CHANNELS=40 -D OFFLINE_QUEUE_SIZE=256 -D WIFI_DEBUG_LOGGING=1 - -D WIFI_SSID='"Livebox-633C"' - -D WIFI_PWD='"vvQUHGSxsWd7fKMYSr"' + -D WIFI_MANAGER='"MC-AP"' + -D WIFI_PWD='"mypwd000"' +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 build_src_filter = ${ThinkNode_M5.build_src_filter} + + @@ -204,6 +206,7 @@ lib_deps = ${ThinkNode_M5.lib_deps} densaugeo/base64 @ ~1.4.0 end2endzone/NonBlockingRTTTL@^1.3.0 + tzapu/WiFiManager@^2.0.17 [env:ThinkNode_M5_companion_radio_serial] extends = ThinkNode_M5 diff --git a/variants/waveshare_rp2040_lora/platformio.ini b/variants/waveshare_rp2040_lora/platformio.ini index 78a5e3e77..4ac5be086 100644 --- a/variants/waveshare_rp2040_lora/platformio.ini +++ b/variants/waveshare_rp2040_lora/platformio.ini @@ -109,14 +109,15 @@ lib_deps = ${waveshare_rp2040_lora.lib_deps} ; -D MAX_CONTACTS=100 ; -D MAX_GROUP_CHANNELS=8 ; -D WIFI_DEBUG_LOGGING=1 -; -D WIFI_SSID='"myssid"' -; -D WIFI_PWD='"mypwd"' -; ; -D MESH_PACKET_LOGGING=1 -; ; -D MESH_DEBUG=1 +; -D WIFI_MANAGER='"MC-AP"' +; -D WIFI_PWD='"mypwd000"' +; ; -D MESH_PACKET_LOGGING=1 +; ; -D MESH_DEBUG=1 ; build_src_filter = ${waveshare_rp2040_lora.build_src_filter} ; +<../examples/companion_radio/*.cpp> ; lib_deps = ${waveshare_rp2040_lora.lib_deps} ; densaugeo/base64 @ ~1.4.0 +; tzapu/WiFiManager@^2.0.17 [env:waveshare_rp2040_lora_terminal_chat] extends = waveshare_rp2040_lora diff --git a/variants/xiao_c3/platformio.ini b/variants/xiao_c3/platformio.ini index 76b72174a..2c49706c7 100644 --- a/variants/xiao_c3/platformio.ini +++ b/variants/xiao_c3/platformio.ini @@ -114,8 +114,8 @@ build_flags = -D MAX_GROUP_CHANNELS=40 -D OFFLINE_QUEUE_SIZE=256 -D WIFI_DEBUG_LOGGING=1 - -D WIFI_SSID='"myssid"' - -D WIFI_PWD='"mypwd"' + -D WIFI_MANAGER='"MC-AP"' + -D WIFI_PWD='"mypwd000"' ; -D BLE_DEBUG_LOGGING=1 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 @@ -123,3 +123,4 @@ lib_deps = ${Xiao_esp32_C3.lib_deps} ${esp32_ota.lib_deps} densaugeo/base64 @ ~1.4.0 + tzapu/WiFiManager@^2.0.17 diff --git a/variants/xiao_rp2040/platformio.ini b/variants/xiao_rp2040/platformio.ini index 2b3e74422..3a9312782 100644 --- a/variants/xiao_rp2040/platformio.ini +++ b/variants/xiao_rp2040/platformio.ini @@ -87,14 +87,15 @@ lib_deps = ${Xiao_rp2040.lib_deps} ; -D MAX_CONTACTS=100 ; -D MAX_GROUP_CHANNELS=8 ; -D WIFI_DEBUG_LOGGING=1 -; -D WIFI_SSID='"myssid"' -; -D WIFI_PWD='"mypwd"' +; -D WIFI_MANAGER='"MC-AP"' +; -D WIFI_PWD='"mypwd000"' ; ; -D MESH_PACKET_LOGGING=1 ; ; -D MESH_DEBUG=1 ; build_src_filter = ${Xiao_rp2040.build_src_filter} ; +<../examples/companion_radio/*.cpp> ; lib_deps = ${Xiao_rp2040.lib_deps} ; densaugeo/base64 @ ~1.4.0 +; tzapu/WiFiManager@^2.0.17 [env:Xiao_rp2040_terminal_chat] extends = Xiao_rp2040 diff --git a/variants/xiao_s3_wio/platformio.ini b/variants/xiao_s3_wio/platformio.ini index 22bb4090a..968007c73 100644 --- a/variants/xiao_s3_wio/platformio.ini +++ b/variants/xiao_s3_wio/platformio.ini @@ -209,14 +209,15 @@ build_flags = -D MAX_GROUP_CHANNELS=40 -D OFFLINE_QUEUE_SIZE=256 -D WIFI_DEBUG_LOGGING=1 - -D WIFI_SSID='"myssid"' - -D WIFI_PWD='"password"' + -D WIFI_MANAGER='"MC-AP"' + -D WIFI_PWD='"mypwd000"' ; -D BLE_DEBUG_LOGGING=1 ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 lib_deps = ${Xiao_S3_WIO.lib_deps} densaugeo/base64 @ ~1.4.0 + tzapu/WiFiManager@^2.0.17 [env:Xiao_S3_WIO_sensor] extends = Xiao_S3_WIO From 02a4d381239a2eac4b1a2fc665d28f515c9bc078 Mon Sep 17 00:00:00 2001 From: Derek Gustafson Date: Mon, 9 Feb 2026 17:11:34 -0800 Subject: [PATCH 2/2] added comment about AP IP address --- docs/faq.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/faq.md b/docs/faq.md index f76c6b5c5..deca2dc67 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -704,4 +704,6 @@ WiFi firmware now utilizes WIFI Manager which automatically creates an AP of "MC To customize the default AP name and password, edit WIFI_MANAGER and WIFI_PWD in `./variants/heltec_v3/platformio.ini` and then flash it to your device. A custom password with fewer than 8 characters will be right-padded with zeros to a length of 8. +If the manager does not pop up automatically after connecting to the AP, please browse to 192.168.4.1 . + ---