Refactor rules processing

This commit is contained in:
Theo Arends 2020-07-20 17:24:51 +02:00
parent 460f166bcc
commit a84ebe552a
19 changed files with 68 additions and 103 deletions

View File

@ -288,8 +288,7 @@ void CommandHandler(char* topicBuf, char* dataBuf, uint32_t data_len)
}
if (mqtt_data[0] != '\0') {
MqttPublishPrefixTopic_P(RESULT_OR_STAT, type);
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, type);
}
fallback_topic_flag = false;
}

View File

@ -136,8 +136,7 @@ void RotaryHandler(void) {
#ifdef USE_LIGHT
if (!Settings.flag4.rotary_uses_rules) { // SetOption98 - Use rules instead of light control
ResponseLightState(0);
MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_CMND_STATE));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_CMND_STATE));
}
#endif // USE_LIGHT
Encoder[index].direction = 0;

View File

@ -1429,8 +1429,7 @@ void SerialInput(void)
}
ResponseJsonEnd();
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_SERIALRECEIVED));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_SERIALRECEIVED));
serial_in_byte_counter = 0;
}
}

View File

@ -381,10 +381,20 @@ void MqttPublishPrefixTopic_P(uint32_t prefix, const char* subtopic)
MqttPublishPrefixTopic_P(prefix, subtopic, false);
}
void MqttPublishPrefixTopicRulesProcess_P(uint32_t prefix, const char* subtopic, bool retained)
{
MqttPublishPrefixTopic_P(prefix, subtopic, retained);
XdrvRulesProcess();
}
void MqttPublishPrefixTopicRulesProcess_P(uint32_t prefix, const char* subtopic)
{
MqttPublishPrefixTopicRulesProcess_P(prefix, subtopic, false);
}
void MqttPublishTeleSensor(void)
{
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
}
void MqttPublishPowerState(uint32_t device)

View File

@ -370,8 +370,7 @@ void EnergyMarginCheck(void)
}
if (jsonflg) {
ResponseJsonEndEnd();
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_MARGINS), MQTT_TELE_RETAIN);
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR(D_RSLT_MARGINS), MQTT_TELE_RETAIN);
EnergyMqttShow();
}

View File

@ -1878,8 +1878,7 @@ void LightAnimate(void)
Response_P(PSTR("{\"" D_CMND_WAKEUP "\":\"" D_JSON_DONE "\""));
ResponseLightState(1);
ResponseJsonEnd();
MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_CMND_WAKEUP));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_CMND_WAKEUP));
Light.wakeup_active = 0;
Settings.light_scheme = LS_POWER;

View File

@ -155,9 +155,8 @@ void IrReceiveCheck(void)
}
ResponseJsonEndEnd();
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_IRRECEIVED));
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_IRRECEIVED));
XdrvRulesProcess();
#ifdef USE_DOMOTICZ
if (iridx) {
unsigned long value = results.value | (iridx << 28); // [Protocol:4, Data:28]

View File

@ -232,9 +232,7 @@ void IrReceiveCheck(void)
}
ResponseJsonEndEnd();
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_IRRECEIVED));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_IRRECEIVED));
}
irrecv->resume();
@ -475,7 +473,7 @@ uint32_t IrRemoteCmndIrSendRaw(void)
for (uint32_t i = 0; i <= count; i++) {
GC[i] = strtol(strtok_r(nullptr, ", ", &p), nullptr, 0);
if (!GC[i]) {
return IE_INVALID_RAWDATA;
return IE_INVALID_RAWDATA;
}
}
irsend_active = true;

View File

@ -226,9 +226,7 @@ void SonoffBridgeReceivedRaw(void)
}
}
ResponseAppend_P(PSTR("\"}}"));
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_CMND_RFRAW));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_CMND_RFRAW));
}
/********************************************************************************************/
@ -298,8 +296,7 @@ void SonoffBridgeReceived(void)
}
ResponseTime_P(PSTR(",\"" D_JSON_RFRECEIVED "\":{\"" D_JSON_SYNC "\":%d,\"" D_JSON_LOW "\":%d,\"" D_JSON_HIGH "\":%d,\"" D_JSON_DATA "\":%s,\"" D_CMND_RFKEY "\":%s}}"),
sync_time, low_time, high_time, stemp, rfkey);
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_RFRECEIVED));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_RFRECEIVED));
#ifdef USE_DOMOTICZ
DomoticzSensor(DZ_COUNT, received_id); // Send rid as Domoticz Counter value
#endif // USE_DOMOTICZ

