Skip to content

Commit 75c6983

Browse files
authored
Merge pull request #268 from sparkfun/Add_AP+STN_for_firmwware_update_on_AP
Add WIFI_AP_STA for firmware update on AP
2 parents 4f532d6 + 747d2de commit 75c6983

File tree

6 files changed

+1830
-1794
lines changed

6 files changed

+1830
-1794
lines changed

Firmware/RTK_Everywhere/AP-Config/src/main.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,6 @@ function sendData() {
481481
//Check boxes, radio buttons
482482
//Remove file manager files
483483
clsElements = document.querySelectorAll(".form-check-input:not(.fileManagerCheck), .form-radio");
484-
485484
for (let x = 0; x < clsElements.length; x++) {
486485
settingCSV += clsElements[x].id + "," + clsElements[x].checked + ",";
487486
}

Firmware/RTK_Everywhere/Display.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2060,6 +2060,10 @@ void displayWiFiConfig()
20602060
else if (WiFi.getMode() == WIFI_AP)
20612061
snprintf(mySSID, sizeof(mySSID), "%s", "RTK Config");
20622062

2063+
// If we are in AP+STA mode, still display RTK Config
2064+
else if (WiFi.getMode() == WIFI_AP_STA)
2065+
snprintf(mySSID, sizeof(mySSID), "%s", "RTK Config");
2066+
20632067
else
20642068
snprintf(mySSID, sizeof(mySSID), "%s", "Error");
20652069
}
@@ -2093,7 +2097,7 @@ void displayWiFiConfig()
20932097

20942098
#ifdef COMPILE_AP
20952099
IPAddress myIpAddress;
2096-
if (WiFi.getMode() == WIFI_AP)
2100+
if ((WiFi.getMode() == WIFI_AP) || (WiFi.getMode() == WIFI_AP_STA))
20972101
myIpAddress = WiFi.softAPIP();
20982102
else
20992103
myIpAddress = WiFi.localIP();

Firmware/RTK_Everywhere/WiFi.ino

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ void wifiUpdate()
388388
break;
389389
}
390390

391-
// Process DNS when we are in AP mode for captive portal
392-
if (WiFi.getMode() == WIFI_AP && settings.enableCaptivePortal)
391+
// Process DNS when we are in AP mode or AP+STA mode for captive portal
392+
if (((WiFi.getMode() == WIFI_AP) || (WiFi.getMode() == WIFI_AP_STA)) && settings.enableCaptivePortal)
393393
{
394394
dnsServer.processNextRequest();
395395
}
@@ -435,7 +435,7 @@ void wifiStop()
435435
MDNS.end();
436436

437437
// Stop the DNS server if we were using the captive portal
438-
if (WiFi.getMode() == WIFI_AP && settings.enableCaptivePortal)
438+
if (((WiFi.getMode() == WIFI_AP) || (WiFi.getMode() == WIFI_AP_STA)) && settings.enableCaptivePortal)
439439
dnsServer.stop();
440440

441441
// Stop the other network clients and then WiFi
@@ -486,16 +486,40 @@ bool wifiIsConnected()
486486
// Attempts a connection to all provided SSIDs
487487
// Returns true if successful
488488
// Gives up if no SSID detected or connection times out
489+
// If useAPSTAMode is true, do an extra check and go from WIFI_AP mode to WIFI_AP_STA mode
489490
bool wifiConnect(unsigned long timeout)
491+
{
492+
return wifiConnect(timeout, false, nullptr);
493+
}
494+
bool wifiConnect(unsigned long timeout, bool useAPSTAMode, bool *wasInAPmode)
490495
{
491496
if (wifiIsConnected())
492497
return (true); // Nothing to do
493498

494499
displayWiFiConnect();
495500

496-
// Before we can issue esp_wifi_() commands WiFi must be started
497-
if (WiFi.getMode() != WIFI_STA)
498-
WiFi.mode(WIFI_STA);
501+
// If otaUpdate or otaCheckVersion wants to use WIFI_AP_STA mode
502+
if (useAPSTAMode && (wasInAPmode != nullptr))
503+
{
504+
*wasInAPmode = (WiFi.getMode() == WIFI_AP);
505+
506+
if (*wasInAPmode)
507+
{
508+
systemPrintln("wifiConnect: changing from WIFI_AP to WIFI_AP_STA");
509+
WiFi.mode(WIFI_AP_STA); // Change mode from WIFI_AP to WIFI_AP_STA
510+
}
511+
else
512+
{
513+
systemPrintln("wifiConnect: was not in WIFI_AP mode. Going to WIFI_STA");
514+
WiFi.mode(WIFI_STA); // Must have been off - or already in STA mode?
515+
}
516+
}
517+
else
518+
{
519+
// Before we can issue esp_wifi_() commands WiFi must be started
520+
if (WiFi.getMode() != WIFI_STA)
521+
WiFi.mode(WIFI_STA);
522+
}
499523

500524
// Verify that the necessary protocols are set
501525
uint8_t protocols = 0;

0 commit comments

Comments
 (0)