Skip to content

Commit 3828134

Browse files
authored
Merge pull request #411 from sparkfun/Fix_#370
Fix error in networkGetActiveType - resolves #370
2 parents b9d225c + 38aa82f commit 3828134

File tree

2 files changed

+50
-19
lines changed

2 files changed

+50
-19
lines changed

Firmware/RTK_Everywhere/Network.ino

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,23 @@ IPAddress networkGetSubnetMask(uint8_t networkType)
482482
//----------------------------------------
483483
uint8_t networkGetActiveType()
484484
{
485-
NETWORK_DATA *network;
486-
uint8_t type;
485+
// Previously we had this (which is wrong - network is not initialized):
486+
//NETWORK_DATA *network;
487+
//uint8_t type;
488+
//type = network->type;
489+
490+
// Is the intent this?
491+
//NETWORK_DATA *network;
492+
//uint8_t type;
493+
//network = &networkData;
494+
//type = network->type;
495+
496+
// Or this?
497+
uint8_t type = networkGetType();
498+
499+
if (settings.debugNetworkLayer)
500+
systemPrintf("networkGetActiveType: network type is %s\r\n", networkTypeToString(type));
487501

488-
type = network->type;
489502
if (type == NETWORK_TYPE_USE_DEFAULT)
490503
type = NETWORK_TYPE_ETHERNET;
491504
return type;
@@ -1063,8 +1076,13 @@ uint8_t networkTranslateNetworkType(uint8_t networkType, bool translateActive)
10631076
//----------------------------------------
10641077
const char *networkTypeToString(uint8_t type)
10651078
{
1079+
static const char unknown[] = { "Unknown" };
10661080
if (type >= networkNameEntries)
1067-
return "Unknown";
1081+
{
1082+
if (settings.debugNetworkLayer)
1083+
systemPrintf("networkTypeToString: unknown type %d", type);
1084+
return unknown;
1085+
}
10681086
return networkName[type];
10691087
}
10701088

Firmware/RTK_Everywhere/menuFirmware.ino

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ bool otaCheckVersion(char *versionAvailable, uint8_t versionAvailableLength)
517517
// If we were in WIFI_AP mode, return to WIFI_AP mode
518518
// There may be some overlap with systemState STATE_WIFI_CONFIG ? Not sure...
519519
if (wasInAPmode)
520-
WiFi.mode(WIFI_AP);
520+
wifiSetApMode();
521521

522522
if (systemState != STATE_WIFI_CONFIG)
523523
{
@@ -589,23 +589,36 @@ void otaUpdate()
589589
bool previouslyConnected = wifiIsConnected();
590590

591591
bool wasInAPmode;
592-
uint8_t networkType;
593592

594-
networkType = networkGetType();
595-
if ((networkType != NETWORK_TYPE_WIFI)
596-
|| (wifiConnect(settings.wifiConnectTimeoutMs, true, &wasInAPmode)
597-
== true)) // Use WIFI_AP_STA if already in WIFI_AP mode
598-
overTheAirUpdate();
599-
600-
// Update failed. If we were in WIFI_AP mode, return to WIFI_AP mode
601-
if (networkType == NETWORK_TYPE_WIFI)
593+
uint8_t networkType = networkGetActiveType();
594+
if ((networkType == NETWORK_TYPE_WIFI) && (wifiNetworkCount() == 0))
595+
{
596+
systemPrintln("Error: Please enter at least one SSID before getting keys");
597+
}
598+
else
602599
{
603-
if (wasInAPmode)
604-
wifiSetApMode();
600+
if ((networkType != NETWORK_TYPE_WIFI)
601+
|| (wifiConnect(settings.wifiConnectTimeoutMs, true, &wasInAPmode)
602+
== true)) // Use WIFI_AP_STA if already in WIFI_AP mode
603+
overTheAirUpdate();
605604

606-
// Update failed. If WiFi was originally off, turn it off again
607-
if (previouslyConnected == false)
608-
WIFI_STOP();
605+
// Update failed. If we were in WIFI_AP mode, return to WIFI_AP mode
606+
if (networkType == NETWORK_TYPE_WIFI)
607+
{
608+
if (wasInAPmode)
609+
wifiSetApMode();
610+
611+
if (systemState != STATE_WIFI_CONFIG)
612+
{
613+
// WIFI_STOP() turns off the entire radio including the webserver. We need to turn off Station mode
614+
// only. For now, unit exits AP mode via reset so if we are in AP config mode, leave WiFi Station
615+
// running.
616+
617+
// If WiFi was originally off, turn it off again
618+
if (previouslyConnected == false)
619+
WIFI_STOP();
620+
}
621+
}
609622
}
610623
#endif // COMPILE_NETWORK
611624
}

0 commit comments

Comments
 (0)