SetOption158 publish/suppress ModbusReceived MQTT messages (#20678)

This commit is contained in:
Fulvio Spelta 2024-02-07 15:57:09 +01:00 committed by GitHub
parent b31ff75f3c
commit ab8676d865
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 21 additions and 4 deletions

View File

@ -314,6 +314,9 @@ String EthernetMacAddress(void);
#ifndef MQTT_LWT_ONLINE #ifndef MQTT_LWT_ONLINE
#define MQTT_LWT_ONLINE "Online" // MQTT LWT online topic message #define MQTT_LWT_ONLINE "Online" // MQTT LWT online topic message
#endif #endif
#ifndef MQTT_DISABLE_MODBUSRECEIVED
#define MQTT_DISABLE_MODBUSRECEIVED 0 // 1 = Disable ModbusReceived mqtt messages, 0 = Enable ModbusReceived mqtt messages (default)
#endif
#ifndef MESSZ #ifndef MESSZ
#define MESSZ 1040 // Max number of characters in JSON message string (Hass discovery and nice MQTT_MAX_PACKET_SIZE = 1200) #define MESSZ 1040 // Max number of characters in JSON message string (Hass discovery and nice MQTT_MAX_PACKET_SIZE = 1200)

View File

@ -191,7 +191,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
uint32_t zcfallingedge : 1; // bit 9 (v13.0.0.1) - SetOption155 - (ZCDimmer) Enable rare falling Edge dimmer instead of leading edge uint32_t zcfallingedge : 1; // bit 9 (v13.0.0.1) - SetOption155 - (ZCDimmer) Enable rare falling Edge dimmer instead of leading edge
uint32_t sen5x_passive_mode : 1; // bit 10 (v13.1.0.1) - SetOption156 - (Sen5x) Run in passive mode when there is another I2C master (e.g. Ikea Vindstyrka), i.e. do not set up Sen5x sensor, higher polling interval uint32_t sen5x_passive_mode : 1; // bit 10 (v13.1.0.1) - SetOption156 - (Sen5x) Run in passive mode when there is another I2C master (e.g. Ikea Vindstyrka), i.e. do not set up Sen5x sensor, higher polling interval
uint32_t neopool_outputsensitive : 1; // bit 11 (v13.2.0.1) - SetOption157 - (NeoPool) Output sensitive data (1) uint32_t neopool_outputsensitive : 1; // bit 11 (v13.2.0.1) - SetOption157 - (NeoPool) Output sensitive data (1)
uint32_t spare12 : 1; // bit 12 uint32_t mqtt_disable_modbus : 1; // bit 12 (v13.2.0.1) - SetOption158 - (MQTT) Disable publish ModbusReceived MQTT messages, you must use event trigger rules instead.
uint32_t spare13 : 1; // bit 13 uint32_t spare13 : 1; // bit 13
uint32_t spare14 : 1; // bit 14 uint32_t spare14 : 1; // bit 14
uint32_t spare15 : 1; // bit 15 uint32_t spare15 : 1; // bit 15

View File

@ -418,6 +418,7 @@
#define MQTT_TELE_RETAIN 0 // Tele messages may send retain flag (0 = off, 1 = on) #define MQTT_TELE_RETAIN 0 // Tele messages may send retain flag (0 = off, 1 = on)
#define MQTT_CLEAN_SESSION 1 // Mqtt clean session connection (0 = No clean session, 1 = Clean session (default)) #define MQTT_CLEAN_SESSION 1 // Mqtt clean session connection (0 = No clean session, 1 = Clean session (default))
#define MQTT_DISABLE_SSERIALRECEIVED 0 // 1 = Disable sserialreceived mqtt messages, 0 = Enable sserialreceived mqtt messages (default) #define MQTT_DISABLE_SSERIALRECEIVED 0 // 1 = Disable sserialreceived mqtt messages, 0 = Enable sserialreceived mqtt messages (default)
#define MQTT_DISABLE_MODBUSRECEIVED 0 // 1 = Disable ModbusReceived mqtt messages, 0 = Enable ModbusReceived mqtt messages (default)
// -- MQTT - Domoticz ----------------------------- // -- MQTT - Domoticz -----------------------------
#define USE_DOMOTICZ // Enable Domoticz (+6k code, +0.3k mem) #define USE_DOMOTICZ // Enable Domoticz (+6k code, +0.3k mem)

View File

@ -1121,6 +1121,7 @@ void SettingsDefaultSet2(void) {
flag5.mqtt_persistent |= ~MQTT_CLEAN_SESSION; flag5.mqtt_persistent |= ~MQTT_CLEAN_SESSION;
flag6.mqtt_disable_sserialrec |= MQTT_DISABLE_SSERIALRECEIVED; flag6.mqtt_disable_sserialrec |= MQTT_DISABLE_SSERIALRECEIVED;
// flag.mqtt_serial |= 0; // flag.mqtt_serial |= 0;
flag6.mqtt_disable_modbus |= MQTT_DISABLE_MODBUSRECEIVED;
flag.device_index_enable |= MQTT_POWER_FORMAT; flag.device_index_enable |= MQTT_POWER_FORMAT;
flag3.time_append_timezone |= MQTT_APPEND_TIMEZONE; flag3.time_append_timezone |= MQTT_APPEND_TIMEZONE;
flag3.button_switch_force_local |= MQTT_BUTTON_SWITCH_FORCE_LOCAL; flag3.button_switch_force_local |= MQTT_BUTTON_SWITCH_FORCE_LOCAL;

View File

@ -380,7 +380,11 @@ void ModbusBridgeHandle(void)
} }
ResponseAppend_P(PSTR("]}")); ResponseAppend_P(PSTR("]}"));
ResponseJsonEnd(); ResponseJsonEnd();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_MODBUS_RECEIVED)); if (Settings->flag6.mqtt_disable_modbus ) { // SetOption158 If it is activated, Tasmota will not publish ModbusReceived MQTT messages, but it will proccess event trigger rules
XdrvRulesProcess(0);
} else {
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_MODBUS_RECEIVED));
}
} }
else if (modbusBridge.type == ModbusBridgeType::mb_hex) else if (modbusBridge.type == ModbusBridgeType::mb_hex)
{ {
@ -394,7 +398,11 @@ void ModbusBridgeHandle(void)
} }
ResponseAppend_P(PSTR("]}")); ResponseAppend_P(PSTR("]}"));
ResponseJsonEnd(); ResponseJsonEnd();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_MODBUS_RECEIVED)); if (Settings->flag6.mqtt_disable_modbus ) { // SetOption158 If it is activated, Tasmota will not publish ModbusReceived MQTT messages, but it will proccess event trigger rules
XdrvRulesProcess(0);
} else {
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_MODBUS_RECEIVED));
}
} }
else if ((modbusBridge.buffer[1] > 0) && (modbusBridge.buffer[1] < 7)) else if ((modbusBridge.buffer[1] > 0) && (modbusBridge.buffer[1] < 7))
{ {
@ -556,7 +564,11 @@ void ModbusBridgeHandle(void)
ResponseAppend_P(PSTR("}")); ResponseAppend_P(PSTR("}"));
ResponseJsonEnd(); ResponseJsonEnd();
if (errorcode == ModbusBridgeError::noerror) if (errorcode == ModbusBridgeError::noerror)
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_MODBUS_RECEIVED)); if (Settings->flag6.mqtt_disable_modbus ) { // SetOption158 If it is activated, Tasmota will not publish ModbusReceived MQTT messages, but it will proccess event trigger rules
XdrvRulesProcess(0);
} else {
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_MODBUS_RECEIVED));
}
} }
else else
errorcode = ModbusBridgeError::wrongfunctioncode; errorcode = ModbusBridgeError::wrongfunctioncode;