-
Notifications
You must be signed in to change notification settings - Fork 964
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #421 from mc-hamster/master
Fix for Bug #420 : Wifi in station mode sometimes enters loops of repeatedly joining
- Loading branch information
Showing
5 changed files
with
150 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,5 @@ void handleJSONChatHistory(); | |
void notifyWebUI(); | ||
|
||
void handleHotspot(); | ||
|
||
void handleRoot(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,19 +3,22 @@ | |
#include "configuration.h" | ||
#include "main.h" | ||
#include "meshwifi/meshhttp.h" | ||
#include <WiFi.h> | ||
#include <DNSServer.h> | ||
#include <WiFi.h> | ||
|
||
static void WiFiEvent(WiFiEvent_t event); | ||
|
||
DNSServer dnsServer; | ||
|
||
bool isWifiAvailable() | ||
bool isWifiAvailable() | ||
{ | ||
const char *wifiName = radioConfig.preferences.wifi_ssid; | ||
const char *wifiPsw = radioConfig.preferences.wifi_password; | ||
|
||
if (*wifiName && *wifiPsw) { | ||
|
||
// Once every 10 seconds, try to reconnect. | ||
|
||
return 1; | ||
} else { | ||
return 0; | ||
|
@@ -26,7 +29,7 @@ bool isWifiAvailable() | |
void deinitWifi() | ||
{ | ||
/* | ||
Note from Jm (Sept 16, 2020): | ||
Note from Jm ([email protected] - Sept 16, 2020): | ||
A bug in the ESP32 SDK was introduced in Oct 2019 that keeps the WiFi radio from | ||
turning back on after it's shut off. See: | ||
|
@@ -38,7 +41,7 @@ void deinitWifi() | |
|
||
WiFi.mode(WIFI_MODE_NULL); | ||
DEBUG_MSG("WiFi Turned Off\n"); | ||
WiFi.printDiag(Serial); | ||
// WiFi.printDiag(Serial); | ||
} | ||
|
||
// Startup WiFi | ||
|
@@ -53,7 +56,7 @@ void initWifi() | |
const char *wifiPsw = radioConfig.preferences.wifi_password; | ||
|
||
/* | ||
if (1) { | ||
if (0) { | ||
radioConfig.preferences.wifi_ap_mode = 1; | ||
strcpy(radioConfig.preferences.wifi_ssid, "MeshTest2"); | ||
strcpy(radioConfig.preferences.wifi_password, "12345678"); | ||
|
@@ -62,11 +65,11 @@ void initWifi() | |
strcpy(radioConfig.preferences.wifi_ssid, "meshtastic"); | ||
strcpy(radioConfig.preferences.wifi_password, "meshtastic!"); | ||
} | ||
*/ | ||
*/ | ||
|
||
if (*wifiName && *wifiPsw) { | ||
if (radioConfig.preferences.wifi_ap_mode) { | ||
|
||
IPAddress apIP(192, 168, 42, 1); | ||
WiFi.onEvent(WiFiEvent); | ||
|
||
|
@@ -76,7 +79,6 @@ void initWifi() | |
|
||
dnsServer.start(53, "*", apIP); | ||
|
||
|
||
} else { | ||
WiFi.mode(WIFI_MODE_STA); | ||
WiFi.onEvent(WiFiEvent); | ||
|
@@ -116,9 +118,9 @@ static void WiFiEvent(WiFiEvent_t event) | |
break; | ||
case SYSTEM_EVENT_STA_DISCONNECTED: | ||
DEBUG_MSG("Disconnected from WiFi access point\n"); | ||
// Event 5 | ||
|
||
// Reconnect WiFi | ||
initWifi(); | ||
reconnectWiFi(); | ||
break; | ||
case SYSTEM_EVENT_STA_AUTHMODE_CHANGE: | ||
DEBUG_MSG("Authentication mode of access point has changed\n"); | ||
|
@@ -189,12 +191,29 @@ static void WiFiEvent(WiFiEvent_t event) | |
break; | ||
default: | ||
break; | ||
|
||
} | ||
} | ||
|
||
void handleDNSResponse() { | ||
void handleDNSResponse() | ||
{ | ||
if (radioConfig.preferences.wifi_ap_mode) { | ||
dnsServer.processNextRequest(); | ||
} | ||
} | ||
|
||
void reconnectWiFi() | ||
{ | ||
const char *wifiName = radioConfig.preferences.wifi_ssid; | ||
const char *wifiPsw = radioConfig.preferences.wifi_password; | ||
|
||
if (radioConfig.has_preferences) { | ||
|
||
if (*wifiName && *wifiPsw) { | ||
|
||
DEBUG_MSG("... Reconnecting to WiFi access point"); | ||
|
||
WiFi.mode(WIFI_MODE_STA); | ||
WiFi.begin(wifiName, wifiPsw); | ||
} | ||
} | ||
} |
Oops, something went wrong.