View File

@ -93,8 +93,7 @@ void SerialBridgeInput(void)
}
ResponseJsonEnd();
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_SSERIALRECEIVED));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_SSERIALRECEIVED));
serial_bridge_in_byte_counter = 0;
}
}

View File

@ -69,8 +69,7 @@ void RfReceiveCheck(void)
}
ResponseTime_P(PSTR(",\"" D_JSON_RFRECEIVED "\":{\"" D_JSON_RF_DATA "\":%s,\"" D_JSON_RF_BITS "\":%d,\"" D_JSON_RF_PROTOCOL "\":%d,\"" D_JSON_RF_PULSE "\":%d}}"),
stemp, bits, protocol, delay);
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_RFRECEIVED));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_RFRECEIVED));
#ifdef USE_DOMOTICZ
DomoticzSensor(DZ_COUNT, data); // Send data as Domoticz Counter value
#endif // USE_DOMOTICZ

View File

@ -622,8 +622,7 @@ public:
_frame_control, _manuf_code, _transact_seq, _cmd_id,
hex_char);
if (Settings.flag3.tuya_serial_mqtt_publish) {
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR(D_RSLT_SENSOR));
} else {
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_ZIGBEE "%s"), mqtt_data);
}
@ -1152,8 +1151,7 @@ void ZCLFrame::parseResponse(void) {
msg.reserve(100);
json.printTo(msg);
Response_P(PSTR("{\"" D_JSON_ZIGBEE_RESPONSE "\":%s}"), msg.c_str());
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
}

View File

@ -1097,8 +1097,7 @@ void ZigbeeStateMachine_Run(void) {
const char *f_msg = (const char*) cur_ptr1;
Response_P(PSTR("{\"" D_JSON_ZIGBEE_STATE "\":{\"Status\":%d,\"Message\":\"%s\"}}"),
cur_d8, f_msg);
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_STATE));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_STATE));
}
break;
case ZGB_INSTR_SEND:

View File

