flag to publish self state every minute

This commit is contained in:
openshwprojects
2022-07-01 11:24:43 +02:00
parent b2dd65f7d5
commit 67d2855d00
3 changed files with 18 additions and 1 deletions

View File

@@ -1344,6 +1344,9 @@ int http_fn_cfg_pins(http_request_t *request) {
const char *g_obk_flagNames[] = {
"[MQTT] Broadcast led params together (send dimmer and color when dimmer or color changes, topic name: YourDevName/led_basecolor_rgb/get, YourDevName/led_dimmer/get)",
"[MQTT] Broadcast led final color (topic name: YourDevName/led_finalcolor_rgb/get)",
"[MQTT] Broadcast self state every minute",
"error",
"error",
"error",
"error",
"error",

View File

@@ -678,6 +678,7 @@ bool MQTT_DoItemPublish(int idx) {
}
return false; // didnt publish
}
static int g_secondsBeforeNextFullBroadcast = 30;
// called from user timer.
int MQTT_RunEverySecondUpdate() {
@@ -718,12 +719,14 @@ int MQTT_RunEverySecondUpdate() {
// The item indexes start at negative values for special items
// and then covers Channel indexes up to CHANNEL_MAX
if(g_bPublishAllStatesNow) {
// Doing step by a step a full publish state
int g_sent_thisFrame = 0;
while(g_publishItemIndex < CHANNEL_MAX) {
if(MQTT_DoItemPublish(g_publishItemIndex)) {
g_sent_thisFrame++;
if(g_sent_thisFrame>=2){
g_publishItemIndex++;
break;
}
}
@@ -733,6 +736,16 @@ int MQTT_RunEverySecondUpdate() {
// done
g_bPublishAllStatesNow = 0;
}
} else {
// not doing anything
if(CFG_HasFlag(OBK_FLAG_MQTT_BROADCASTSELFSTATEPERMINUTE)) {
// this is called every second
g_secondsBeforeNextFullBroadcast--;
if(g_secondsBeforeNextFullBroadcast <= 0) {
g_secondsBeforeNextFullBroadcast = 60;
MQTT_PublishWholeDeviceState();
}
}
}
}

View File

@@ -80,7 +80,8 @@ typedef struct pinsState_s {
// bit indexes (not values), so 0 1 2 3 4
#define OBK_FLAG_MQTT_BROADCASTLEDPARAMSTOGETHER 0
#define OBK_FLAG_MQTT_BROADCASTLEDFINALCOLOR 1
#define OBK_TOTAL_FLAGS 2
#define OBK_FLAG_MQTT_BROADCASTSELFSTATEPERMINUTE 2
#define OBK_TOTAL_FLAGS 3
//
// Main config structure (less than 2KB)