Browse Source

Relay MQTT group sync mode setting

rules-rpn
Max Prokhorov 5 years ago
parent
commit
a53b66d55a
4 changed files with 23 additions and 11 deletions
  1. +4
    -0
      code/espurna/config/types.h
  2. +15
    -8
      code/espurna/relay.ino
  3. +2
    -2
      code/html/custom.js
  4. +2
    -1
      code/html/index.html

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

@ -96,6 +96,10 @@
#define RELAY_PROVIDER_RFBRIDGE 3 #define RELAY_PROVIDER_RFBRIDGE 3
#define RELAY_PROVIDER_STM 4 #define RELAY_PROVIDER_STM 4
#define RELAY_GROUP_SYNC_NORMAL 0
#define RELAY_GROUP_SYNC_INVERSE 1
#define RELAY_GROUP_SYNC_RECEIVEONLY 2
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// UDP SYSLOG // UDP SYSLOG
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------


+ 15
- 8
code/espurna/relay.ino View File

@ -630,7 +630,7 @@ void _relayWebSocketSendRelay(unsigned char i) {
line["pulse_ms"] = _relays[i].pulse_ms / 1000.0; line["pulse_ms"] = _relays[i].pulse_ms / 1000.0;
#if MQTT_SUPPORT #if MQTT_SUPPORT
line["group"] = getSetting("mqttGroup", i, ""); line["group"] = getSetting("mqttGroup", i, "");
line["group_inv"] = getSetting("mqttGroupInv", i, 0).toInt();
line["group_sync"] = getSetting("mqttGroupSync", i, RELAY_GROUP_SYNC_NORMAL).toInt();
line["on_disc"] = getSetting("relayOnDisc", i, 0).toInt(); line["on_disc"] = getSetting("relayOnDisc", i, 0).toInt();
#endif #endif
@ -794,6 +794,18 @@ void relaySetupAPI() {
#if MQTT_SUPPORT #if MQTT_SUPPORT
void _relayMQTTGroup(unsigned char id) {
String topic = getSetting("mqttGroup", id, "");
if (!topic.length()) return;
unsigned char mode = getSetting("mqttGroupSync", id, RELAY_GROUP_SYNC_NORMAL).toInt();
if (mode == RELAY_GROUP_SYNC_RECEIVEONLY) return;
bool status = relayStatus(id);
if (mode == RELAY_GROUP_SYNC_INVERSE) status = !status;
mqttSendRaw(topic.c_str(), status ? RELAY_MQTT_ON : RELAY_MQTT_OFF);
}
void relayMQTT(unsigned char id) { void relayMQTT(unsigned char id) {
if (id >= _relays.size()) return; if (id >= _relays.size()) return;
@ -807,12 +819,7 @@ void relayMQTT(unsigned char id) {
// Check group topic // Check group topic
if (_relays[id].group_report) { if (_relays[id].group_report) {
_relays[id].group_report = false; _relays[id].group_report = false;
String t = getSetting("mqttGroup", id, "");
if (t.length() > 0) {
bool status = relayStatus(id);
if (getSetting("mqttGroupInv", id, 0).toInt() == 1) status = !status;
mqttSendRaw(t.c_str(), status ? RELAY_MQTT_ON : RELAY_MQTT_OFF);
}
_relayMQTTGroup(id);
} }
// Send speed for IFAN02 // Send speed for IFAN02
@ -939,7 +946,7 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo
if (value == 0xFF) return; if (value == 0xFF) return;
if (value < 2) { if (value < 2) {
if (getSetting("mqttGroupInv", i, 0).toInt() == 1) {
if (getSetting("mqttGroupSync", i, RELAY_GROUP_SYNC_NORMAL).toInt() == RELAY_GROUP_SYNC_INVERSE) {
value = 1 - value; value = 1 - value;
} }
} }


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

@ -246,7 +246,7 @@ function addValue(data, name, value) {
"ssid", "pass", "gw", "mask", "ip", "dns", "ssid", "pass", "gw", "mask", "ip", "dns",
"schEnabled", "schSwitch","schAction","schType","schHour","schMinute","schWDs","schUTC", "schEnabled", "schSwitch","schAction","schType","schHour","schMinute","schWDs","schUTC",
"relayBoot", "relayPulse", "relayTime", "relayBoot", "relayPulse", "relayTime",
"mqttGroup", "mqttGroupInv", "relayOnDisc",
"mqttGroup", "mqttGroupSync", "relayOnDisc",
"dczRelayIdx", "dczMagnitude", "dczRelayIdx", "dczMagnitude",
"tspkRelay", "tspkMagnitude", "tspkRelay", "tspkMagnitude",
"ledMode", "ledMode",
@ -951,7 +951,7 @@ function initRelayConfig(data) {
$("select[name='relayPulse']", line).val(relay.pulse); $("select[name='relayPulse']", line).val(relay.pulse);
$("input[name='relayTime']", line).val(relay.pulse_ms); $("input[name='relayTime']", line).val(relay.pulse_ms);
$("input[name='mqttGroup']", line).val(relay.group); $("input[name='mqttGroup']", line).val(relay.group);
$("select[name='mqttGroupInv']", line).val(relay.group_inv);
$("select[name='mqttGroupSync']", line).val(relay.group_sync);
$("select[name='relayOnDisc']", line).val(relay.on_disc); $("select[name='relayOnDisc']", line).val(relay.on_disc);
line.appendTo("#relayConfig"); line.appendTo("#relayConfig");


+ 2
- 1
code/html/index.html View File

@ -1631,9 +1631,10 @@
</div> </div>
<div class="pure-g module module-mqtt"> <div class="pure-g module module-mqtt">
<div class="pure-u-1 pure-u-lg-1-4"><label>MQTT group sync</label></div> <div class="pure-u-1 pure-u-lg-1-4"><label>MQTT group sync</label></div>
<select class="pure-u-1 pure-u-lg-3-4" name="mqttGroupInv">
<select class="pure-u-1 pure-u-lg-3-4" name="mqttGroupSync">
<option value="0">Same</option> <option value="0">Same</option>
<option value="1">Inverse</option> <option value="1">Inverse</option>
<option value="2">Receive Only</option>
</select> </select>
</div> </div>
<div class="pure-g module module-mqtt"> <div class="pure-g module module-mqtt">


Loading…
Cancel
Save