@ -43,8 +43,7 @@ int32_t EZ_RSTACK(uint8_t reset_code) {
",\"Code\":%d}}"),
ZIGBEE_STATUS_BOOT, reason_str, reset_code);
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_STATE));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_STATE));
}
// EZSP: received ASH "ERROR" frame, indicating that the MCU finished boot
@ -60,8 +59,7 @@ int32_t EZ_ERROR(uint8_t error_code) {
",\"Code\":%d}}"),
ZIGBEE_STATUS_ABORT, reason_str, error_code);
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_STATE));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_STATE));
}
int32_t EZ_ReadAPSUnicastMessage(int32_t res, class SBuffer &buf) {
@ -112,8 +110,7 @@ int32_t EZ_NetworkParameters(int32_t res, class SBuffer &buf) {
",\"DeviceType\":%d}}"),
ZIGBEE_STATUS_EZ_INFO, hex, localShortAddr, node_type);
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_STATE));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_STATE));
return res;
}
@ -161,8 +158,7 @@ int32_t Z_EZSPNetworkParameters(int32_t res, class SBuffer &buf) {
",\"DeviceType\":%d}}"),
ZIGBEE_STATUS_EZ_INFO, hex, localShortAddr, node_type);
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_STATE));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_STATE));
return res;
}
@ -212,10 +208,8 @@ int32_t ZNP_ReceiveDeviceInfo(int32_t res, class SBuffer &buf) {
ResponseAppend_P(PSTR("]"));
}
ResponseJsonEnd(); // append '}'
ResponseJsonEnd(); // append '}'
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_STATE));
XdrvRulesProcess();
ResponseJsonEndEnd(); // append '}}'
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_STATE));
return res;
}
@ -257,8 +251,7 @@ int32_t ZNP_Reboot(int32_t res, class SBuffer &buf) {
ZIGBEE_STATUS_BOOT, reason_str,
major_rel, minor_rel);
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_STATE));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_STATE));
if ((0x02 == major_rel) && (0x06 == minor_rel)) {
return 0; // version 2.6.x is ok
@ -289,8 +282,7 @@ int32_t ZNP_ReceiveCheckVersion(int32_t res, class SBuffer &buf) {
ZIGBEE_STATUS_CC_VERSION, major_rel, minor_rel,
maint_rel, revision);
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_STATE));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_STATE));
if ((0x02 == major_rel) && (0x06 == minor_rel)) {
return 0; // version 2.6.x is ok
@ -318,8 +310,7 @@ int32_t EZ_ReceiveCheckVersion(int32_t res, class SBuffer &buf) {
stack_type
);
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_STATE));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_STATE));
if (0x08 == protocol_version) {
return 0; // protocol v8 is ok
@ -394,8 +385,7 @@ int32_t ZNP_ReceivePermitJoinStatus(int32_t res, const class SBuffer &buf) {
ResponseAppend_P(message, duration);
ResponseAppend_P(PSTR("\"}}"));
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_STATE));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_STATE));
return -1;
}
@ -435,8 +425,7 @@ int32_t ZNP_ReceiveNodeDesc(int32_t res, const class SBuffer &buf) {
complexDescriptorAvailable ? PSTR("true") : PSTR("false")
);
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
}
return -1;
@ -473,8 +462,7 @@ int32_t Z_ReceiveActiveEp(int32_t res, const class SBuffer &buf) {
ResponseAppend_P(PSTR("\"0x%02X\""), activeEpList[i]);
}
ResponseAppend_P(PSTR("]}}"));
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
Z_SendAFInfoRequest(nwkAddr); // probe for ModelId and ManufId
@ -515,8 +503,7 @@ int32_t Z_ReceiveIEEEAddr(int32_t res, const class SBuffer &buf) {
}
ResponseAppend_P(PSTR("\"}}"));
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
}
return -1;
}
@ -534,8 +521,7 @@ int32_t ZNP_DataConfirm(int32_t res, const class SBuffer &buf) {
",\"" D_JSON_ZIGBEE_STATUS "\":%d"
",\"" D_JSON_ZIGBEE_STATUS_MSG "\":\"%s\""
"}}"), endpoint, status, getZigbeeStatusMessage(status).c_str());
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
}
return -1;
@ -591,8 +577,7 @@ int32_t ZNP_ReceiveStateChange(int32_t res, const class SBuffer &buf) {
ZIGBEE_STATUS_SCANNING, state, msg
);
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
}
if ((ZDO_DEV_END_DEVICE == state) || (ZDO_DEV_ROUTER == state) || (ZDO_DEV_ZB_COORD == state)) {
@ -637,8 +622,7 @@ int32_t Z_ReceiveEndDeviceAnnonce(int32_t res, const class SBuffer &buf) {
uint32_t wait_ms = 2000; // wait for 2s
Z_Query_Bulb(nwkAddr, wait_ms);
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
Z_SendActiveEpReq(nwkAddr);
return -1;
}
@ -662,8 +646,7 @@ int32_t ZNP_ReceiveTCDevInd(int32_t res, const class SBuffer &buf) {
ZIGBEE_STATUS_DEVICE_INDICATION, hex, srcAddr, parentNw
);
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
return -1;
}
@ -692,8 +675,7 @@ int32_t Z_BindRsp(int32_t res, const class SBuffer &buf) {
",\"" D_JSON_ZIGBEE_STATUS_MSG "\":\"%s\""
"}}"), status, msg.c_str());
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
return -1;
}
@ -723,8 +705,7 @@ int32_t Z_UnbindRsp(int32_t res, const class SBuffer &buf) {
",\"" D_JSON_ZIGBEE_STATUS_MSG "\":\"%s\""
"}}"), status, msg.c_str());
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
return -1;
}
@ -799,8 +780,7 @@ int32_t Z_MgmtBindRsp(int32_t res, const class SBuffer &buf) {
ResponseAppend_P(PSTR("]}}"));
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_BIND_STATE));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_BIND_STATE));
return -1;
}
@ -880,8 +860,7 @@ int32_t EZ_ReceiveTCJoinHandler(int32_t res, const class SBuffer &buf) {
status, decision
);
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEEZCL_RECEIVED));
}
return -1;
}

