Browse Source

Option to disable MQTT at build time

fastled
Xose Pérez 6 years ago
parent
commit
d1abe1fc65
22 changed files with 2723 additions and 2630 deletions
  1. +3
    -1
      code/espurna/analog.ino
  2. +4
    -0
      code/espurna/button.ino
  3. +8
    -3
      code/espurna/config/general.h
  4. +0
    -4
      code/espurna/config/prototypes.h
  5. +3
    -1
      code/espurna/counter.ino
  6. BIN
      code/espurna/data/index.html.gz
  7. +4
    -2
      code/espurna/dht.ino
  8. +3
    -1
      code/espurna/ds18b20.ino
  9. +6
    -2
      code/espurna/espurna.ino
  10. +5
    -1
      code/espurna/led.ino
  11. +27
    -19
      code/espurna/light.ino
  12. +2
    -0
      code/espurna/mdns.ino
  13. +5
    -0
      code/espurna/mqtt.ino
  14. +3
    -0
      code/espurna/power.ino
  15. +13
    -4
      code/espurna/relay.ino
  16. +12
    -3
      code/espurna/rfbridge.ino
  17. +8
    -6
      code/espurna/settings.ino
  18. +2523
    -2522
      code/espurna/static/index.html.gz.h
  19. +69
    -48
      code/espurna/utils.ino
  20. +3
    -1
      code/espurna/wifi.ino
  21. +17
    -7
      code/espurna/ws.ino
  22. +5
    -5
      code/html/index.html

+ 3
- 1
code/espurna/analog.ino View File

