From c099efa911240dbd188c99b6e275774a6707c538 Mon Sep 17 00:00:00 2001 From: TheBakedPotato <11617336+TheBakedPotato@users.noreply.github.com> Date: Sat, 14 Feb 2026 12:38:31 -0500 Subject: [PATCH 1/3] (#226): Setting callback for AP mode starting - Also setting it up to not output that the IP set if the ip address is 0.0.0.0 --- Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.cpp | 45 +++++++++++++++++-- Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.h | 8 ++-- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.cpp b/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.cpp index 6b3c52a..feb11e8 100644 --- a/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.cpp +++ b/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.cpp @@ -33,11 +33,40 @@ void Manager::connect(const char *const accessPointSsid) this->wifiManager.setSaveConfigCallback(saveConfigCallback); - auto apStaConnectedCallback = [this](arduino_event_id_t event, arduino_event_info_t info) + auto staGotIpCallback = [this](arduino_event_id_t event, arduino_event_info_t info) { - this->ipSet(); + if (this->wifi.localIP() == INADDR_NONE) + { + return; + } + + switch (this->getMode()) + { + case wifi_mode_t::WIFI_MODE_AP: + // TODO: output its IP address for AP mode + break; + + case wifi_mode_t::WIFI_MODE_STA: + this->ipSet(); + + break; + } + }; + this->wifi.onEvent(staGotIpCallback, arduino_event_id_t::ARDUINO_EVENT_WIFI_STA_GOT_IP); + + auto apStartedCallback = [this](arduino_event_id_t event, arduino_event_info_t info) + { + this->print.print("AP Has Started: "); + this->wifi.localIP().printTo(this->print); + this->print.print("\n"); + + if (this->apStartedCallback) + { + this->apStartedCallback(this->getMode()); + } }; - this->wifi.onEvent(apStaConnectedCallback, arduino_event_id_t::ARDUINO_EVENT_WIFI_STA_GOT_IP); + + this->wifi.onEvent(apStartedCallback, arduino_event_id_t::ARDUINO_EVENT_WIFI_AP_START); bool connectSuccess = false; if (accessPointSsid == "") @@ -55,6 +84,16 @@ void Manager::setConnectedCallback(std::function callback) this->connectedCallback = callback; } +void Manager::setApStartedCallback(std::function callback) +{ + this->apStartedCallback = callback; +} + +wifi_mode_t Manager::getMode() +{ + return this->wifi.getMode(); +} + void Manager::ssidSaved() { this->print.print("Network Saved with SSID: "); diff --git a/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.h b/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.h index b2af372..6920227 100644 --- a/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.h +++ b/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.h @@ -1,11 +1,8 @@ #ifndef WIFI_MANAGER_H #define WIFI_MANAGER_H -// #include #include #include -#include -#include extern const char *DEFAULT_SSID; extern String ledState; @@ -22,12 +19,17 @@ namespace WifiOTA void initialize(); void connect(const char *const accessPointSsid); void setConnectedCallback(std::function callBack); + void setApStartedCallback(std::function callback); + wifi_mode_t getMode(); + // Include a "on wifi mode change" callback + // The callback takes a single parameter, it's the WiFi's current mode private: WiFiClass &wifi; Print &print; WiFiManager wifiManager; std::function connectedCallback; + std::function apStartedCallback; void ssidSaved(); void ipSet(); From ed46d878d2c77a9daedfba105c60850c213f412a Mon Sep 17 00:00:00 2001 From: TheBakedPotato <11617336+TheBakedPotato@users.noreply.github.com> Date: Mon, 16 Feb 2026 17:18:24 -0500 Subject: [PATCH 2/3] (#226): Callback set for when the AP starts --- Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.cpp | 49 +++++++++---------- Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.h | 5 +- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.cpp b/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.cpp index feb11e8..05de8de 100644 --- a/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.cpp +++ b/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.cpp @@ -33,41 +33,24 @@ void Manager::connect(const char *const accessPointSsid) this->wifiManager.setSaveConfigCallback(saveConfigCallback); + auto apStartedCallback = [this](WiFiManager *wifiManager) + { + this->apStarted(); + }; + + this->wifiManager.setAPCallback(apStartedCallback); + auto staGotIpCallback = [this](arduino_event_id_t event, arduino_event_info_t info) { - if (this->wifi.localIP() == INADDR_NONE) + if ((this->wifi.localIP() == INADDR_NONE) && (this->getMode() == wifi_mode_t::WIFI_MODE_STA)) { return; } - switch (this->getMode()) - { - case wifi_mode_t::WIFI_MODE_AP: - // TODO: output its IP address for AP mode - break; - - case wifi_mode_t::WIFI_MODE_STA: - this->ipSet(); - - break; - } + this->ipSet(); }; this->wifi.onEvent(staGotIpCallback, arduino_event_id_t::ARDUINO_EVENT_WIFI_STA_GOT_IP); - auto apStartedCallback = [this](arduino_event_id_t event, arduino_event_info_t info) - { - this->print.print("AP Has Started: "); - this->wifi.localIP().printTo(this->print); - this->print.print("\n"); - - if (this->apStartedCallback) - { - this->apStartedCallback(this->getMode()); - } - }; - - this->wifi.onEvent(apStartedCallback, arduino_event_id_t::ARDUINO_EVENT_WIFI_AP_START); - bool connectSuccess = false; if (accessPointSsid == "") { @@ -84,7 +67,7 @@ void Manager::setConnectedCallback(std::function callback) this->connectedCallback = callback; } -void Manager::setApStartedCallback(std::function callback) +void Manager::setApStartedCallback(std::function callback) { this->apStartedCallback = callback; } @@ -117,6 +100,18 @@ void Manager::ipSet() } } +void Manager::apStarted() +{ + this->print.print("AP Has Started: "); + this->wifi.softAPIP().printTo(this->print); + this->print.print("\n"); + + if (this->apStartedCallback) + { + this->apStartedCallback(); + } +} + void WifiOTA::initLittleFS() { if (!LittleFS.begin(true)) diff --git a/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.h b/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.h index 6920227..8f67e30 100644 --- a/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.h +++ b/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.h @@ -19,7 +19,7 @@ namespace WifiOTA void initialize(); void connect(const char *const accessPointSsid); void setConnectedCallback(std::function callBack); - void setApStartedCallback(std::function callback); + void setApStartedCallback(std::function callback); wifi_mode_t getMode(); // Include a "on wifi mode change" callback // The callback takes a single parameter, it's the WiFi's current mode @@ -29,10 +29,11 @@ namespace WifiOTA Print &print; WiFiManager wifiManager; std::function connectedCallback; - std::function apStartedCallback; + std::function apStartedCallback; void ssidSaved(); void ipSet(); + void apStarted(); }; void initLittleFS(); From be48a2f18b939f71cdb79742856b4df2c8966234 Mon Sep 17 00:00:00 2001 From: TheBakedPotato <11617336+TheBakedPotato@users.noreply.github.com> Date: Wed, 18 Feb 2026 19:55:37 -0500 Subject: [PATCH 3/3] (#226): The splash screen prints what the network mode is along with the IP --- Firmware/GPAD_API/GPAD_API/GPAD_API.ino | 20 +++++++++++++++---- Firmware/GPAD_API/GPAD_API/GPAD_HAL.cpp | 20 +++++++++++++++---- Firmware/GPAD_API/GPAD_API/GPAD_HAL.h | 5 +++-- Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.cpp | 13 ++++++++++++ Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.h | 3 +-- 5 files changed, 49 insertions(+), 12 deletions(-) diff --git a/Firmware/GPAD_API/GPAD_API/GPAD_API.ino b/Firmware/GPAD_API/GPAD_API/GPAD_API.ino index 5ca68a6..df9160a 100644 --- a/Firmware/GPAD_API/GPAD_API/GPAD_API.ino +++ b/Firmware/GPAD_API/GPAD_API/GPAD_API.ino @@ -356,9 +356,8 @@ void setup() serialSplash(); // We call this a second time to get the MAC on the screen clearLCD(); - splashLCD(); - // Set LED pins as outputs +// Set LED pins as outputs #if defined(LED_D9) pinMode(LED_D9, OUTPUT); #endif @@ -382,7 +381,8 @@ void setup() // Setup and present LCD splash screen // Setup the SWITCH_MUTE // Setup the SWITCH_ENCODER - GPAD_HAL_setup(&Serial); + IPAddress deviceAddress = wifiManager.getAddress(); + GPAD_HAL_setup(&Serial, wifiManager.getMode(), deviceAddress); #if (DEBUG > 0) Serial.println("MAC: "); @@ -457,10 +457,22 @@ void setup() { reconnect(); } + + clearLCD(); + IPAddress currentAddress = wifiManager.getAddress(); + splashLCD(wifiManager.getMode(), currentAddress); }; wifiManager.setConnectedCallback(connectedCallback); #endif + auto apStartedCallback = [&]() + { + clearLCD(); + IPAddress currentAddress = wifiManager.getAddress(); + splashLCD(wifiManager.getMode(), currentAddress); + }; + wifiManager.setApStartedCallback(apStartedCallback); + wifiManager.connect(setupSsid); WifiOTA::initLittleFS(); server.begin(); // Start server web socket to render pages @@ -473,7 +485,7 @@ void setup() digitalWrite(LED_BUILTIN, LOW); // turn the LED off at end of setup initRotator(); - splashLCD(); + splashLCD(wifiManager.getMode(), deviceAddress); setupDFPlayer(); setup_GPAD_menu(); diff --git a/Firmware/GPAD_API/GPAD_API/GPAD_HAL.cpp b/Firmware/GPAD_API/GPAD_API/GPAD_HAL.cpp index c318953..1a8dffe 100644 --- a/Firmware/GPAD_API/GPAD_API/GPAD_HAL.cpp +++ b/Firmware/GPAD_API/GPAD_API/GPAD_HAL.cpp @@ -325,7 +325,7 @@ void muteButtonCallback(byte buttonEvent) } } -void GPAD_HAL_setup(Stream *serialport) +void GPAD_HAL_setup(Stream *serialport, wifi_mode_t wifiMode, IPAddress &deviceIp) { // Setup and present LCD splash screen // Setup the SWITCH_MUTE @@ -344,7 +344,7 @@ void GPAD_HAL_setup(Stream *serialport) serialport->println(F("Start LCD splash")); #endif - splashLCD(); + splashLCD(wifiMode, deviceIp); #if (DEBUG > 0) serialport->println(F("EndLCD splash")); @@ -581,7 +581,7 @@ void clearLCD(void) } // Splash a message so we can tell the LCD is working -void splashLCD(void) +void splashLCD(wifi_mode_t wifiMode, IPAddress &deviceIp) { lcd.init(); // initialize the lcd // Print a message to the LCD. @@ -602,7 +602,18 @@ void splashLCD(void) // Line 1 lcd.setCursor(0, 1); - lcd.print("IP: " + WiFi.localIP().toString()); + switch (wifiMode) + { + case wifi_mode_t::WIFI_MODE_AP: + lcd.print("AP "); + break; + case wifi_mode_t::WIFI_MODE_STA: + lcd.print("STA "); + break; + } + + lcd.print("IP: "); + deviceIp.printTo(lcd); // Line 2 lcd.setCursor(0, 2); @@ -612,6 +623,7 @@ void splashLCD(void) lcd.setCursor(0, 3); lcd.print("MAC: "); lcd.print(macAddressString); + lcd.scrollDisplayRight(); } bool printable(char c) { diff --git a/Firmware/GPAD_API/GPAD_API/GPAD_HAL.h b/Firmware/GPAD_API/GPAD_API/GPAD_HAL.h index aba0f8e..e2e62bb 100644 --- a/Firmware/GPAD_API/GPAD_API/GPAD_HAL.h +++ b/Firmware/GPAD_API/GPAD_API/GPAD_HAL.h @@ -24,6 +24,7 @@ // #include #include #include +#include // On Nov. 5th, 2024, we image 3 different hardware platforms. // The GPAD exists, and is working: https://www.hardware-x.com/article/S2468-0672(24)00084-1/fulltext @@ -185,12 +186,12 @@ void restoreAlarmLevel(Stream *serialport); void unchanged_anunicateAlarmLevel(Stream *serialport); void annunciateAlarmLevel(Stream *serialport); void clearLCD(void); -void splashLCD(void); +void splashLCD(wifi_mode_t wifiMode, IPAddress &deviceIp); void interpretBuffer(char *buf, int rlen, Stream *serialport, PubSubClient *client); // This module has to be initialized and called each time through the superloop -void GPAD_HAL_setup(Stream *serialport); +void GPAD_HAL_setup(Stream *serialport, wifi_mode_t wifiMode, IPAddress &deviceIp); void GPAD_HAL_loop(); extern LiquidCrystal_I2C lcd; diff --git a/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.cpp b/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.cpp index 05de8de..f8c99aa 100644 --- a/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.cpp +++ b/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.cpp @@ -77,6 +77,19 @@ wifi_mode_t Manager::getMode() return this->wifi.getMode(); } +IPAddress Manager::getAddress() +{ + switch (this->getMode()) + { + case wifi_mode_t::WIFI_MODE_AP: + return this->wifi.softAPIP(); + case wifi_mode_t::WIFI_MODE_STA: + return this->wifi.localIP(); + default: + return INADDR_NONE; + } +} + void Manager::ssidSaved() { this->print.print("Network Saved with SSID: "); diff --git a/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.h b/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.h index 8f67e30..f6e9355 100644 --- a/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.h +++ b/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.h @@ -21,8 +21,7 @@ namespace WifiOTA void setConnectedCallback(std::function callBack); void setApStartedCallback(std::function callback); wifi_mode_t getMode(); - // Include a "on wifi mode change" callback - // The callback takes a single parameter, it's the WiFi's current mode + IPAddress getAddress(); private: WiFiClass &wifi;