View File

@ -131,8 +131,7 @@ void ZigbeeInputLoop(void) {
ToHex_P((unsigned char*)znp_buffer.getBuffer(), znp_buffer.len(), hex_char, sizeof(hex_char));
Response_P(PSTR("{\"" D_JSON_ZIGBEEZNPRECEIVED "\":\"%s\"}"), hex_char);
if (Settings.flag3.tuya_serial_mqtt_publish) {
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR(D_RSLT_SENSOR));
} else {
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_ZIGBEE "%s"), mqtt_data);
}
@ -194,7 +193,7 @@ void ZigbeeInputLoop(void) {
if (zigbee_buffer->len() < ZIGBEE_BUFFER_SIZE) {
if (escape) {
// invert bit 5
zigbee_in_byte ^= 0x20;
zigbee_in_byte ^= 0x20;
escape = false;
}
@ -252,8 +251,7 @@ void ZigbeeInputLoop(void) {
ToHex_P((unsigned char*)ezsp_buffer.getBuffer(), ezsp_buffer.len(), hex_char, sizeof(hex_char));
Response_P(PSTR("{\"" D_JSON_ZIGBEE_EZSP_RECEIVED "2\":\"%s\"}"), hex_char);
if (Settings.flag3.tuya_serial_mqtt_publish) {
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR(D_RSLT_SENSOR));
} else {
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_ZIGBEE "%s"), mqtt_data); // TODO move to LOG_LEVEL_DEBUG when stable
}
@ -435,7 +433,7 @@ void ZigbeeEZSPSendRaw(const uint8_t *msg, size_t len, bool send_cancel) {
bool data_frame = (0 == (msg[0] & 0x80));
uint8_t rand = 0x42; // pseudo-randomizer initial value
uint16_t crc = 0xFFFF; // CRC16 CCITT initialization
for (uint32_t i=0; i<len; i++) {
uint8_t out_byte = msg[i];
@ -508,7 +506,7 @@ void ZigbeeEZSPSendDATA(const uint8_t *msg, size_t len, bool send_cancel) {
ZigbeeEZSPSendRaw(buf.getBuffer(), buf.len(), send_cancel);
}
// Receive a high-level EZSP command/response, starting with 16-bits frame ID
// Receive a high-level EZSP command/response, starting with 16-bits frame ID
int32_t ZigbeeProcessInputEZSP(class SBuffer &buf) {
// verify errors in first 2 bytes.
// TODO
@ -534,8 +532,7 @@ int32_t ZigbeeProcessInputEZSP(class SBuffer &buf) {
ToHex_P((unsigned char*)buf.getBuffer(), buf.len(), hex_char, sizeof(hex_char));
Response_P(PSTR("{\"" D_JSON_ZIGBEE_EZSP_RECEIVED "\":\"%s\"}"), hex_char);
if (Settings.flag3.tuya_serial_mqtt_publish) {
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(TELE, PSTR(D_RSLT_SENSOR));
} else {
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_ZIGBEE "%s"), mqtt_data); // TODO move to LOG_LEVEL_DEBUG when stable
}
@ -562,7 +559,7 @@ int32_t ZigbeeProcessInputRaw(class SBuffer &buf) {
// NAK
AddLog_P2(LOG_LEVEL_INFO, PSTR("ZIG: Received NAK %d, resending not implemented"), ack_num);
} else if (control_byte == 0xC1) {
// RSTACK
// received just after boot, either because of Power up, hardware reset or RST
EZ_RSTACK(buf.get8(2));
@ -576,7 +573,7 @@ int32_t ZigbeeProcessInputRaw(class SBuffer &buf) {
buf.setLen(3);
ZigbeeProcessInput(buf);
} else if (control_byte == 0xC2) {
// ERROR
EZ_ERROR(buf.get8(2));
zigbee.active = false; // stop all zigbee activities
@ -641,7 +638,7 @@ void CmndZbEZSPSendOrReceive(bool send)
if (2 == XdrvMailbox.index) { ZigbeeEZSPSendDATA(buf.getBuffer(), buf.len(), true); }
else if (3 == XdrvMailbox.index) { ZigbeeEZSPSendRaw(buf.getBuffer(), buf.len(), true); }
else { ZigbeeEZSPSendCmd(buf.getBuffer(), buf.len(), true); }
} else {
// Command was `ZbEZSPReceive`
if (2 == XdrvMailbox.index) { ZigbeeProcessInput(buf); }

View File

@ -715,7 +715,7 @@ void ZbBindUnbind(bool unbind) { // false = bind, true = unbind
#ifdef USE_ZIGBEE_EZSP
SBuffer buf(24);
// ZDO message payload (see Zigbee spec 2.4.3.2.2)
buf.add64(srcLongAddr);
buf.add8(endpoint);
@ -895,8 +895,7 @@ void CmndZbLight(void) {
String dump = zigbee_devices.dumpLightState(shortaddr);
Response_P(PSTR("{\"" D_PRFX_ZB D_CMND_ZIGBEE_LIGHT "\":%s}"), dump.c_str());
MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_PRFX_ZB D_CMND_ZIGBEE_LIGHT));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_PRFX_ZB D_CMND_ZIGBEE_LIGHT));
ResponseCmndDone();
}
@ -1041,7 +1040,7 @@ void CmndZbEZSPListen(void) {
} else if (group > 0xFFFF) {
group = 0xFFFF;
}
SBuffer buf(8);
buf.add16(EZSP_setMulticastTableEntry);
buf.add8(index);

View File

@ -279,8 +279,7 @@ void ShutterReportPosition(bool always, uint32_t index)
}
ResponseJsonEnd();
if (always || (rules_flag.shutter_moving)) {
MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_PRFX_SHUTTER));
XdrvRulesProcess(); //RulesProcess() now re-entry protected
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_PRFX_SHUTTER)); // RulesProcess() now re-entry protected
}
//AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: rules_flag.shutter_moving: %d, moved %d"), rules_flag.shutter_moving, rules_flag.shutter_moved);
@ -716,8 +715,7 @@ void ShutterButtonHandler(void)
Response_P(PSTR("{"));
ResponseAppend_P(JSON_SHUTTER_BUTTON, shutter_index+1, (buttonState <= SHT_PRESSED_EXT_HOLD) ? (button_index+1) : 0, press_index);
ResponseJsonEnd();
MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_PRFX_SHUTTER));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_PRFX_SHUTTER));
}
}

