mirror of
https://github.com/meshtastic/firmware.git
synced 2026-01-30 05:32:08 +00:00
Fix for "Wifi in station mode sometimes enters loops of repeatedly joining... #420"
Fix for Wifi in station mode sometimes enters loops of repeatedly joining... #420
This commit is contained in:
@@ -8,7 +8,9 @@
|
||||
|
||||
WebServer webserver(80);
|
||||
|
||||
struct message {
|
||||
const uint16_t maxMessages = 50;
|
||||
|
||||
struct message_t {
|
||||
char sender[10];
|
||||
char message[250];
|
||||
int32_t gpsLat;
|
||||
@@ -17,7 +19,12 @@ struct message {
|
||||
bool fromMe;
|
||||
};
|
||||
|
||||
struct message arrayMessages[50];
|
||||
struct messages_t
|
||||
{
|
||||
message_t history[maxMessages]; // 900 positions to save up to 1200 seconds (15 minutes). uInt for each temerature sensor, Input and Setpoint.
|
||||
};
|
||||
|
||||
messages_t messages_history;
|
||||
|
||||
String something = "";
|
||||
String sender = "";
|
||||
@@ -50,6 +57,7 @@ void initWebServer()
|
||||
|
||||
void handleJSONChatHistory()
|
||||
{
|
||||
int i;
|
||||
|
||||
String out = "";
|
||||
out += "{\n";
|
||||
@@ -61,6 +69,14 @@ void handleJSONChatHistory()
|
||||
out += "\"" + something + "\"";
|
||||
out += "]\n";
|
||||
|
||||
for (i = 0; i < maxMessages; i++) {
|
||||
out += "[";
|
||||
out += "\"" + String(messages_history.history[i].sender) + "\"";
|
||||
out += ",";
|
||||
out += "\"" + String(messages_history.history[i].message) + "\"";
|
||||
out += "]\n";
|
||||
}
|
||||
|
||||
out += "\n";
|
||||
out += " }\n";
|
||||
out += "}\n";
|
||||
|
||||
@@ -17,9 +17,7 @@ bool isWifiAvailable()
|
||||
|
||||
if (*wifiName && *wifiPsw) {
|
||||
|
||||
|
||||
//
|
||||
|
||||
// Once every 10 seconds, try to reconnect.
|
||||
|
||||
return 1;
|
||||
} else {
|
||||
@@ -43,7 +41,7 @@ void deinitWifi()
|
||||
|
||||
WiFi.mode(WIFI_MODE_NULL);
|
||||
DEBUG_MSG("WiFi Turned Off\n");
|
||||
WiFi.printDiag(Serial);
|
||||
// WiFi.printDiag(Serial);
|
||||
}
|
||||
|
||||
// Startup WiFi
|
||||
@@ -57,17 +55,17 @@ void initWifi()
|
||||
const char *wifiName = radioConfig.preferences.wifi_ssid;
|
||||
const char *wifiPsw = radioConfig.preferences.wifi_password;
|
||||
|
||||
/*
|
||||
if (0) {
|
||||
radioConfig.preferences.wifi_ap_mode = 1;
|
||||
strcpy(radioConfig.preferences.wifi_ssid, "MeshTest2");
|
||||
strcpy(radioConfig.preferences.wifi_password, "12345678");
|
||||
} else {
|
||||
radioConfig.preferences.wifi_ap_mode = 0;
|
||||
strcpy(radioConfig.preferences.wifi_ssid, "meshtastic1");
|
||||
strcpy(radioConfig.preferences.wifi_ssid, "meshtastic");
|
||||
strcpy(radioConfig.preferences.wifi_password, "meshtastic!");
|
||||
}
|
||||
/*
|
||||
*/
|
||||
*/
|
||||
|
||||
if (*wifiName && *wifiPsw) {
|
||||
if (radioConfig.preferences.wifi_ap_mode) {
|
||||
@@ -120,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");
|
||||
@@ -201,4 +199,21 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,8 @@
|
||||
#include <functional>
|
||||
|
||||
#ifdef HAS_WIFI
|
||||
#include <WiFi.h>
|
||||
#include <DNSServer.h>
|
||||
#include <WiFi.h>
|
||||
#endif
|
||||
|
||||
void initWifi();
|
||||
@@ -14,3 +14,5 @@ void deinitWifi();
|
||||
bool isWifiAvailable();
|
||||
|
||||
void handleDNSResponse();
|
||||
|
||||
void reconnectWiFi();
|
||||
|
||||
Reference in New Issue
Block a user