@ -55,7 +55,9 @@ void analogLoop() {
DEBUG_MSG_P(PSTR("[ANALOG] Value: %d\n"), analog);
// Send MQTT messages
mqttSend(getSetting("analogTopic", ANALOG_TOPIC).c_str(), String(analog).c_str());
#if MQTT_SUPPORT
mqttSend(getSetting("analogTopic", ANALOG_TOPIC).c_str(), String(analog).c_str());
#endif
// Send to Domoticz
#if DOMOTICZ_SUPPORT


+ 4
- 0
code/espurna/button.ino View File

@ -21,6 +21,7 @@ typedef struct {
std::vector<button_t> _buttons;
#if MQTT_SUPPORT
#ifdef MQTT_TOPIC_BUTTON
void buttonMQTT(unsigned char id, uint8_t event) {
if (id >= _buttons.size()) return;
@ -29,6 +30,7 @@ void buttonMQTT(unsigned char id, uint8_t event) {
mqttSend(MQTT_TOPIC_BUTTON, id, payload);
}
#endif
#endif
int buttonFromRelay(unsigned int relayID) {
for (unsigned int i=0; i < _buttons.size(); i++) {
@ -81,9 +83,11 @@ void buttonEvent(unsigned int id, unsigned char event) {
DEBUG_MSG_P(PSTR("[BUTTON] Pressed #%d, event: %d\n"), id, event);
if (event == 0) return;
#if MQTT_SUPPORT
#ifdef MQTT_TOPIC_BUTTON
buttonMQTT(id, event);
#endif
#endif
unsigned char action = buttonAction(id, event);


+ 8
- 3
code/espurna/config/general.h View File

@ -369,8 +369,13 @@ PROGMEM const char* const custom_reset_string[] = {
// MQTT
// -----------------------------------------------------------------------------
#ifndef MQTT_SUPPORT
#define MQTT_SUPPORT 1 // MQTT support (22.38Kb async, 12.48Kb sync)
#endif
#ifndef MQTT_USE_ASYNC
#define MQTT_USE_ASYNC 1 // Use AysncMQTTClient (1) or PubSubClient (0, 9.83Kb less)
#define MQTT_USE_ASYNC 1 // Use AysncMQTTClient (1) or PubSubClient
#endif
// MQTT OVER SSL
@ -673,7 +678,7 @@ PROGMEM const char* const custom_reset_string[] = {
// -----------------------------------------------------------------------------
#ifndef DOMOTICZ_SUPPORT
#define DOMOTICZ_SUPPORT 1 // Build with domoticz support (1.72Kb)
#define DOMOTICZ_SUPPORT MQTT_SUPPORT // Build with domoticz (if MQTT) support (1.72Kb)
#endif
#define DOMOTICZ_ENABLED 0 // Disable domoticz by default
@ -686,7 +691,7 @@ PROGMEM const char* const custom_reset_string[] = {
// -----------------------------------------------------------------------------
#ifndef HOMEASSISTANT_SUPPORT
#define HOMEASSISTANT_SUPPORT 1 // Build with home assistant support (1.64Kb)
#define HOMEASSISTANT_SUPPORT MQTT_SUPPORT // Build with home assistant support (if MQTT, 1.64Kb)
#endif
#define HOMEASSISTANT_ENABLED 0 // Integration not enabled by default


+ 0
- 4
code/espurna/config/prototypes.h View File

@ -6,8 +6,6 @@ extern "C" {
#include "user_interface.h"
}
#if WEB_SUPPORT
// -----------------------------------------------------------------------------
// WebServer
// -----------------------------------------------------------------------------
@ -34,8 +32,6 @@ void wsOnActionRegister(ws_on_action_callback_f callback);
typedef std::function<void(void)> ws_on_after_parse_callback_f;
void wsOnAfterParseRegister(ws_on_after_parse_callback_f callback);
#endif // WEB_SUPPORT
// -----------------------------------------------------------------------------
// MQTT
// -----------------------------------------------------------------------------


+ 3
- 1
code/espurna/counter.ino View File

@ -82,7 +82,9 @@ void counterLoop() {
if (_counterBufferPointer == 0) {
// Send MQTT messages
mqttSend(getSetting("counterTopic", COUNTER_TOPIC).c_str(), String(_counterValue).c_str());
#if MQTT_SUPPORT
mqttSend(getSetting("counterTopic", COUNTER_TOPIC).c_str(), String(_counterValue).c_str());
#endif
// Send to Domoticz
#if DOMOTICZ_SUPPORT


BIN
code/espurna/data/index.html.gz View File


+ 4
- 2
code/espurna/dht.ino View File

@ -232,8 +232,10 @@ void dhtLoop() {
last_humidity = h;
// Send MQTT messages
mqttSend(getSetting("dhtTmpTopic", DHT_TEMPERATURE_TOPIC).c_str(), temperature);
mqttSend(getSetting("dhtHumTopic", DHT_HUMIDITY_TOPIC).c_str(), humidity);
#if MQTT_SUPPORT
mqttSend(getSetting("dhtTmpTopic", DHT_TEMPERATURE_TOPIC).c_str(), temperature);
mqttSend(getSetting("dhtHumTopic", DHT_HUMIDITY_TOPIC).c_str(), humidity);
#endif
// Send to Domoticz
#if DOMOTICZ_SUPPORT


+ 3
- 1
code/espurna/ds18b20.ino View File

@ -120,7 +120,9 @@ void dsLoop() {
last_temperature = _dsTemperature;
// Send MQTT messages
mqttSend(getSetting("dsTmpTopic", DS18B20_TEMPERATURE_TOPIC).c_str(), temperature);
#if MQTT_SUPPORT
mqttSend(getSetting("dsTmpTopic", DS18B20_TEMPERATURE_TOPIC).c_str(), temperature);
#endif
// Send to Domoticz
#if DOMOTICZ_SUPPORT


+ 6
- 2
code/espurna/espurna.ino View File

@ -269,7 +269,9 @@ void setup() {
relaySetup();
buttonSetup();
ledSetup();
mqttSetup();
#if MQTT_SUPPORT
mqttSetup();
#endif
#if MDNS_SUPPORT
mdnsSetup();
@ -352,7 +354,9 @@ void loop() {
relayLoop();
buttonLoop();
ledLoop();
mqttLoop();
#if MQTT_SUPPORT
mqttLoop();
#endif
#ifdef ITEAD_SONOFF_RFBRIDGE
rfbLoop();


+ 5
- 1
code/espurna/led.ino View File

@ -58,6 +58,7 @@ void showStatus() {
}
#endif
#if MQTT_SUPPORT
void ledMQTTCallback(unsigned int type, const char * topic, const char * payload) {
static bool isFirstMessage = true;
@ -99,6 +100,7 @@ void ledMQTTCallback(unsigned int type, const char * topic, const char * payload
}
}
#endif
unsigned char ledCount() {
return _leds.size();
@ -130,7 +132,9 @@ void ledSetup() {
ledConfigure();
mqttRegister(ledMQTTCallback);
#if MQTT_SUPPORT
mqttRegister(ledMQTTCallback);
#endif
DEBUG_MSG_P(PSTR("[LED] Number of leds: %d\n"), _leds.size());
DEBUG_MSG_P(PSTR("[LED] Led auto indicator is %s\n"), ledAuto ? "ON" : "OFF" );


+ 27
- 19
code/espurna/light.ino View File

@ -433,6 +433,7 @@ void _lightColorRestore() {
// MQTT
// -----------------------------------------------------------------------------
#if MQTT_SUPPORT
void _lightMQTTCallback(unsigned int type, const char * topic, const char * payload) {
@ -501,23 +502,6 @@ void _lightMQTTCallback(unsigned int type, const char * topic, const char * payl
}
// -----------------------------------------------------------------------------
// API
// -----------------------------------------------------------------------------
unsigned char lightChannels() {
return _channels.size();
}
bool lightHasColor() {
bool useColor = getSetting("useColor", LIGHT_USE_COLOR).toInt() == 1;
return useColor && (_channels.size() > 2);
}
unsigned char lightWhiteChannels() {
return _channels.size() % 3;
}
void lightMQTT() {
char buffer[12];
@ -549,12 +533,33 @@ void lightMQTT() {
}
#endif
// -----------------------------------------------------------------------------
// API
// -----------------------------------------------------------------------------
unsigned char lightChannels() {
return _channels.size();
}
bool lightHasColor() {
bool useColor = getSetting("useColor", LIGHT_USE_COLOR).toInt() == 1;
return useColor && (_channels.size() > 2);
}
unsigned char lightWhiteChannels() {
return _channels.size() % 3;
}
void lightUpdate(bool save, bool forward) {
_lightProviderUpdate();
// Report color & brightness to MQTT broker
if (forward) lightMQTT();
#if MQTT_SUPPORT
if (forward) lightMQTT();
#endif
// Report color to WS clients (using current brightness setting)
#if WEB_SUPPORT
@ -897,6 +902,7 @@ void lightSetup() {
DEBUG_MSG_P(PSTR("[LIGHT] Number of channels: %d\n"), _channels.size());
_lightColorRestore();
#if WEB_SUPPORT
_lightAPISetup();
wsOnSendRegister(_lightWebSocketOnSend);
@ -906,7 +912,9 @@ void lightSetup() {
#endif
#endif
mqttRegister(_lightMQTTCallback);
#if MQTT_SUPPORT
mqttRegister(_lightMQTTCallback);
#endif
}


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

@ -13,6 +13,7 @@ Copyright (C) 2017 by Xose Pérez <xose dot perez at gmail dot com>
WiFiEventHandler _mdns_wifi_onSTA;
WiFiEventHandler _mdns_wifi_onAP;
#if MQTT_SUPPORT
void mdnsFindMQTT() {
int count = MDNS.queryService("mqtt", "tcp");
DEBUG_MSG_P("[MQTT] MQTT brokers found: %d\n", count);
@ -21,6 +22,7 @@ void mdnsFindMQTT() {
mqttSetBrokerIfNone(MDNS.IP(i), MDNS.port(i));
}
}
#endif
void _mdnsStart() {
if (MDNS.begin(WiFi.getMode() == WIFI_AP ? APP_NAME : (char *) WiFi.hostname().c_str())) {


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

@ -6,6 +6,8 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
*/
#if MQTT_SUPPORT
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ArduinoJson.h>
@ -201,6 +203,7 @@ void mqttRegister(mqtt_callback_f callback) {
// -----------------------------------------------------------------------------
void _mqttWebSocketOnSend(JsonObject& root) {
root["mqttVisible"] = 1;
root["mqttStatus"] = mqttConnected();
root["mqttEnabled"] = mqttEnabled();
root["mqttServer"] = getSetting("mqttServer", MQTT_SERVER);
@ -602,3 +605,5 @@ void mqttLoop() {
#endif
}
#endif // MQTT_SUPPORT

+ 3
- 0
code/espurna/power.ino View File

@ -227,6 +227,8 @@ void _powerReport() {
dtostrf(_power_current, 1-sizeof(buf_current), POWER_CURRENT_DECIMALS, buf_current);
dtostrf(energy_delta * POWER_ENERGY_FACTOR, 1-sizeof(buf_energy_delta), POWER_ENERGY_DECIMALS, buf_energy_delta);
dtostrf(_power_energy * POWER_ENERGY_FACTOR, 1-sizeof(buf_energy_total), POWER_ENERGY_DECIMALS, buf_energy_total);
#if MQTT_SUPPORT
{
mqttSend(MQTT_TOPIC_CURRENT, buf_current);
mqttSend(MQTT_TOPIC_POWER_APPARENT, String((int) _power_apparent).c_str());
@ -239,6 +241,7 @@ void _powerReport() {
mqttSend(MQTT_TOPIC_POWER_FACTOR, String((int) 100 * _power_factor).c_str());
#endif
}
#endif
#if DOMOTICZ_SUPPORT
if (domoticzEnabled()) {


+ 13
- 4
code/espurna/relay.ino View File

@ -143,6 +143,7 @@ void relayPulseMode(unsigned int value, bool report) {
setSetting("relayPulseMode", value);
/*
#if MQTT_SUPPORT
if (report) {
char topic[strlen(MQTT_TOPIC_RELAY) + 10];
snprintf_P(topic, sizeof(topic), PSTR("%s/pulse"), MQTT_TOPIC_RELAY);
@ -150,6 +151,7 @@ void relayPulseMode(unsigned int value, bool report) {
snprintf_P(value, sizeof(value), PSTR("%d"), value);
mqttSend(topic, value);
}
#endif
*/
#if WEB_SUPPORT
@ -465,6 +467,8 @@ void relayWS() {
// MQTT
//------------------------------------------------------------------------------
#if MQTT_SUPPORT
void relayMQTT(unsigned char id) {
if (id >= _relays.size()) return;
mqttSend(MQTT_TOPIC_RELAY, id, relayStatus(id) ? "1" : "0");
@ -533,6 +537,8 @@ void relaySetupMQTT() {
mqttRegister(relayMQTTCallback);
}
#endif
//------------------------------------------------------------------------------
// InfluxDB
//------------------------------------------------------------------------------
@ -593,7 +599,10 @@ void relaySetup() {
wsOnSendRegister(_relayWebSocketOnSend);
wsOnActionRegister(_relayWebSocketOnAction);
#endif
relaySetupMQTT();
#if MQTT_SUPPORT
relaySetupMQTT();
#endif
DEBUG_MSG_P(PSTR("[RELAY] Number of relays: %d\n"), _relays.size());
@ -621,9 +630,9 @@ void relayLoop(void) {
}
// Send MQTT report if requested
if (_relays[id].scheduledReport) {
relayMQTT(id);
}
#if MQTT_SUPPORT
if (_relays[id].scheduledReport) relayMQTT(id);
#endif
if (!recursive) {
relayPulse(id);


+ 12
- 3
code/espurna/rfbridge.ino View File

@ -131,8 +131,10 @@ void _rfbDecode() {
}
if (action == RF_CODE_LEARN_OK || action == RF_CODE_RFIN) {
_rfbToChar(&_uartbuf[1], buffer);
mqttSend(MQTT_TOPIC_RFIN, buffer);
#if MQTT_SUPPORT
_rfbToChar(&_uartbuf[1], buffer);
mqttSend(MQTT_TOPIC_RFIN, buffer);
#endif
_rfbAck();
}
@ -243,6 +245,7 @@ bool _rfbToChar(byte * in, char * out) {
return true;
}
#if MQTT_SUPPORT
void _rfbMqttCallback(unsigned int type, const char * topic, const char * payload) {
if (type == MQTT_CONNECT_EVENT) {
@ -287,6 +290,7 @@ void _rfbMqttCallback(unsigned int type, const char * topic, const char * payloa
}
}
#endif
// -----------------------------------------------------------------------------
// PUBLIC
@ -343,11 +347,16 @@ void rfbForget(unsigned char id, bool status) {
// -----------------------------------------------------------------------------
void rfbSetup() {
mqttRegister(_rfbMqttCallback);
#if MQTT_SUPPORT
mqttRegister(_rfbMqttCallback);
#endif
#if WEB_SUPPORT
wsOnSendRegister(_rfbWebSocketOnSend);
wsOnActionRegister(_rfbWebSocketOnAction);
#endif
}
void rfbLoop() {


+ 8
- 6
code/espurna/settings.ino View File

@ -132,12 +132,14 @@ void settingsSetup() {
DEBUG_MSG_P(PSTR("+OK\n"));
});
Embedis::command( F("RESET.MQTT"), [](Embedis* e) {
mqttConfigure();
mqttDisconnect();
DEBUG_MSG_P(PSTR("+OK\n"));
});
#if MQTT_SUPPORT
Embedis::command( F("RESET.MQTT"), [](Embedis* e) {
mqttConfigure();
mqttDisconnect();
DEBUG_MSG_P(PSTR("+OK\n"));
});
#endif
Embedis::command( F("INFO"), [](Embedis* e) {
welcome();
DEBUG_MSG_P(PSTR("+OK\n"));


+ 2523
- 2522
code/espurna/static/index.html.gz.h
File diff suppressed because it is too large
View File


+ 69
- 48
code/espurna/utils.ino View File

@ -81,67 +81,88 @@ void heartbeat() {
unsigned long uptime_seconds = getUptime();
unsigned int free_heap = ESP.getFreeHeap();
#if NTP_SUPPORT
DEBUG_MSG_P(PSTR("[MAIN] Time: %s\n"), (char *) ntpDateTime().c_str());
// -------------------------------------------------------------------------
// MQTT
// -------------------------------------------------------------------------
#if MQTT_SUPPORT
#if (HEARTBEAT_REPORT_INTERVAL)
mqttSend(MQTT_TOPIC_INTERVAL, HEARTBEAT_INTERVAL / 1000);
#endif
#if (HEARTBEAT_REPORT_APP)
mqttSend(MQTT_TOPIC_APP, APP_NAME);
#endif
#if (HEARTBEAT_REPORT_VERSION)
mqttSend(MQTT_TOPIC_VERSION, APP_VERSION);
#endif
#if (HEARTBEAT_REPORT_HOSTNAME)
mqttSend(MQTT_TOPIC_HOSTNAME, getSetting("hostname").c_str());
#endif
#if (HEARTBEAT_REPORT_IP)
mqttSend(MQTT_TOPIC_IP, getIP().c_str());
#endif
#if (HEARTBEAT_REPORT_MAC)
mqttSend(MQTT_TOPIC_MAC, WiFi.macAddress().c_str());
#endif
#if (HEARTBEAT_REPORT_RSSI)
mqttSend(MQTT_TOPIC_RSSI, String(WiFi.RSSI()).c_str());
#endif
#if (HEARTBEAT_REPORT_UPTIME)
mqttSend(MQTT_TOPIC_UPTIME, String(uptime_seconds).c_str());
#endif
#if (HEARTBEAT_REPORT_FREEHEAP)
mqttSend(MQTT_TOPIC_FREEHEAP, String(free_heap).c_str());
#endif
#if (HEARTBEAT_REPORT_RELAY)
relayMQTT();
#endif
#if (LIGHT_PROVIDER != LIGHT_PROVIDER_NONE) & (HEARTBEAT_REPORT_LIGHT)
lightMQTT();
#endif
#if (HEARTBEAT_REPORT_VCC)
#if ADC_VCC_ENABLED
mqttSend(MQTT_TOPIC_VCC, String(ESP.getVcc()).c_str());
#endif
#endif
#if (HEARTBEAT_REPORT_STATUS)
mqttSend(MQTT_TOPIC_STATUS, MQTT_STATUS_ONLINE, true);
#endif
bool serial = !mqttConnected();
#else
bool serial = true;
#endif
if (!mqttConnected()) {
// -------------------------------------------------------------------------
// Serial
// -------------------------------------------------------------------------
if (serial) {
DEBUG_MSG_P(PSTR("[MAIN] Uptime: %ld seconds\n"), uptime_seconds);
DEBUG_MSG_P(PSTR("[MAIN] Free heap: %d bytes\n"), free_heap);
#if ADC_VCC_ENABLED
DEBUG_MSG_P(PSTR("[MAIN] Power: %d mV\n"), ESP.getVcc());
#endif
}
#if (HEARTBEAT_REPORT_INTERVAL)
mqttSend(MQTT_TOPIC_INTERVAL, HEARTBEAT_INTERVAL / 1000);
#endif
#if (HEARTBEAT_REPORT_APP)
mqttSend(MQTT_TOPIC_APP, APP_NAME);
#endif
#if (HEARTBEAT_REPORT_VERSION)
mqttSend(MQTT_TOPIC_VERSION, APP_VERSION);
#endif
#if (HEARTBEAT_REPORT_HOSTNAME)
mqttSend(MQTT_TOPIC_HOSTNAME, getSetting("hostname").c_str());
#endif
#if (HEARTBEAT_REPORT_IP)
mqttSend(MQTT_TOPIC_IP, getIP().c_str());
#endif
#if (HEARTBEAT_REPORT_MAC)
mqttSend(MQTT_TOPIC_MAC, WiFi.macAddress().c_str());
#endif
#if (HEARTBEAT_REPORT_RSSI)
mqttSend(MQTT_TOPIC_RSSI, String(WiFi.RSSI()).c_str());
#if NTP_SUPPORT
DEBUG_MSG_P(PSTR("[MAIN] Time: %s\n"), (char *) ntpDateTime().c_str());
#endif
#if (HEARTBEAT_REPORT_UPTIME)
mqttSend(MQTT_TOPIC_UPTIME, String(uptime_seconds).c_str());
#if INFLUXDB_SUPPORT
idbSend(MQTT_TOPIC_UPTIME, String(uptime_seconds).c_str());
// -------------------------------------------------------------------------
// InfluxDB
// -------------------------------------------------------------------------
#if INFLUXDB_SUPPORT
#if (HEARTBEAT_REPORT_UPTIME)
idbSend(MQTT_TOPIC_UPTIME, String(uptime_seconds).c_str());
#endif
#endif
#if (HEARTBEAT_REPORT_FREEHEAP)
mqttSend(MQTT_TOPIC_FREEHEAP, String(free_heap).c_str());
#if INFLUXDB_SUPPORT
idbSend(MQTT_TOPIC_FREEHEAP, String(free_heap).c_str());
#if (HEARTBEAT_REPORT_FREEHEAP)
idbSend(MQTT_TOPIC_FREEHEAP, String(free_heap).c_str());
#endif
#endif
#if (HEARTBEAT_REPORT_RELAY)
relayMQTT();
#endif
#if (LIGHT_PROVIDER != LIGHT_PROVIDER_NONE) & (HEARTBEAT_REPORT_LIGHT)
lightMQTT();
#endif
#if (HEARTBEAT_REPORT_VCC)
#if ADC_VCC_ENABLED
mqttSend(MQTT_TOPIC_VCC, String(ESP.getVcc()).c_str());
#endif
#endif
#if (HEARTBEAT_REPORT_STATUS)
mqttSend(MQTT_TOPIC_STATUS, MQTT_STATUS_ONLINE, true);
#endif
// Send info to websocket clients
// -------------------------------------------------------------------------
// WebSockets
// -------------------------------------------------------------------------
#if WEB_SUPPORT
#if NTP_SUPPORT
{


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

@ -295,9 +295,11 @@ void wifiSetup() {
#endif // DEBUG_SUPPORT
#if MQTT_SUPPORT
#if MDNS_SUPPORT
if (code == MESSAGE_CONNECTED) mdnsFindMQTT();
#endif // MDNS_SUPPORT
#endif // MDNS_SUPPORT
#endif // MQTT_SUPPORT
});


+ 17
- 7
code/espurna/ws.ino View File

@ -26,10 +26,12 @@ std::vector<ws_on_after_parse_callback_f> _ws_on_after_parse_callbacks;
// Private methods
// -----------------------------------------------------------------------------
#if MQTT_SUPPORT
void _wsMQTTCallback(unsigned int type, const char * topic, const char * payload) {
if (type == MQTT_CONNECT_EVENT) wsSend_P(PSTR("{\"mqttStatus\": true}"));
if (type == MQTT_DISCONNECT_EVENT) wsSend_P(PSTR("{\"mqttStatus\": false}"));
}
#endif
void _wsParse(AsyncWebSocketClient *client, uint8_t * payload, size_t length) {
@ -100,7 +102,9 @@ void _wsParse(AsyncWebSocketClient *client, uint8_t * payload, size_t length) {
bool save = false;
bool changed = false;
bool changedMQTT = false;
#if MQTT_SUPPORT
bool changedMQTT = false;
#endif
unsigned int network = 0;
unsigned int dczRelayIdx = 0;
@ -216,7 +220,9 @@ void _wsParse(AsyncWebSocketClient *client, uint8_t * payload, size_t length) {
if (value != getSetting(key)) {
setSetting(key, value);
save = changed = true;
if (key.startsWith("mqtt")) changedMQTT = true;
#if MQTT_SUPPORT
if (key.startsWith("mqtt")) changedMQTT = true;
#endif
}
}
@ -235,10 +241,12 @@ void _wsParse(AsyncWebSocketClient *client, uint8_t * payload, size_t length) {
// This should got to callback as well
// but first change management has to be in place
if (changedMQTT) {
mqttConfigure();
mqttDisconnect();
}
#if MQTT_SUPPORT
if (changedMQTT) {
mqttConfigure();
mqttDisconnect();
}
#endif
// Persist settings
saveSettings();
@ -406,7 +414,9 @@ void wsSetup() {
_ws.onEvent(_wsEvent);
wsConfigure();
webServer()->addHandler(&_ws);
mqttRegister(_wsMQTTCallback);
#if MQTT_SUPPORT
mqttRegister(_wsMQTTCallback);
#endif
wsOnAfterParseRegister(wsConfigure);
}


+ 5
- 5
code/html/index.html View File

@ -91,7 +91,7 @@
</li>
<li class="pure-menu-item">
<a href="#" class="pure-menu-link" data="panel-mqtt">MQTT</a>
<a href="#" class="pure-menu-link module module-mqtt" data="panel-mqtt">MQTT</a>
</li>
<li class="pure-menu-item module module-ntp">
@ -264,11 +264,11 @@
<div class="pure-u-1 pure-u-sm-1-4">Free space</div>
<div class="pure-u-1 pure-u-sm-17-24"><span class="right" name="free_size" post=" bytes"></span></div>
<div class="pure-u-1 pure-u-sm-1-4">MQTT Status</div>
<div class="pure-u-1 pure-u-sm-17-24"><span class="right" name="mqttStatus"></span></div>
<div class="pure-u-1 pure-u-sm-1-4 module module-mqtt">MQTT Status</div>
<div class="pure-u-1 pure-u-sm-17-24 module module-mqtt"><span class="right" name="mqttStatus"></span></div>
<div class="pure-u-1 pure-u-sm-1-4">NTP Status</div>
<div class="pure-u-1 pure-u-sm-17-24"><span class="right" name="ntpStatus"></span></div>
<div class="pure-u-1 pure-u-sm-1-4 module module-ntp">NTP Status</div>
<div class="pure-u-1 pure-u-sm-17-24 module module-ntp"><span class="right" name="ntpStatus"></span></div>
</div>


Loading…
Cancel
Save