View File

@ -539,8 +539,7 @@ void TasmotaClient_ProcessIn(void) {
Response_P(PSTR("{\"TasmotaClient\":"));
ResponseAppend_P("%s", inbuf);
ResponseJsonEnd();
MqttPublishPrefixTopic_P(RESULT_OR_TELE, mqtt_data);
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, mqtt_data);
}
if (CMND_EXECUTE_CMND == TClientCommand.command) { // We need to execute the incoming command
ExecuteCommand(inbuf, SRC_IGNORE);

View File

@ -35,7 +35,7 @@ void (* const PingCommand[])(void) PROGMEM = {
};
extern "C" {
extern uint32 system_relative_time(uint32 time);
extern void ets_bzero(void *s, size_t n);
@ -130,7 +130,7 @@ extern "C" {
if ((p->len == p->tot_len) && (p->next == nullptr)) {
ip_addr_t ping_target;
struct icmp_echo_hdr *iecho;
ping_target.addr = ping->ip;
iecho = (struct icmp_echo_hdr *) p->payload;
@ -177,7 +177,7 @@ extern "C" {
iecho = (struct icmp_echo_hdr *)p->payload;
if ((iecho->id == Ping_ID) && (iecho->seqno == htons(ping->seq_num)) && iecho->type == ICMP_ER) {
if (iecho->seqno != ping->seqno){ // debounce already received packet
/* do some ping result processing */
sys_untimeout(t_ping_timeout, ping); // remove time-out handler
@ -282,9 +282,8 @@ void PingResponsePoll(void) {
success ? ping->min_time : 0, ping->max_time,
success ? ping->sum_time / success : 0
);
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_PING));
XdrvRulesProcess();
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_PING));
// remove from linked list
*prev_link = ping->next;
// don't increment prev_link