mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-27 05:06:44 +00:00
Fix wifi connect/disconnect bug
This commit is contained in:
parent
4103535aac
commit
287f1f1e0b
@ -1175,24 +1175,28 @@ void dispatch_exec(const char*, const char* payload, uint8_t source)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char buffer[1024];
|
// char buffer[512]; // use stack
|
||||||
|
String buffer((char*)0); // use heap
|
||||||
|
buffer.reserve(256);
|
||||||
|
|
||||||
ReadBufferingStream bufferedFile{cmdfile, 256};
|
ReadBufferingStream bufferedFile{cmdfile, 256};
|
||||||
cmdfile.seek(0);
|
cmdfile.seek(0);
|
||||||
|
|
||||||
while(bufferedFile.available()) {
|
while(bufferedFile.available()) {
|
||||||
// int l = bufferedFile.readBytesUntil('\n', buffer, sizeof(buffer) - 1);
|
size_t index = 0; buffer="";
|
||||||
|
// while(index < sizeof(buffer) - 1) {
|
||||||
size_t index = 0;
|
while(index < MQTT_MAX_PACKET_SIZE) {
|
||||||
while(index < sizeof(buffer) - 1) {
|
|
||||||
int c = bufferedFile.read();
|
int c = bufferedFile.read();
|
||||||
if(c < 0 || c == '\n' || c == '\r') { // CR or LF
|
if(c < 0 || c == '\n' || c == '\r') { // CR or LF
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
buffer[index] = (char)c;
|
// buffer[index] = (char)c;
|
||||||
|
buffer += (char)c;
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
buffer[index] = 0; // terminate string
|
// buffer[index] = 0; // terminate string
|
||||||
if(index > 0 && buffer[0] != '#') dispatch_text_line(buffer, TAG_FILE); // # for comments
|
// if(index > 0 && buffer[0] != '#') dispatch_text_line(buffer.c_str(), TAG_FILE); // # for comments
|
||||||
|
if(index > 0 && buffer.charAt(0) != '#') dispatch_text_line(buffer.c_str(), TAG_FILE); // # for comments
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdfile.close();
|
cmdfile.close();
|
||||||
|
@ -51,6 +51,7 @@ char wifiPassword[64] = "";
|
|||||||
char wifiIpAddress[16] = "";
|
char wifiIpAddress[16] = "";
|
||||||
uint16_t wifiReconnectCounter = 0;
|
uint16_t wifiReconnectCounter = 0;
|
||||||
bool wifiOnline = false;
|
bool wifiOnline = false;
|
||||||
|
bool haspOnline = false;
|
||||||
|
|
||||||
// const byte DNS_PORT = 53;
|
// const byte DNS_PORT = 53;
|
||||||
// DNSServer dnsServer;
|
// DNSServer dnsServer;
|
||||||
@ -84,11 +85,11 @@ static void wifiConnected(IPAddress ipaddress)
|
|||||||
wifiOnline = true; // now we are connected
|
wifiOnline = true; // now we are connected
|
||||||
|
|
||||||
wifiReconnectCounter = 0;
|
wifiReconnectCounter = 0;
|
||||||
dispatch_exec(NULL, "/online.cmd", TAG_WIFI);
|
// dispatch_exec(NULL, "/online.cmd", TAG_WIFI);
|
||||||
|
|
||||||
LOG_VERBOSE(TAG_WIFI, F("Connected = %s"),
|
LOG_VERBOSE(TAG_WIFI, F("Connected = %s"),
|
||||||
WiFi.status() == WL_CONNECTED ? PSTR(D_NETWORK_ONLINE) : PSTR(D_NETWORK_OFFLINE));
|
WiFi.status() == WL_CONNECTED ? PSTR(D_NETWORK_ONLINE) : PSTR(D_NETWORK_OFFLINE));
|
||||||
networkStart();
|
// networkStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wifiDisconnected(const char* ssid, uint8_t reason)
|
static void wifiDisconnected(const char* ssid, uint8_t reason)
|
||||||
@ -287,8 +288,10 @@ static void wifiDisconnected(const char* ssid, uint8_t reason)
|
|||||||
else
|
else
|
||||||
wifiOnline = false; // now we are disconnected
|
wifiOnline = false; // now we are disconnected
|
||||||
|
|
||||||
dispatch_exec(NULL, "/offline.cmd", TAG_WIFI);
|
// dispatch_exec(NULL, "/offline.cmd", TAG_WIFI);
|
||||||
networkStop();
|
LOG_VERBOSE(TAG_WIFI, F("Connected = %s"),
|
||||||
|
WiFi.status() == WL_CONNECTED ? PSTR(D_NETWORK_ONLINE) : PSTR(D_NETWORK_OFFLINE));
|
||||||
|
// networkStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wifiSsidConnected(const char* ssid)
|
static void wifiSsidConnected(const char* ssid)
|
||||||
@ -470,18 +473,31 @@ bool wifiEvery5Seconds()
|
|||||||
#if defined(STM32F4xx)
|
#if defined(STM32F4xx)
|
||||||
if(wifiShowAP()) { // no ssid is set yet wait for user on-screen input
|
if(wifiShowAP()) { // no ssid is set yet wait for user on-screen input
|
||||||
return false;
|
return false;
|
||||||
} else if(WiFi.status() == WL_CONNECTED) {
|
}
|
||||||
#else
|
#else
|
||||||
if(WiFi.getMode() != WIFI_STA) {
|
if(WiFi.getMode() != WIFI_STA) {
|
||||||
return false;
|
return false;
|
||||||
} else if(WiFi.status() == WL_CONNECTED) {
|
|
||||||
#endif
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
LOG_WARNING(TAG_WIFI, F("No Connection... retry %d"), wifiReconnectCounter);
|
|
||||||
wifiReconnect();
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(wifiOnline != haspOnline) {
|
||||||
|
if(wifiOnline) {
|
||||||
|
dispatch_exec(NULL, "/online.cmd", TAG_WIFI);
|
||||||
|
networkStart();
|
||||||
|
} else {
|
||||||
|
dispatch_exec(NULL, "/offline.cmd", TAG_WIFI);
|
||||||
|
networkStop();
|
||||||
|
}
|
||||||
|
haspOnline = wifiOnline;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(WiFi.status() == WL_CONNECTED) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_WARNING(TAG_WIFI, F("No Connection... retry %d"), wifiReconnectCounter);
|
||||||
|
wifiReconnect();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wifiValidateSsid(const char* ssid, const char* pass)
|
bool wifiValidateSsid(const char* ssid, const char* pass)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user