Browse Source

Defer wifi disconnection from web interface to allow request to return

fastled
Xose Pérez 7 years ago
parent
commit
4b557535e6
3 changed files with 9 additions and 7 deletions
  1. +1
    -1
      code/espurna/mqtt.ino
  2. +8
    -1
      code/espurna/web.ino
  3. +0
    -5
      code/espurna/wifi.ino

+ 1
- 1
code/espurna/mqtt.ino View File

@ -94,7 +94,7 @@ void _mqttOnConnect(bool sessionPresent) {
void _mqttOnDisconnect(AsyncMqttClientDisconnectReason reason) { void _mqttOnDisconnect(AsyncMqttClientDisconnectReason reason) {
DEBUG_MSG("[MQTT] Disconnected!\n");
DEBUG_MSG("[MQTT] Disconnected\n");
// Send disconnect event to subscribers // Send disconnect event to subscribers
for (unsigned char i = 0; i < _mqtt_callbacks.size(); i++) { for (unsigned char i = 0; i < _mqtt_callbacks.size(); i++) {


+ 8
- 1
code/espurna/web.ino View File

@ -14,6 +14,7 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
#include <Hash.h> #include <Hash.h>
#include <AsyncJson.h> #include <AsyncJson.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <Ticker.h>
AsyncWebServer server(80); AsyncWebServer server(80);
AsyncWebSocket ws("/ws"); AsyncWebSocket ws("/ws");
@ -24,6 +25,7 @@ typedef struct {
} ws_ticket_t; } ws_ticket_t;
ws_ticket_t _ticket[WS_BUFFER_SIZE]; ws_ticket_t _ticket[WS_BUFFER_SIZE];
Ticker deferred;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// WEBSOCKETS // WEBSOCKETS
@ -75,7 +77,12 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
DEBUG_MSG("[WEBSOCKET] Requested action: %s\n", action.c_str()); DEBUG_MSG("[WEBSOCKET] Requested action: %s\n", action.c_str());
if (action.equals("reset")) ESP.reset(); if (action.equals("reset")) ESP.reset();
if (action.equals("reconnect")) wifiDisconnect();
if (action.equals("reconnect")) {
// Let the HTTP request return and disconnect after 100ms
deferred.once_ms(100, wifiDisconnect);
}
if (action.equals("on")) relayStatus(relayID, true); if (action.equals("on")) relayStatus(relayID, true);
if (action.equals("off")) relayStatus(relayID, false); if (action.equals("off")) relayStatus(relayID, false);


+ 0
- 5
code/espurna/wifi.ino View File

@ -148,11 +148,6 @@ void wifiSetup() {
#endif #endif
// Disconnect from MQTT server if no WIFI
if (code != MESSAGE_CONNECTED) {
if (mqttConnected()) mqttDisconnect();
}
// Configure mDNS // Configure mDNS
if (code == MESSAGE_CONNECTED) { if (code == MESSAGE_CONNECTED) {


Loading…
Cancel
Save