Skip to content

Commit 0c545ac

Browse files
authored
Merge pull request #656 from LeeLeahy2/wip-wifi-restart
WiFi: Switch to new restart
2 parents 7fb94c0 + b173f16 commit 0c545ac

File tree

4 files changed

+57
-299
lines changed

4 files changed

+57
-299
lines changed

Firmware/RTK_Everywhere/Developer.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,9 @@ void wifiDisplaySoftApStatus() {}
210210
bool wifiEspNowOff(const char * fileName, uint32_t lineNumber) {return true;}
211211
bool wifiEspNowOn(const char * fileName, uint32_t lineNumber) {return false;}
212212
void wifiEspNowSetChannel(WIFI_CHANNEL_t channel) {}
213-
uint32_t wifiGetStartTimeout() {return 0;}
214213
int wifiNetworkCount() {return 0;}
215-
void wifiResetThrottleTimeout() {}
216214
void wifiResetTimeout() {}
215+
IPAddress wifiSoftApGetIpAddress() {return IPAddress((uint32_t)0);}
217216
const char * wifiSoftApGetSsid() {return "";}
218217
bool wifiSoftApOff(const char * fileName, uint32_t lineNumber) {return true;}
219218
bool wifiSoftApOn(const char * fileName, uint32_t lineNumber) {return false;}

Firmware/RTK_Everywhere/Network.ino

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,10 +2301,7 @@ void networkStartDelayed(NetIndex_t index, uintptr_t parameter, bool debug)
23012301
//----------------------------------------
23022302
void networkUpdate()
23032303
{
2304-
bool displayIpAddress;
23052304
NetIndex_t index;
2306-
IPAddress ipAddress;
2307-
bool ipAddressDisplayed;
23082305
uint8_t networkType;
23092306
NETWORK_POLL_ROUTINE pollRoutine;
23102307
uint8_t priority;
@@ -2317,18 +2314,8 @@ void networkUpdate()
23172314

23182315
// Handle the network lost internet event
23192316
if (networkEventInternetLost[index])
2320-
{
23212317
networkInterfaceInternetConnectionLost(index);
23222318

2323-
// Attempt to restart WiFi
2324-
if ((index == NETWORK_WIFI_STATION) && (networkIsHighestPriority(index)))
2325-
{
2326-
if (networkIsStarted(index))
2327-
networkStop(index, settings.debugWifiState, __FILE__, __LINE__);
2328-
networkStart(index, settings.debugWifiState, __FILE__, __LINE__);
2329-
}
2330-
}
2331-
23322319
// Handle the network stop event
23332320
if (networkEventStop[index])
23342321
networkStop(index, settings.debugNetworkLayer, __FILE__, __LINE__);
@@ -2363,6 +2350,9 @@ void networkUpdate()
23632350
}
23642351
}
23652352

2353+
// Update the WiFi state
2354+
wifiStationUpdate();
2355+
23662356
// Update the network services
23672357
// Start or stop mDNS
23682358
if (networkMdnsRequests != networkMdnsRunning)
@@ -2389,44 +2379,62 @@ void networkUpdate()
23892379
webServerUpdate(); // Start webServer for web config as needed
23902380

