Browse Source

Reset relays on MQTT disconnection

Improved version, where you can set the expected reaction on MQTT disconnection separate for every relay on the SWITCHES page of the web interface
rfm69
a-tom-s 6 years ago
parent
commit
3c853b25f2
7 changed files with 2555 additions and 2475 deletions
  1. +67
    -0
      code/.travis.yml
  2. +0
    -2
      code/espurna/config/general.h
  3. BIN
      code/espurna/data/index.html.gz
  4. +9
    -5
      code/espurna/relay.ino
  5. +2470
    -2467
      code/espurna/static/index.html.gz.h
  6. +1
    -1
      code/html/custom.js
  7. +8
    -0
      code/html/index.html

+ 67
- 0
code/.travis.yml View File

@ -0,0 +1,67 @@
# Continuous Integration (CI) is the practice, in software
# engineering, of merging all developer working copies with a shared mainline
# several times a day < http://docs.platformio.org/page/ci/index.html >
#
# Documentation:
#
# * Travis CI Embedded Builds with PlatformIO
# < https://docs.travis-ci.com/user/integration/platformio/ >
#
# * PlatformIO integration with Travis CI
# < http://docs.platformio.org/page/ci/travis.html >
#
# * User Guide for `platformio ci` command
# < http://docs.platformio.org/page/userguide/cmd_ci.html >
#
#
# Please choice one of the following templates (proposed below) and uncomment
# it (remove "# " before each line) or use own configuration according to the
# Travis CI documentation (see above).
#
#
# Template #1: General project. Test it using existing `platformio.ini`.
#
# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# install:
# - pip install -U platformio
# - platformio update
#
# script:
# - platformio run
#
# Template #2: The project is intended to by used as a library with examples
#
# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# env:
# - PLATFORMIO_CI_SRC=path/to/test/file.c
# - PLATFORMIO_CI_SRC=examples/file.ino
# - PLATFORMIO_CI_SRC=path/to/test/directory
#
# install:
# - pip install -U platformio
# - platformio update
#
# script:
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N

+ 0
- 2
code/espurna/config/general.h View File

@ -513,8 +513,6 @@ PROGMEM const char* const custom_reset_string[] = {
#define MQTT_USE_JSON_DELAY 100 // Wait this many ms before grouping messages
#define MQTT_QUEUE_MAX_SIZE 10 // Size of the MQTT queue when MQTT_USE_JSON is enabled
#define MQTT_DISCONNECT_RELAY_DEFAULT 1 // 0 - do nothing, 1 - reset relays to OFF in case of MQTT disconnection
// These are the properties that will be sent when useJson is true
#ifndef MQTT_ENQUEUE_IP
#define MQTT_ENQUEUE_IP 1


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


+ 9
- 5
code/espurna/relay.ino View File

@ -441,6 +441,7 @@ void _relayWebSocketOnStart(JsonObject& root) {
#if MQTT_SUPPORT
line["group"] = getSetting("mqttGroup", i, "");
line["group_inv"] = getSetting("mqttGroupInv", i, 0).toInt();
line["disc_react"] = getSetting("mqttDisconnectReaction",i,0).toInt();
#endif
}
@ -566,7 +567,6 @@ void relayMQTT(unsigned char id) {
mqttSendRaw(t.c_str(), status ? "1" : "0");
}
}
}
void relayMQTT() {
@ -654,13 +654,17 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo
}
if (type == MQTT_DISCONNECT_EVENT)
{
if (MQTT_DISCONNECT_RELAY_DEFAULT == 1){
for (unsigned int i=0; i < _relays.size(); i++){
if (type == MQTT_DISCONNECT_EVENT) {
for (unsigned int i=0; i < _relays.size(); i++){
int reaction = getSetting("mqttDisconnectReaction",i,0).toInt();
if (reaction == 1) { // switch relay OFF
DEBUG_MSG_P(PSTR("[RELAY] Reset relay (%d) due to MQTT disconnection\n"), i);
relayStatusWrap(i, false, false);
}
else if(reaction == 2) { // switch relay ON
DEBUG_MSG_P(PSTR("[RELAY] Set relay (%d) due to MQTT disconnection\n"), i);
relayStatusWrap(i, true, false);
}
}
}


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


+ 1
- 1
code/html/custom.js View File

@ -152,7 +152,7 @@ var is_group = [
"ssid", "pass", "gw", "mask", "ip", "dns",
"schEnabled", "schSwitch","schAction","schHour","schMinute","schWDs",
"relayBoot", "relayPulse", "relayTime",
"mqttGroup", "mqttGroupInv",
"mqttGroup", "mqttGroupInv", "mqttDisconnectReaction",
"dczRelayIdx", "dczMagnitude",
"tspkRelay", "tspkMagnitude",
"ledMode",


+ 8
- 0
code/html/index.html View File

@ -1162,6 +1162,14 @@
<option value="1">Inverse</option>
</select>
</div>
<div class="pure-g module module-mqtt">
<div class="pure-u-1 pure-u-lg-1-4"><label>MQTT disconnect reaction</label></div>
<select class="pure-u-1 pure-u-lg-3-4" name="mqttDisconnectReaction">
<option value="0">keep current relay state</option>
<option value="1">relay OFF</option>
<option value="2">relay ON</option>
</select>
</div>
</div>
<div id="dczRelayTemplate" class="template">


Loading…
Cancel
Save