Skip to content

Commit d1b6202

Browse files
committed
Add NoWiFi display. Exit AP if no local WiFi.
1 parent 0defbfb commit d1b6202

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

Firmware/RTK_Surveyor/Display.ino

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1566,6 +1566,11 @@ void displayGNSSFail(uint16_t displayTime)
15661566
displayMessage("GNSS Failed", displayTime);
15671567
}
15681568

1569+
void displayNoWiFi(uint16_t displayTime)
1570+
{
1571+
displayMessage("No WiFi", displayTime);
1572+
}
1573+
15691574
void displayRoverStart(uint16_t displayTime)
15701575
{
15711576
if (online.display == true)
@@ -1677,7 +1682,10 @@ void displayWiFiConfig()
16771682
char mySSID[50] = {'\0'};
16781683

16791684
#ifdef COMPILE_WIFI
1680-
sprintf(mySSID, "%s", WiFi.SSID().c_str());
1685+
if (settings.wifiConfigOverAP == true)
1686+
sprintf(mySSID, "%s", "RTK Config");
1687+
else
1688+
sprintf(mySSID, "%s", WiFi.SSID().c_str());
16811689
#else
16821690
sprintf(mySSID, "%s", "!Compiled");
16831691
#endif

Firmware/RTK_Surveyor/WiFi.ino

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,13 @@ void wifiSetState(byte newState)
129129

130130
//Start the access point for user to connect to and configure device
131131
//We can also start as a WiFi station and attempt to connect to local WiFi for config
132-
void wifiStartAP()
132+
bool wifiStartAP()
133133
{
134134
if (settings.wifiConfigOverAP == true)
135135
{
136+
//Stop any current WiFi activity
137+
wifiStop();
138+
136139
//Start in AP mode
137140
WiFi.mode(WIFI_AP);
138141

@@ -148,7 +151,7 @@ void wifiStartAP()
148151
if (WiFi.softAP("RTK Config") == false) //Must be short enough to fit OLED Width
149152
{
150153
systemPrintln("WiFi AP failed to start");
151-
return;
154+
return (false);
152155
}
153156
systemPrint("WiFi AP Started with IP: ");
154157
systemPrintln(WiFi.softAPIP());
@@ -158,9 +161,11 @@ void wifiStartAP()
158161
//Start webserver on local WiFi instead of AP
159162
wifiStart(); //Makes sure any ESP-Now settings have been cleared
160163

161-
//Attempt to connect to local WiFi 3 times with increasing timeouts
164+
//Attempt to connect to local WiFi with increasing timeouts
162165
int timeout = 0;
163-
for (int x = 0 ; x < 3 ; x++)
166+
int x = 0;
167+
const int maxTries = 2;
168+
for ( ; x < maxTries ; x++)
164169
{
165170
timeout += 5000;
166171
if (wifiConnect(timeout) == true) //Attempt to connect to any SSID on settings list
@@ -169,7 +174,15 @@ void wifiStartAP()
169174
break;
170175
}
171176
}
177+
if (x == maxTries)
178+
{
179+
displayNoWiFi(2000);
180+
requestChangeState(STATE_ROVER_NOT_STARTED);
181+
return(false);
182+
}
172183
}
184+
185+
return(true);
173186
}
174187

175188
#endif //COMPILE_WIFI
@@ -227,7 +240,7 @@ void wifiUpdate()
227240
else
228241
{
229242
systemPrintln("WiFi connection failed. Giving up.");
230-
//paintWiFiFail(4000, true); //TODO
243+
displayNoWiFi(2000);
231244
wifiStop(); //Move back to WIFI_OFF
232245
}
233246
}
@@ -420,7 +433,7 @@ bool wifiIsNeeded()
420433

421434
//If WiFi is on while we are in the following states, allow WiFi to continue to operate
422435
if (systemState >= STATE_BUBBLE_LEVEL && systemState <= STATE_PROFILE)
423-
{
436+
{
424437
//Keep WiFi on if user presses setup button, enters bubble level, is in AP config mode, etc
425438
needed = true;
426439
}

0 commit comments

Comments
 (0)