23912381
// Periodically display the network interface state
2392-
displayIpAddress = PERIODIC_DISPLAY(PD_IP_ADDRESS);
2393-
for (int index = 0; index < NETWORK_OFFLINE; index++)
2382+
if (PERIODIC_DISPLAY(PD_NETWORK_STATE))
23942383
{
2395-
// Display the current state
2396-
ipAddressDisplayed = displayIpAddress && (index == networkPriority);
2397-
if (PERIODIC_DISPLAY(networkInterfaceTable[index].pdState) || PERIODIC_DISPLAY(PD_NETWORK_STATE) ||
2398-
ipAddressDisplayed)
2399-
{
2384+
PERIODIC_CLEAR(PD_NETWORK_STATE);
2385+
PERIODIC_CLEAR(PD_IP_ADDRESS);
2386+
for (int index = 0; index < NETWORK_OFFLINE; index++)
24002387
PERIODIC_CLEAR(networkInterfaceTable[index].pdState);
2401-
if (networkInterfaceTable[index].netif->hasIP())
2402-
{
2403-
ipAddress = networkInterfaceTable[index].netif->localIP();
2404-
systemPrintf("%s: %s%s\r\n", networkInterfaceTable[index].name, ipAddress.toString().c_str(),
2405-
networkInterfaceTable[index].netif->isDefault() ? " (default)" : "");
2406-
}
2407-
else if (networkInterfaceTable[index].netif->linkUp())
2408-
systemPrintf("%s: Link Up\r\n", networkInterfaceTable[index].name);
2409-
else if (networkInterfaceTable[index].netif->started())
2410-
systemPrintf("%s: Started\r\n", networkInterfaceTable[index].name);
24112388

2412-
else if (index == NETWORK_WIFI_STATION && (WiFi.getMode() == WIFI_AP || WiFi.getMode() == WIFI_AP_STA))
2413-
{
2414-
// NETIF doesn't capture the IP address of a soft AP
2415-
ipAddress = WiFi.softAPIP();
2416-
systemPrintf("%s: %s%s\r\n", networkInterfaceTable[index].name, ipAddress.toString().c_str(),
2417-
networkInterfaceTable[index].netif->isDefault() ? " (default)" : "");
2418-
}
2419-
else
2420-
systemPrintf("%s: Stopped\r\n", networkInterfaceTable[index].name);
2421-
}
2389+
// Display the network state
2390+
networkDisplayStatus();
24222391
}
2423-
if (PERIODIC_DISPLAY(PD_NETWORK_STATE))
2424-
PERIODIC_CLEAR(PD_NETWORK_STATE);
2425-
if (displayIpAddress)
2392+
2393+
// Periodically display the IP address
2394+
else if (PERIODIC_DISPLAY(PD_IP_ADDRESS))
24262395
{
2427-
if (!ipAddressDisplayed)
2428-
systemPrintln("Network: Offline");
2396+
int index;
2397+
IPAddress ipAddress;
2398+
24292399
PERIODIC_CLEAR(PD_IP_ADDRESS);
2400+
2401+
// Display the IP address of the highest priority network
2402+
index = networkPriorityTable[networkPriority];
2403+
if ((index < NETWORK_OFFLINE)
2404+
&& networkInterfaceHasInternet(index)
2405+
&& networkInterfaceTable[index].netif->hasIP())
2406+
{
2407+
ipAddress = networkInterfaceTable[index].netif->localIP();
2408+
systemPrintf("%s: %s%s\r\n",
2409+
networkInterfaceTable[index].name,
2410+
ipAddress.toString().c_str(),
2411+
networkInterfaceTable[index].netif->isDefault() ? " (default)" : "");
2412+
}
2413+
else
2414+
systemPrintf("Network: Offline\r\n");
2415+
2416+
// Display the soft AP IP address
2417+
if (wifiSoftApOnline)
2418+
{
2419+
ipAddress = wifiSoftApGetIpAddress();
2420+
systemPrintf("WiFi Soft AP: %s\r\n", ipAddress.toString().c_str());
2421+
}
2422+
else
2423+
systemPrintf("WiFi Soft AP: Offline\r\n");
2424+
}
2425+
2426+
// Periodically display an interface state
2427+
else
2428+
{
2429+
for (int index = 0; index < NETWORK_OFFLINE; index++)
2430+
if (PERIODIC_DISPLAY(networkInterfaceTable[index].pdState))
2431+
{
2432+
PERIODIC_CLEAR(networkInterfaceTable[index].pdState);
2433+
2434+
// Display the state for an interface
2435+
networkPrintStatus(index);
2436+
networkDisplayInterface(index);
2437+
}
24302438
}
24312439
}
24322440

0 commit comments

Comments
 (0)