diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index 6de585017..2f27c36ef 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -2188,7 +2188,7 @@ const char* g_obk_flagNames[] = { "[DRV] Deactivate Autostart of all drivers", "[WiFi] Quick connect to WiFi on reboot (TODO: check if it works for you and report on github)", "[Power] Set power and current to zero if all relays are open", - "TODO - UNUSED", + "[MQTT] [Debug] Publish all channels (don't enable it, it will be publish all 64 possible channels on connect)", "error", "error", "error", diff --git a/src/mqtt/new_mqtt.c b/src/mqtt/new_mqtt.c index 700d1c848..a60872b3c 100644 --- a/src/mqtt/new_mqtt.c +++ b/src/mqtt/new_mqtt.c @@ -620,7 +620,7 @@ int channelSet(obk_mqtt_request_t* request) { // if not /set, then stop here if (strcmp(p, "/set")) { - addLogAdv(LOG_INFO, LOG_FEATURE_MQTT, "channelSet NOT 'set'"); + //addLogAdv(LOG_INFO, LOG_FEATURE_MQTT, "channelSet NOT 'set'"); return 0; } @@ -961,7 +961,7 @@ static void mqtt_incoming_data_cb(void* arg, const u8_t* data, u16_t len, u8_t f //} } } - addLogAdv(LOG_INFO, LOG_FEATURE_MQTT, "MQTT topic not handled: %s", g_mqtt_request.topic); + //addLogAdv(LOG_INFO, LOG_FEATURE_MQTT, "MQTT topic not handled: %s", g_mqtt_request.topic); } } @@ -1762,16 +1762,9 @@ OBK_Publish_Result MQTT_DoItemPublish(int idx) // because we are using led_basecolor_rgb, led_dimmer, led_enableAll, etc // NOTE: negative indexes are not channels - they are special values bWantsToPublish = false; - if (CHANNEL_HasRoleThatShouldBePublished(idx)) { + if (CHANNEL_ShouldBePublished(idx)) { bWantsToPublish = true; } -#ifdef ENABLE_DRIVER_TUYAMCU - // publish if channel is used by TuyaMCU (no pin role set), for example door sensor state with power saving V0 protocol - // Not enabled by default, you have to set OBK_FLAG_TUYAMCU_ALWAYSPUBLISHCHANNELS flag - if (!bWantsToPublish && CFG_HasFlag(OBK_FLAG_TUYAMCU_ALWAYSPUBLISHCHANNELS) && TuyaMCU_IsChannelUsedByTuyaMCU(idx)) { - bWantsToPublish = true; - } -#endif // TODO //type = CHANNEL_GetType(idx); if (bWantsToPublish) { diff --git a/src/new_pins.c b/src/new_pins.c index c608d023c..6e93d29f3 100644 --- a/src/new_pins.c +++ b/src/new_pins.c @@ -888,8 +888,6 @@ static void Channel_OnChanged(int ch, int prevValue, int iFlags) { int i; int iVal; int bOn; - int bCallCb = 0; - //bOn = BIT_CHECK(g_channelStates,ch); iVal = g_channelValues[ch]; @@ -912,45 +910,20 @@ static void Channel_OnChanged(int ch, int prevValue, int iFlags) { if (g_cfg.pins.channels[i] == ch) { if (g_cfg.pins.roles[i] == IOR_Relay || g_cfg.pins.roles[i] == IOR_BAT_Relay || g_cfg.pins.roles[i] == IOR_LED) { RAW_SetPinValue(i, bOn); - bCallCb = 1; } else if (g_cfg.pins.roles[i] == IOR_Relay_n || g_cfg.pins.roles[i] == IOR_LED_n) { RAW_SetPinValue(i, !bOn); - bCallCb = 1; - } - else if (g_cfg.pins.roles[i] == IOR_DigitalInput || g_cfg.pins.roles[i] == IOR_DigitalInput_n - || g_cfg.pins.roles[i] == IOR_DigitalInput_NoPup || g_cfg.pins.roles[i] == IOR_DigitalInput_NoPup_n - || g_cfg.pins.roles[i] == IOR_DoorSensorWithDeepSleep || g_cfg.pins.roles[i] == IOR_DoorSensorWithDeepSleep_NoPup - || g_cfg.pins.roles[i] == IOR_DoorSensorWithDeepSleep_pd) { - bCallCb = 1; - } - else if (g_cfg.pins.roles[i] == IOR_ToggleChannelOnToggle) { - bCallCb = 1; } else if (g_cfg.pins.roles[i] == IOR_PWM) { HAL_PIN_PWM_Update(i, iVal); - bCallCb = 1; } else if (g_cfg.pins.roles[i] == IOR_PWM_n) { HAL_PIN_PWM_Update(i, 100 - iVal); - bCallCb = 1; - } - else if (IS_PIN_DHT_ROLE(g_cfg.pins.roles[i])) { - bCallCb = 1; } } - else if (g_cfg.pins.channels2[i] == ch) { - //DHT setup uses 2 channels - if (IS_PIN_DHT_ROLE(g_cfg.pins.roles[i])) { - bCallCb = 1; - } - } - } - if (g_cfg.pins.channelTypes[ch] != ChType_Default) { - bCallCb = 1; } if ((iFlags & CHANNEL_SET_FLAG_SKIP_MQTT) == 0) { - if (bCallCb) { + if (CHANNEL_ShouldBePublished(ch)) { MQTT_ChannelPublish(ch, 0); } } @@ -1307,7 +1280,7 @@ bool CHANNEL_IsPowerRelayChannel(int ch) { } return false; } -bool CHANNEL_HasRoleThatShouldBePublished(int ch) { +bool CHANNEL_ShouldBePublished(int ch) { int i; for (i = 0; i < PLATFORM_GPIO_MAX; i++) { int role = g_cfg.pins.roles[i]; @@ -1335,6 +1308,16 @@ bool CHANNEL_HasRoleThatShouldBePublished(int ch) { } } } + if (g_cfg.pins.channelTypes[ch] != ChType_Default) { + return true; + } +#ifdef ENABLE_DRIVER_TUYAMCU + // publish if channel is used by TuyaMCU (no pin role set), for example door sensor state with power saving V0 protocol + // Not enabled by default, you have to set OBK_FLAG_TUYAMCU_ALWAYSPUBLISHCHANNELS flag + if (CFG_HasFlag(OBK_FLAG_TUYAMCU_ALWAYSPUBLISHCHANNELS) && TuyaMCU_IsChannelUsedByTuyaMCU(ch)) { + return true; + } +#endif return false; } int CHANNEL_GetRoleForOutputChannel(int ch) { diff --git a/src/new_pins.h b/src/new_pins.h index 54dd4a9b2..35afe105f 100644 --- a/src/new_pins.h +++ b/src/new_pins.h @@ -861,7 +861,7 @@ typedef struct pinsState_s { #define OBK_FLAG_DRV_DISABLE_AUTOSTART 36 #define OBK_FLAG_WIFI_FAST_CONNECT 37 #define OBK_FLAG_POWER_FORCE_ZERO_IF_RELAYS_OPEN 38 -#define OBK_FLAG_UNUSED_TODO 39 +#define OBK_FLAG_MQTT_PUBLISH_ALL_CHANNELS 39 #define OBK_TOTAL_FLAGS 40