Refactor Sensor MQTT data adding rule support

This commit is contained in:
Theo Arends 2019-11-10 17:40:37 +01:00
parent b2e6a2fe75
commit 48e15216be
13 changed files with 22 additions and 17 deletions

View File

@ -851,7 +851,14 @@ void PerformEverySecond(void)
tele_period = 0;
MqttPublishTeleState();
MqttPublishSensor();
mqtt_data[0] = '\0';
if (MqttShowSensor()) {
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
#if defined(USE_RULES) || defined(USE_SCRIPT)
RulesTeleperiod(); // Allow rule based HA messages
#endif // USE_RULES
}
XdrvCall(FUNC_AFTER_TELEPERIOD);
}

View File

@ -432,9 +432,7 @@ void MqttPublishPrefixTopic_P(uint32_t prefix, const char* subtopic)
void MqttPublishTeleSensor(void)
{
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
#if defined(USE_RULES) || defined(USE_SCRIPT)
RulesTeleperiod(); // Allow rule based HA messages
#endif // USE_RULES
XdrvRulesProcess();
}
void MqttPublishPowerState(uint32_t device)

View File

@ -425,7 +425,7 @@ void EnergyMqttShow(void)
EnergyShow(true);
tele_period = tele_period_save;
ResponseJsonEnd();
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
MqttPublishTeleSensor();
Energy.power_delta = false;
}
#endif // USE_ENERGY_MARGIN_DETECTION

View File

@ -181,7 +181,7 @@ void PCA9685_OutputTelemetry(bool telemetry) {
}
ResponseAppend_P(PSTR("\"END\":1}}"));
if (telemetry) {
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
MqttPublishTeleSensor();
}
}

View File

@ -126,7 +126,7 @@ void ILI9488_InitDriver()
#ifdef USE_TOUCH_BUTTONS
void ILI9488_MQTT(uint8_t count,const char *cp) {
ResponseTime_P(PSTR(",\"RA8876\":{\"%s%d\":\"%d\"}}"), cp,count+1,(buttons[count]->vpower&0x80)>>7);
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
MqttPublishTeleSensor();
}
void ILI9488_RDW_BUTT(uint32_t count,uint32_t pwr) {

View File

@ -111,7 +111,7 @@ void RA8876_InitDriver()
#ifdef USE_TOUCH_BUTTONS
void RA8876_MQTT(uint8_t count,const char *cp) {
ResponseTime_P(PSTR(",\"RA8876\":{\"%s%d\":\"%d\"}}"), cp,count+1,(buttons[count]->vpower&0x80)>>7);
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
MqttPublishTeleSensor();
}
void RA8876_RDW_BUTT(uint32_t count,uint32_t pwr) {

View File

@ -742,7 +742,7 @@ void MCP230xx_OutputTelemetry(void) {
}
}
ResponseAppend_P(PSTR("\"END\":1}}"));
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
MqttPublishTeleSensor();
}
}
@ -757,7 +757,7 @@ void MCP230xx_Interrupt_Counter_Report(void) {
}
}
ResponseAppend_P(PSTR("\"END\":1}}"));
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
MqttPublishTeleSensor();
mcp230xx_int_sec_counter = 0;
}
@ -772,7 +772,7 @@ void MCP230xx_Interrupt_Retain_Report(void) {
}
}
ResponseAppend_P(PSTR("\"Value\":%u}}"),retainresult);
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
MqttPublishTeleSensor();
}
/*********************************************************************************************\

View File

@ -360,7 +360,7 @@ void HxEvery100mSecond(void)
ResponseAppendTime();
HxShow(true);
ResponseJsonEnd();
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
MqttPublishTeleSensor();
Hx.weight_changed = false;
}
}

View File

@ -500,7 +500,7 @@ void PN532_ScanForTag(void)
ResponseTime_P(PSTR(",\"PN532\":{\"UID\":\"%s\"}}"), uids);
#endif // USE_PN532_DATA_FUNCTION
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
MqttPublishTeleSensor();
#ifdef USE_PN532_CAUSE_EVENTS

View File

@ -254,7 +254,7 @@ void SPS30_Show(bool json) {
void CmdClean(void) {
sps30_cmd(SPS_CMD_CLEAN);
ResponseTime_P(PSTR(",\"SPS30\":{\"CFAN\":\"true\"}}"));
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
MqttPublishTeleSensor();
}
bool SPS30_cmd(void) {

View File

@ -107,7 +107,7 @@ void RDM6300_ScanForTag() {
rdm_uid_str[9]=0;
ResponseTime_P(PSTR(",\"RDM6300\":{\"UID\":\"%s\"}}"), rdm_uid_str);
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
MqttPublishTeleSensor();
/*
char command[24];
sprintf(command,"event RDM6300=%s",rdm_uid_str);

View File

@ -548,7 +548,7 @@ void ibeacon_mqtt(const char *mac,const char *rssi) {
s_rssi[4]=0;
int16_t n_rssi=atoi(s_rssi);
ResponseTime_P(PSTR(",\"" D_CMND_IBEACON "_%s\":{\"RSSI\":%d}}"),s_mac,n_rssi);
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
MqttPublishTeleSensor();
}

View File

@ -1621,7 +1621,7 @@ void SML_Immediate_MQTT(const char *mp,uint8_t index,uint8_t mindex) {
// immediate mqtt
dtostrfd(meter_vars[index],dp&0xf,tpowstr);
ResponseTime_P(PSTR(",\"%s\":{\"%s\":%s}}"),meter_desc_p[mindex].prefix,jname,tpowstr);
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); // CMND_SENSORRETAIN
MqttPublishTeleSensor();
}
}
}