Better support for Prefix1 equals Prefix2

This commit is contained in:
Theo Arends 2020-01-18 16:57:48 +01:00
parent 5716d08de9
commit 45ed0257b6
4 changed files with 21 additions and 18 deletions

View File

@ -338,7 +338,8 @@ void CmndStatus(void)
char stemp2[TOPSZ];
// Workaround MQTT - TCP/IP stack queueing when SUB_PREFIX = PUB_PREFIX
if (!strcmp(SettingsText(SET_MQTTPREFIX1), SettingsText(SET_MQTTPREFIX2)) && (!payload)) { option++; } // TELE
// Commented on 20200118 as it seems to be no longer needed
// if (!strcmp(SettingsText(SET_MQTTPREFIX1), SettingsText(SET_MQTTPREFIX2)) && (!payload)) { option++; } // TELE
if ((!Settings.flag.mqtt_enabled) && (6 == payload)) { payload = 99; } // SetOption3 - Enable MQTT
if (!energy_flg && (9 == payload)) { payload = 99; }

View File

@ -692,7 +692,12 @@ void MqttPublishSensor(void)
}
}
/********************************************************************************************/
/*********************************************************************************************\
* State loops
\*********************************************************************************************/
/*-------------------------------------------------------------------------------------------*\
* Every second
\*-------------------------------------------------------------------------------------------*/
void PerformEverySecond(void)
{
@ -715,6 +720,13 @@ void PerformEverySecond(void)
#endif
}
if (mqtt_cmnd_blocked_reset) {
mqtt_cmnd_blocked_reset--;
if (!mqtt_cmnd_blocked_reset) {
mqtt_cmnd_blocked = 0; // Clean up MQTT cmnd loop block
}
}
if (seriallog_timer) {
seriallog_timer--;
if (!seriallog_timer) {
@ -763,9 +775,6 @@ void PerformEverySecond(void)
}
}
/*********************************************************************************************\
* State loops
\*********************************************************************************************/
/*-------------------------------------------------------------------------------------------*\
* Every 0.1 second
\*-------------------------------------------------------------------------------------------*/
@ -822,8 +831,6 @@ void Every250mSeconds(void)
state_250mS++;
state_250mS &= 0x3;
if (mqtt_cmnd_publish) mqtt_cmnd_publish--; // Clean up
if (!Settings.flag.global_state) { // Problem blinkyblinky enabled - SetOption31 - Control link led blinking
if (global_state.data) { // Any problem
if (global_state.mqtt_down) { blinkinterval = 7; } // MQTT problem so blink every 2 seconds (slowest)

View File

@ -110,12 +110,13 @@ float global_temperature = 9999; // Provide a global temperature to b
float global_humidity = 0; // Provide a global humidity to be used by some sensors
float global_pressure = 0; // Provide a global pressure to be used by some sensors
uint16_t tele_period = 9999; // Tele period timer
uint16_t mqtt_cmnd_publish = 0; // ignore flag for publish command
uint16_t blink_counter = 0; // Number of blink cycles
uint16_t seriallog_timer = 0; // Timer to disable Seriallog
uint16_t syslog_timer = 0; // Timer to re-enable syslog_level
int16_t save_data_counter; // Counter and flag for config save to Flash
RulesBitfield rules_flag; // Rule state flags (16 bits)
uint8_t mqtt_cmnd_blocked = 0; // Ignore flag for publish command
uint8_t mqtt_cmnd_blocked_reset = 0; // Count down to reset if needed
uint8_t state_250mS = 0; // State 250msecond per second flag
uint8_t latching_relay_pulse = 0; // Latching relay pulse timer
uint8_t sleep; // Current copy of Settings.sleep

View File

@ -225,10 +225,8 @@ bool MqttPublishLib(const char* topic, bool retained)
if (!strcmp(SettingsText(SET_MQTTPREFIX1), SettingsText(SET_MQTTPREFIX2))) {
char *str = strstr(topic, SettingsText(SET_MQTTPREFIX1));
if (str == topic) {
if (0 == mqtt_cmnd_publish) {
mqtt_cmnd_publish += 3;
}
mqtt_cmnd_publish += 3;
mqtt_cmnd_blocked_reset = 4; // Allow up to four seconds before resetting residual cmnd blocks
mqtt_cmnd_blocked++;
}
}
@ -249,12 +247,8 @@ void MqttDataHandler(char* mqtt_topic, uint8_t* mqtt_data, unsigned int data_len
// Do not execute multiple times if Prefix1 equals Prefix2
if (!strcmp(SettingsText(SET_MQTTPREFIX1), SettingsText(SET_MQTTPREFIX2))) {
char *str = strstr(mqtt_topic, SettingsText(SET_MQTTPREFIX1));
if ((str == mqtt_topic) && mqtt_cmnd_publish) {
if (mqtt_cmnd_publish > 3) {
mqtt_cmnd_publish -= 3;
} else {
mqtt_cmnd_publish = 0;
}
if ((str == mqtt_topic) && mqtt_cmnd_blocked) {
mqtt_cmnd_blocked--;
return;
}
}