Browse Source

Prevent reconnecting when in AP mode if a web session or a telnet session is active

fastled
Xose Pérez 7 years ago
parent
commit
2dab43ec5d
3 changed files with 23 additions and 1 deletions
  1. +9
    -0
      code/espurna/telnet.ino
  2. +2
    -0
      code/espurna/web.ino
  3. +12
    -1
      code/espurna/wifi.ino

+ 9
- 0
code/espurna/telnet.ino View File

@ -23,6 +23,7 @@ void _telnetDisconnect(unsigned char clientId) {
_telnetClients[clientId]->free(); _telnetClients[clientId]->free();
_telnetClients[clientId] = NULL; _telnetClients[clientId] = NULL;
delete _telnetClients[clientId]; delete _telnetClients[clientId];
wifiReconnectCheck();
DEBUG_MSG_P(PSTR("[TELNET] Client #%d disconnected\n"), clientId); DEBUG_MSG_P(PSTR("[TELNET] Client #%d disconnected\n"), clientId);
} }
@ -96,6 +97,7 @@ void _telnetNewClient(AsyncClient *client) {
}, 0); }, 0);
DEBUG_MSG_P(PSTR("[TELNET] Client #%d connected\n"), i); DEBUG_MSG_P(PSTR("[TELNET] Client #%d connected\n"), i);
wifiReconnectCheck();
return; return;
} }
@ -115,6 +117,13 @@ void _telnetNewClient(AsyncClient *client) {
// Public API // Public API
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool telnetConnected() {
for (unsigned char i = 0; i < TELNET_MAX_CLIENTS; i++) {
if (_telnetClients[i] && _telnetClients[i]->connected()) return true;
}
return false;
}
unsigned char telnetWrite(unsigned char ch) { unsigned char telnetWrite(unsigned char ch) {
char data[1] = {ch}; char data[1] = {ch};
return _telnetWrite(data, 1); return _telnetWrite(data, 1);


+ 2
- 0
code/espurna/web.ino View File

@ -746,12 +746,14 @@ void _wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTy
DEBUG_MSG_P(PSTR("[WEBSOCKET] #%u connected, ip: %d.%d.%d.%d, url: %s\n"), client->id(), ip[0], ip[1], ip[2], ip[3], server->url()); DEBUG_MSG_P(PSTR("[WEBSOCKET] #%u connected, ip: %d.%d.%d.%d, url: %s\n"), client->id(), ip[0], ip[1], ip[2], ip[3], server->url());
_wsStart(client->id()); _wsStart(client->id());
client->_tempObject = new WebSocketIncommingBuffer(&_wsParse, true); client->_tempObject = new WebSocketIncommingBuffer(&_wsParse, true);
wifiReconnectCheck();
} else if(type == WS_EVT_DISCONNECT) { } else if(type == WS_EVT_DISCONNECT) {
DEBUG_MSG_P(PSTR("[WEBSOCKET] #%u disconnected\n"), client->id()); DEBUG_MSG_P(PSTR("[WEBSOCKET] #%u disconnected\n"), client->id());
if (client->_tempObject) { if (client->_tempObject) {
delete (WebSocketIncommingBuffer *) client->_tempObject; delete (WebSocketIncommingBuffer *) client->_tempObject;
} }
wifiReconnectCheck();
} else if(type == WS_EVT_ERROR) { } else if(type == WS_EVT_ERROR) {
DEBUG_MSG_P(PSTR("[WEBSOCKET] #%u error(%u): %s\n"), client->id(), *((uint16_t*)arg), (char*)data); DEBUG_MSG_P(PSTR("[WEBSOCKET] #%u error(%u): %s\n"), client->id(), *((uint16_t*)arg), (char*)data);


+ 12
- 1
code/espurna/wifi.ino View File

@ -45,12 +45,23 @@ bool createAP() {
return jw.createAP(); return jw.createAP();
} }
void wifiReconnectCheck() {
bool connected = false;
#if WEB_SUPPORT
if (wsConnected()) connected = true;
#endif
#if TELNET_SUPPORT
if (telnetConnected()) connected = true;
#endif
jw.setReconnectTimeout(connected ? 0 : WIFI_RECONNECT_INTERVAL);
}
void wifiConfigure() { void wifiConfigure() {
jw.setHostname(getSetting("hostname").c_str()); jw.setHostname(getSetting("hostname").c_str());
jw.setSoftAP(getSetting("hostname").c_str(), getSetting("adminPass", ADMIN_PASS).c_str()); jw.setSoftAP(getSetting("hostname").c_str(), getSetting("adminPass", ADMIN_PASS).c_str());
jw.setConnectTimeout(WIFI_CONNECT_TIMEOUT); jw.setConnectTimeout(WIFI_CONNECT_TIMEOUT);
jw.setReconnectTimeout(WIFI_RECONNECT_INTERVAL);
wifiReconnectCheck();
jw.setAPMode(WIFI_AP_MODE); jw.setAPMode(WIFI_AP_MODE);
jw.cleanNetworks(); jw.cleanNetworks();


Loading…
Cancel
Save