Browse Source

Fix mqtt group sync with different switches sharing same group

fastled
Xose Pérez 7 years ago
parent
commit
1a68f89bbf
10 changed files with 2873 additions and 2649 deletions
  1. +24
    -0
      code/espurna/button.ino
  2. +1
    -0
      code/espurna/config/all.h
  3. +337
    -0
      code/espurna/config/defaults.h
  4. +6
    -0
      code/espurna/config/general.h
  5. +4
    -171
      code/espurna/config/hardware.h
  6. BIN
      code/espurna/data/index.html.gz
  7. +12
    -0
      code/espurna/led.ino
  8. +40
    -29
      code/espurna/relay.ino
  9. +2447
    -2447
      code/espurna/static/index.html.gz.h
  10. +2
    -2
      code/html/custom.js

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

@ -155,6 +155,30 @@ void buttonSetup() {
_buttons.push_back({new DebounceEvent(BUTTON4_PIN, BUTTON4_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON4_RELAY});
}
#endif
#ifdef BUTTON5_PIN
{
unsigned int actions = buttonStore(BUTTON5_PRESS, BUTTON5_CLICK, BUTTON5_DBLCLICK, BUTTON5_LNGCLICK, BUTTON5_LNGLNGCLICK);
_buttons.push_back({new DebounceEvent(BUTTON5_PIN, BUTTON5_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON5_RELAY});
}
#endif
#ifdef BUTTON6_PIN
{
unsigned int actions = buttonStore(BUTTON6_PRESS, BUTTON6_CLICK, BUTTON6_DBLCLICK, BUTTON6_LNGCLICK, BUTTON6_LNGLNGCLICK);
_buttons.push_back({new DebounceEvent(BUTTON6_PIN, BUTTON6_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON6_RELAY});
}
#endif
#ifdef BUTTON7_PIN
{
unsigned int actions = buttonStore(BUTTON7_PRESS, BUTTON7_CLICK, BUTTON7_DBLCLICK, BUTTON7_LNGCLICK, BUTTON7_LNGLNGCLICK);
_buttons.push_back({new DebounceEvent(BUTTON7_PIN, BUTTON7_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON7_RELAY});
}
#endif
#ifdef BUTTON8_PIN
{
unsigned int actions = buttonStore(BUTTON8_PRESS, BUTTON8_CLICK, BUTTON8_DBLCLICK, BUTTON8_LNGCLICK, BUTTON8_LNGLNGCLICK);
_buttons.push_back({new DebounceEvent(BUTTON8_PIN, BUTTON8_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON8_RELAY});
}
#endif
#endif


+ 1
- 0
code/espurna/config/all.h View File

@ -1,6 +1,7 @@
#include "version.h"
#include "arduino.h"
#include "hardware.h"
#include "defaults.h"
#include "prototypes.h"
#include "general.h"
#include "sensors.h"


+ 337
- 0
code/espurna/config/defaults.h View File

@ -0,0 +1,337 @@
// -----------------------------------------------------------------------------
// Hardware default values
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Buttons
// -----------------------------------------------------------------------------
#ifndef BUTTON1_PRESS
#define BUTTON1_PRESS BUTTON_MODE_NONE
#endif
#ifndef BUTTON2_PRESS
#define BUTTON2_PRESS BUTTON_MODE_NONE
#endif
#ifndef BUTTON3_PRESS
#define BUTTON3_PRESS BUTTON_MODE_NONE
#endif
#ifndef BUTTON4_PRESS
#define BUTTON4_PRESS BUTTON_MODE_NONE
#endif
#ifndef BUTTON5_PRESS
#define BUTTON5_PRESS BUTTON_MODE_NONE
#endif
#ifndef BUTTON6_PRESS
#define BUTTON6_PRESS BUTTON_MODE_NONE
#endif
#ifndef BUTTON7_PRESS
#define BUTTON7_PRESS BUTTON_MODE_NONE
#endif
#ifndef BUTTON8_PRESS
#define BUTTON8_PRESS BUTTON_MODE_NONE
#endif
#ifndef BUTTON1_CLICK
#define BUTTON1_CLICK BUTTON_MODE_TOGGLE
#endif
#ifndef BUTTON2_CLICK
#define BUTTON2_CLICK BUTTON_MODE_TOGGLE
#endif
#ifndef BUTTON3_CLICK
#define BUTTON3_CLICK BUTTON_MODE_TOGGLE
#endif
#ifndef BUTTON4_CLICK
#define BUTTON4_CLICK BUTTON_MODE_TOGGLE
#endif
#ifndef BUTTON5_CLICK
#define BUTTON5_CLICK BUTTON_MODE_TOGGLE
#endif
#ifndef BUTTON6_CLICK
#define BUTTON6_CLICK BUTTON_MODE_TOGGLE
#endif
#ifndef BUTTON7_CLICK
#define BUTTON7_CLICK BUTTON_MODE_TOGGLE
#endif
#ifndef BUTTON8_CLICK
#define BUTTON8_CLICK BUTTON_MODE_TOGGLE
#endif
#ifndef BUTTON1_DBLCLICK
#define BUTTON1_DBLCLICK BUTTON_MODE_AP
#endif
#ifndef BUTTON2_DBLCLICK
#define BUTTON2_DBLCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON3_DBLCLICK
#define BUTTON3_DBLCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON4_DBLCLICK
#define BUTTON4_DBLCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON5_DBLCLICK
#define BUTTON5_DBLCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON6_DBLCLICK
#define BUTTON6_DBLCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON7_DBLCLICK
#define BUTTON7_DBLCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON8_DBLCLICK
#define BUTTON8_DBLCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON1_LNGCLICK
#define BUTTON1_LNGCLICK BUTTON_MODE_RESET
#endif
#ifndef BUTTON2_LNGCLICK
#define BUTTON2_LNGCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON3_LNGCLICK
#define BUTTON3_LNGCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON4_LNGCLICK
#define BUTTON4_LNGCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON5_LNGCLICK
#define BUTTON5_LNGCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON6_LNGCLICK
#define BUTTON6_LNGCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON7_LNGCLICK
#define BUTTON7_LNGCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON8_LNGCLICK
#define BUTTON8_LNGCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON1_LNGLNGCLICK
#define BUTTON1_LNGLNGCLICK BUTTON_MODE_FACTORY
#endif
#ifndef BUTTON2_LNGLNGCLICK
#define BUTTON2_LNGLNGCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON3_LNGLNGCLICK
#define BUTTON3_LNGLNGCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON4_LNGLNGCLICK
#define BUTTON4_LNGLNGCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON5_LNGLNGCLICK
#define BUTTON5_LNGLNGCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON6_LNGLNGCLICK
#define BUTTON6_LNGLNGCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON7_LNGLNGCLICK
#define BUTTON7_LNGLNGCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON8_LNGLNGCLICK
#define BUTTON8_LNGLNGCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON1_RELAY
#define BUTTON1_RELAY 0
#endif
#ifndef BUTTON2_RELAY
#define BUTTON2_RELAY 0
#endif
#ifndef BUTTON3_RELAY
#define BUTTON3_RELAY 0
#endif
#ifndef BUTTON4_RELAY
#define BUTTON4_RELAY 0
#endif
#ifndef BUTTON5_RELAY
#define BUTTON5_RELAY 0
#endif
#ifndef BUTTON6_RELAY
#define BUTTON6_RELAY 0
#endif
#ifndef BUTTON7_RELAY
#define BUTTON7_RELAY 0
#endif
#ifndef BUTTON8_RELAY
#define BUTTON8_RELAY 0
#endif
// -----------------------------------------------------------------------------
// Relays
// -----------------------------------------------------------------------------
#ifndef RELAY1_TYPE
#define RELAY1_TYPE RELAY_TYPE_NORMAL
#endif
#ifndef RELAY2_TYPE
#define RELAY2_TYPE RELAY_TYPE_NORMAL
#endif
#ifndef RELAY3_TYPE
#define RELAY3_TYPE RELAY_TYPE_NORMAL
#endif
#ifndef RELAY4_TYPE
#define RELAY4_TYPE RELAY_TYPE_NORMAL
#endif
#ifndef RELAY5_TYPE
#define RELAY5_TYPE RELAY_TYPE_NORMAL
#endif
#ifndef RELAY6_TYPE
#define RELAY6_TYPE RELAY_TYPE_NORMAL
#endif
#ifndef RELAY7_TYPE
#define RELAY7_TYPE RELAY_TYPE_NORMAL
#endif
#ifndef RELAY8_TYPE
#define RELAY8_TYPE RELAY_TYPE_NORMAL
#endif
#ifndef RELAY1_RESET_PIN
#define RELAY1_RESET_PIN 0
#endif
#ifndef RELAY2_RESET_PIN
#define RELAY2_RESET_PIN 0
#endif
#ifndef RELAY3_RESET_PIN
#define RELAY3_RESET_PIN 0
#endif
#ifndef RELAY4_RESET_PIN
#define RELAY4_RESET_PIN 0
#endif
#ifndef RELAY5_RESET_PIN
#define RELAY5_RESET_PIN 0
#endif
#ifndef RELAY6_RESET_PIN
#define RELAY6_RESET_PIN 0
#endif
#ifndef RELAY7_RESET_PIN
#define RELAY7_RESET_PIN 0
#endif
#ifndef RELAY8_RESET_PIN
#define RELAY8_RESET_PIN 0
#endif
#ifndef RELAY1_DELAY_ON
#define RELAY1_DELAY_ON 0
#endif
#ifndef RELAY2_DELAY_ON
#define RELAY2_DELAY_ON 0
#endif
#ifndef RELAY3_DELAY_ON
#define RELAY3_DELAY_ON 0
#endif
#ifndef RELAY4_DELAY_ON
#define RELAY4_DELAY_ON 0
#endif
#ifndef RELAY5_DELAY_ON
#define RELAY5_DELAY_ON 0
#endif
#ifndef RELAY6_DELAY_ON
#define RELAY6_DELAY_ON 0
#endif
#ifndef RELAY7_DELAY_ON
#define RELAY7_DELAY_ON 0
#endif
#ifndef RELAY8_DELAY_ON
#define RELAY8_DELAY_ON 0
#endif
#ifndef RELAY1_DELAY_OFF
#define RELAY1_DELAY_OFF 0
#endif
#ifndef RELAY2_DELAY_OFF
#define RELAY2_DELAY_OFF 0
#endif
#ifndef RELAY3_DELAY_OFF
#define RELAY3_DELAY_OFF 0
#endif
#ifndef RELAY4_DELAY_OFF
#define RELAY4_DELAY_OFF 0
#endif
#ifndef RELAY5_DELAY_OFF
#define RELAY5_DELAY_OFF 0
#endif
#ifndef RELAY6_DELAY_OFF
#define RELAY6_DELAY_OFF 0
#endif
#ifndef RELAY7_DELAY_OFF
#define RELAY7_DELAY_OFF 0
#endif
#ifndef RELAY8_DELAY_OFF
#define RELAY8_DELAY_OFF 0
#endif
// -----------------------------------------------------------------------------
// LEDs
// -----------------------------------------------------------------------------
#ifndef LED1_MODE
#define LED1_MODE LED_MODE_WIFI
#endif
#ifndef LED2_MODE
#define LED2_MODE LED_MODE_MQTT
#endif
#ifndef LED3_MODE
#define LED3_MODE LED_MODE_MQTT
#endif
#ifndef LED4_MODE
#define LED4_MODE LED_MODE_MQTT
#endif
#ifndef LED5_MODE
#define LED5_MODE LED_MODE_MQTT
#endif
#ifndef LED6_MODE
#define LED6_MODE LED_MODE_MQTT
#endif
#ifndef LED7_MODE
#define LED7_MODE LED_MODE_MQTT
#endif
#ifndef LED8_MODE
#define LED8_MODE LED_MODE_MQTT
#endif
#ifndef LED1_RELAY
#define LED1_RELAY 1
#endif
#ifndef LED2_RELAY
#define LED2_RELAY 2
#endif
#ifndef LED3_RELAY
#define LED3_RELAY 3
#endif
#ifndef LED4_RELAY
#define LED4_RELAY 4
#endif
#ifndef LED5_RELAY
#define LED5_RELAY 5
#endif
#ifndef LED6_RELAY
#define LED6_RELAY 6
#endif
#ifndef LED7_RELAY
#define LED7_RELAY 7
#endif
#ifndef LED8_RELAY
#define LED8_RELAY 8
#endif
// -----------------------------------------------------------------------------
// General
// -----------------------------------------------------------------------------
// Needed for ESP8285 boards under Windows using PlatformIO (?)
#ifndef BUTTON_PUSHBUTTON
#define BUTTON_PUSHBUTTON 0
#define BUTTON_SWITCH 1
#define BUTTON_DEFAULT_HIGH 2
#define BUTTON_SET_PULLUP 4
#endif
// Relay providers
#ifndef RELAY_PROVIDER
#define RELAY_PROVIDER RELAY_PROVIDER_RELAY
#endif
// Light provider
#ifndef LIGHT_PROVIDER
#define LIGHT_PROVIDER LIGHT_PROVIDER_NONE
#endif

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

@ -38,10 +38,16 @@
#ifndef DEBUG_SERIAL_SUPPORT
#define DEBUG_SERIAL_SUPPORT 1 // Enable serial debug log
#endif
#ifndef DEBUG_PORT
#define DEBUG_PORT Serial // Default debugging port
#endif
#ifndef SERIAL_BAUDRATE
#define SERIAL_BAUDRATE 115200 // Default baudrate
#endif
//------------------------------------------------------------------------------
// UDP debug log


+ 4
- 171
code/espurna/config/hardware.h View File

@ -517,9 +517,12 @@
#define DEVICE "SONOFF_RFBRIDGE"
#define SERIAL_BAUDRATE 19200
#define RELAY_PROVIDER RELAY_PROVIDER_RFBRIDGE
#ifndef DUMMY_RELAY_COUNT
#define DUMMY_RELAY_COUNT 6
#define DUMMY_RELAY_COUNT 8
#endif
// Remove UART noise on serial line
#define TERMINAL_SUPPORT 0
#define DEBUG_SERIAL_SUPPORT 0
@ -1208,173 +1211,3 @@
#else
#error "UNSUPPORTED HARDWARE!"
#endif
// -----------------------------------------------------------------------------
// Default values
// -----------------------------------------------------------------------------
#ifndef BUTTON1_PRESS
#define BUTTON1_PRESS BUTTON_MODE_NONE
#endif
#ifndef BUTTON2_PRESS
#define BUTTON2_PRESS BUTTON_MODE_NONE
#endif
#ifndef BUTTON3_PRESS
#define BUTTON3_PRESS BUTTON_MODE_NONE
#endif
#ifndef BUTTON4_PRESS
#define BUTTON4_PRESS BUTTON_MODE_NONE
#endif
#ifndef BUTTON1_CLICK
#define BUTTON1_CLICK BUTTON_MODE_TOGGLE
#endif
#ifndef BUTTON2_CLICK
#define BUTTON2_CLICK BUTTON_MODE_TOGGLE
#endif
#ifndef BUTTON3_CLICK
#define BUTTON3_CLICK BUTTON_MODE_TOGGLE
#endif
#ifndef BUTTON4_CLICK
#define BUTTON4_CLICK BUTTON_MODE_TOGGLE
#endif
#ifndef BUTTON1_DBLCLICK
#define BUTTON1_DBLCLICK BUTTON_MODE_AP
#endif
#ifndef BUTTON2_DBLCLICK
#define BUTTON2_DBLCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON3_DBLCLICK
#define BUTTON3_DBLCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON4_DBLCLICK
#define BUTTON4_DBLCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON1_LNGCLICK
#define BUTTON1_LNGCLICK BUTTON_MODE_RESET
#endif
#ifndef BUTTON2_LNGCLICK
#define BUTTON2_LNGCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON3_LNGCLICK
#define BUTTON3_LNGCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON4_LNGCLICK
#define BUTTON4_LNGCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON1_LNGLNGCLICK
#define BUTTON1_LNGLNGCLICK BUTTON_MODE_FACTORY
#endif
#ifndef BUTTON2_LNGLNGCLICK
#define BUTTON2_LNGLNGCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON3_LNGLNGCLICK
#define BUTTON3_LNGLNGCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON4_LNGLNGCLICK
#define BUTTON4_LNGLNGCLICK BUTTON_MODE_NONE
#endif
#ifndef BUTTON1_RELAY
#define BUTTON1_RELAY 0
#endif
#ifndef BUTTON2_RELAY
#define BUTTON2_RELAY 0
#endif
#ifndef BUTTON3_RELAY
#define BUTTON3_RELAY 0
#endif
#ifndef BUTTON4_RELAY
#define BUTTON4_RELAY 0
#endif
#ifndef RELAY1_RESET_PIN
#define RELAY1_RESET_PIN 0
#endif
#ifndef RELAY2_RESET_PIN
#define RELAY2_RESET_PIN 0
#endif
#ifndef RELAY3_RESET_PIN
#define RELAY3_RESET_PIN 0
#endif
#ifndef RELAY4_RESET_PIN
#define RELAY4_RESET_PIN 0
#endif
#ifndef RELAY1_DELAY_ON
#define RELAY1_DELAY_ON 0
#endif
#ifndef RELAY2_DELAY_ON
#define RELAY2_DELAY_ON 0
#endif
#ifndef RELAY3_DELAY_ON
#define RELAY3_DELAY_ON 0
#endif
#ifndef RELAY4_DELAY_ON
#define RELAY4_DELAY_ON 0
#endif
#ifndef RELAY1_DELAY_OFF
#define RELAY1_DELAY_OFF 0
#endif
#ifndef RELAY2_DELAY_OFF
#define RELAY2_DELAY_OFF 0
#endif
#ifndef RELAY3_DELAY_OFF
#define RELAY3_DELAY_OFF 0
#endif
#ifndef RELAY4_DELAY_OFF
#define RELAY4_DELAY_OFF 0
#endif
#ifndef LED1_MODE
#define LED1_MODE LED_MODE_WIFI
#endif
#ifndef LED2_MODE
#define LED2_MODE LED_MODE_MQTT
#endif
#ifndef LED3_MODE
#define LED3_MODE LED_MODE_MQTT
#endif
#ifndef LED4_MODE
#define LED4_MODE LED_MODE_MQTT
#endif
#ifndef LED1_RELAY
#define LED1_RELAY 1
#endif
#ifndef LED2_RELAY
#define LED2_RELAY 2
#endif
#ifndef LED3_RELAY
#define LED3_RELAY 3
#endif
#ifndef LED4_RELAY
#define LED4_RELAY 4
#endif
// Needed for ESP8285 boards under Windows using PlatformIO (?)
#ifndef BUTTON_PUSHBUTTON
#define BUTTON_PUSHBUTTON 0
#define BUTTON_SWITCH 1
#define BUTTON_DEFAULT_HIGH 2
#define BUTTON_SET_PULLUP 4
#endif
// Serial baudrate
#ifndef SERIAL_BAUDRATE
#define SERIAL_BAUDRATE 115200
#endif
// Relay providers
#ifndef RELAY_PROVIDER
#define RELAY_PROVIDER RELAY_PROVIDER_RELAY
#endif
// Light provider
#ifndef LIGHT_PROVIDER
#define LIGHT_PROVIDER LIGHT_PROVIDER_NONE
#endif

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


+ 12
- 0
code/espurna/led.ino View File

@ -133,6 +133,18 @@ void ledSetup() {
#ifdef LED4_PIN
_leds.push_back((led_t) { LED4_PIN, LED4_PIN_INVERSE, LED4_MODE, LED4_RELAY });
#endif
#ifdef LED5_PIN
_leds.push_back((led_t) { LED5_PIN, LED5_PIN_INVERSE, LED5_MODE, LED5_RELAY });
#endif
#ifdef LED6_PIN
_leds.push_back((led_t) { LED6_PIN, LED6_PIN_INVERSE, LED6_MODE, LED6_RELAY });
#endif
#ifdef LED7_PIN
_leds.push_back((led_t) { LED7_PIN, LED7_PIN_INVERSE, LED7_MODE, LED7_RELAY });
#endif
#ifdef LED8_PIN
_leds.push_back((led_t) { LED8_PIN, LED8_PIN_INVERSE, LED8_MODE, LED8_RELAY });
#endif
for (unsigned int i=0; i < _leds.size(); i++) {
pinMode(_leds[i].pin, OUTPUT);


+ 40
- 29
code/espurna/relay.ino View File

@ -400,7 +400,7 @@ void _relayWebSocketOnStart(JsonObject& root) {
line["pulse_ms"] = _relays[i].pulse_ms / 1000.0;
#if MQTT_SUPPORT
line["group"] = getSetting("mqttGroup", i, "");
line["group_inv"] = getSetting("mqttGroupInv", i, 0).toInt() == 1;
line["group_inv"] = getSetting("mqttGroupInv", i, 0).toInt();
#endif
}
@ -547,6 +547,17 @@ void relayMQTT() {
}
}
void relayStatusWrap(unsigned char id, unsigned char value, bool is_group_topic) {
// Action to perform
if (value == 0) {
relayStatus(id, false, mqttForward(), !is_group_topic);
} else if (value == 1) {
relayStatus(id, true, mqttForward(), !is_group_topic);
} else if (value == 2) {
relayToggle(id, true, true);
}
}
void relayMQTTCallback(unsigned int type, const char * topic, const char * payload) {
if (type == MQTT_CONNECT_EVENT) {
@ -571,10 +582,6 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo
if (type == MQTT_MESSAGE_EVENT) {
// Get relay
unsigned int relayID;
bool is_group_topic = false;
// Get value
unsigned char value = relayParsePayload(payload);
if (value == 0xFF) {
@ -583,43 +590,35 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo
}
// Check group topics
bool found = false;
for (unsigned int i=0; i < _relays.size(); i++) {
String t = getSetting("mqttGroup", i, "");
if (t.equals(topic)) {
unsigned char local_value = value;
if (getSetting("mqttGroupInv", i, 0).toInt() == 1) {
if (value < 2) value = 1 - value;
if (local_value < 2) local_value = 1 - local_value;
}
found = true;
DEBUG_MSG_P(PSTR("[RELAY] Matched group topic for relayID %d\n"), i);
is_group_topic = true;
relayID = i;
break;
relayStatusWrap(i, local_value, true);
}
}
// Not group topic, look for own topic
if (!is_group_topic) {
// Match topic
String t = mqttSubtopic((char *) topic);
if (!t.startsWith(MQTT_TOPIC_RELAY)) return;
// If found as group topic quit
if (found) return;
// Get relay ID
relayID = t.substring(strlen(MQTT_TOPIC_RELAY)+1).toInt();
if (relayID >= relayCount()) {
DEBUG_MSG_P(PSTR("[RELAY] Wrong relayID (%d)\n"), relayID);
return;
}
// Else, try to match topic
String t = mqttSubtopic((char *) topic);
if (!t.startsWith(MQTT_TOPIC_RELAY)) return;
// Get relay ID
unsigned int id = t.substring(strlen(MQTT_TOPIC_RELAY)+1).toInt();
if (id >= relayCount()) {
DEBUG_MSG_P(PSTR("[RELAY] Wrong relayID (%d)\n"), id);
return;
}
// Action to perform
if (value == 0) {
relayStatus(relayID, false, mqttForward(), !is_group_topic);
} else if (value == 1) {
relayStatus(relayID, true, mqttForward(), !is_group_topic);
} else if (value == 2) {
relayToggle(relayID, true, true);
}
relayStatusWrap(id, value, false);
}
@ -670,6 +669,18 @@ void relaySetup() {
#ifdef RELAY4_PIN
_relays.push_back((relay_t) { RELAY4_PIN, RELAY4_TYPE, RELAY4_RESET_PIN, RELAY4_DELAY_ON, RELAY4_DELAY_OFF });
#endif
#ifdef RELAY5_PIN
_relays.push_back((relay_t) { RELAY5_PIN, RELAY5_TYPE, RELAY5_RESET_PIN, RELAY5_DELAY_ON, RELAY5_DELAY_OFF });
#endif
#ifdef RELAY6_PIN
_relays.push_back((relay_t) { RELAY6_PIN, RELAY6_TYPE, RELAY6_RESET_PIN, RELAY6_DELAY_ON, RELAY6_DELAY_OFF });
#endif
#ifdef RELAY7_PIN
_relays.push_back((relay_t) { RELAY7_PIN, RELAY7_TYPE, RELAY7_RESET_PIN, RELAY7_DELAY_ON, RELAY7_DELAY_OFF });
#endif
#ifdef RELAY8_PIN
_relays.push_back((relay_t) { RELAY8_PIN, RELAY8_TYPE, RELAY8_RESET_PIN, RELAY8_DELAY_ON, RELAY8_DELAY_OFF });
#endif
#endif


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


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

@ -504,8 +504,8 @@ function initRelayConfig(data) {
$("select[name='relayBoot']", line).val(data[i].boot);
$("select[name='relayPulse']", line).val(data[i].pulse);
$("input[name='relayTime']", line).val(data[i].pulse_ms);
$("intut[name='mqttGroup']", line).val(data[i].group || 0);
$("select[name='mqttGroupInv']", line).val(data[i].group_inv || 0);
$("input[name='mqttGroup']", line).val(data[i].group);
$("select[name='mqttGroupInv']", line).val(data[i].group_inv);
line.appendTo("#relayConfig");
}


Loading…
Cancel
Save