diff --git a/platforms/W600/Makefile b/platforms/W600/Makefile index 300483713..8f49d7529 100644 --- a/platforms/W600/Makefile +++ b/platforms/W600/Makefile @@ -47,6 +47,7 @@ CSRCS += $(_SHARED_APP)/driver/drv_dht_internal.c CSRCS += $(_SHARED_APP)/driver/drv_httpButtons.c CSRCS += $(_SHARED_APP)/driver/drv_main.c CSRCS += $(_SHARED_APP)/driver/drv_ntp.c +CSRCS += $(_SHARED_APP)/driver/drv_ds1820_simple.c CSRCS += $(_SHARED_APP)/driver/drv_tasmotaDeviceGroups.c CSRCS += $(_SHARED_APP)/driver/drv_test_drivers.c CSRCS += $(_SHARED_APP)/driver/drv_bridge_driver.c diff --git a/platforms/W800/Makefile b/platforms/W800/Makefile index 9c8874db0..d9acbbe7d 100644 --- a/platforms/W800/Makefile +++ b/platforms/W800/Makefile @@ -59,9 +59,50 @@ CSRCS += $(_SHARED_APP)/new_ping.c CSRCS += $(_SHARED_APP)/new_pins.c CSRCS += $(_SHARED_APP)/rgb2hsv.c CSRCS += $(_SHARED_APP)/tiny_crc8.c +CSRCS += $(_SHARED_APP)/driver/drv_adcButton.c +CSRCS += $(_SHARED_APP)/driver/drv_adcSmoother.c +CSRCS += $(_SHARED_APP)/driver/drv_battery.c +CSRCS += $(_SHARED_APP)/driver/drv_bp1658cj.c +CSRCS += $(_SHARED_APP)/driver/drv_bp5758d.c +CSRCS += $(_SHARED_APP)/driver/drv_bmp280.c +CSRCS += $(_SHARED_APP)/driver/drv_bmpi2c.c +CSRCS += $(_SHARED_APP)/driver/drv_bridge_driver.c +CSRCS += $(_SHARED_APP)/driver/drv_cht8305.c +CSRCS += $(_SHARED_APP)/driver/drv_charts.c +CSRCS += $(_SHARED_APP)/driver/drv_chargingLimit.c +CSRCS += $(_SHARED_APP)/driver/drv_ddp.c +CSRCS += $(_SHARED_APP)/driver/drv_debouncer.c +CSRCS += $(_SHARED_APP)/driver/drv_doorSensorWithDeepSleep.c +CSRCS += $(_SHARED_APP)/driver/drv_drawers.c +CSRCS += $(_SHARED_APP)/driver/drv_freeze.c +CSRCS += $(_SHARED_APP)/driver/drv_httpButtons.c +CSRCS += $(_SHARED_APP)/driver/drv_kp18058.c +CSRCS += $(_SHARED_APP)/driver/drv_kp18068.c +CSRCS += $(_SHARED_APP)/driver/drv_max72xx_clock.c +CSRCS += $(_SHARED_APP)/driver/drv_max72xx_internal.c +CSRCS += $(_SHARED_APP)/driver/drv_max72xx_single.c +CSRCS += $(_SHARED_APP)/driver/drv_max6675.c +CSRCS += $(_SHARED_APP)/driver/drv_mcp9808.c CSRCS += $(_SHARED_APP)/driver/drv_main.c +CSRCS += $(_SHARED_APP)/driver/drv_ntp.c +CSRCS += $(_SHARED_APP)/driver/drv_ntp_events.c +CSRCS += $(_SHARED_APP)/driver/drv_pt6523.c +CSRCS += $(_SHARED_APP)/driver/drv_pwmToggler.c +CSRCS += $(_SHARED_APP)/driver/drv_sgp.c +CSRCS += $(_SHARED_APP)/driver/drv_soft_i2c.c +CSRCS += $(_SHARED_APP)/driver/drv_shiftRegister.c +CSRCS += $(_SHARED_APP)/driver/drv_tasmotaDeviceGroups.c +CSRCS += $(_SHARED_APP)/driver/drv_ssdp.c CSRCS += $(_SHARED_APP)/driver/drv_ds1820_simple.c CSRCS += $(_SHARED_APP)/driver/drv_charts.c +CSRCS += $(_SHARED_APP)/driver/drv_dht.c +CSRCS += $(_SHARED_APP)/i2c/drv_i2c_main.c +CSRCS += $(_SHARED_APP)/i2c/drv_i2c_tc74.c +CSRCS += $(_SHARED_APP)/i2c/drv_i2c_ads1115.c +CSRCS += $(_SHARED_APP)/i2c/drv_i2c_lcd_pcf8574t.c +CSRCS += $(_SHARED_APP)/i2c/drv_i2c_mcp23017.c +CSRCS += $(_SHARED_APP)/driver/drv_dht_internal.c +CSRCS += $(_SHARED_APP)/driver/drv_openWeatherMap.c CSRCS += $(_SHARED_APP)/user_main.c CSRCS += main.c diff --git a/src/cmnds/cmd_if.c b/src/cmnds/cmd_if.c index 32d254555..9fed0d19f 100644 --- a/src/cmnds/cmd_if.c +++ b/src/cmnds/cmd_if.c @@ -189,6 +189,7 @@ float getFlagValue(const char *s) { return CFG_HasFlag(idx); } +#if ENABLE_LED_BASIC float getLedDimmer(const char *s) { return LED_GetDimmer(); } @@ -220,6 +221,7 @@ float getLedSaturation(const char *s) { float getLedTemperature(const char *s) { return LED_GetTemperature(); } +#endif float getActiveRepeatingEvents(const char *s) { return RepeatingEvents_GetActiveCount(); @@ -369,6 +371,7 @@ const constant_t g_constants[] = { //cnstdetail:"descr":"Provides flag access, as above.", //cnstdetail:"requires":""} {"$FLAG*", &getFlagValue}, +#if ENABLE_LED_BASIC //cnstdetail:{"name":"$led_dimmer", //cnstdetail:"title":"$led_dimmer", //cnstdetail:"descr":"Current value of LED dimmer, 0-100 range", @@ -409,6 +412,7 @@ const constant_t g_constants[] = { //cnstdetail:"descr":"Current LED temperature value", //cnstdetail:"requires":""} {"$led_temperature", &getLedTemperature}, +#endif //cnstdetail:{"name":"$activeRepeatingEvents", //cnstdetail:"title":"$activeRepeatingEvents", //cnstdetail:"descr":"Current number of active repeating events", diff --git a/src/cmnds/cmd_main.c b/src/cmnds/cmd_main.c index 1d04b5ce7..d9bf68596 100644 --- a/src/cmnds/cmd_main.c +++ b/src/cmnds/cmd_main.c @@ -215,7 +215,7 @@ static commandResult_t CMD_DeepSleep(const void* context, const char* cmd, const return CMD_RES_OK; } - +#if ENABLE_HA_DISCOVERY static commandResult_t CMD_ScheduleHADiscovery(const void* context, const char* cmd, const char* args, int cmdFlags) { int delay; @@ -230,6 +230,7 @@ static commandResult_t CMD_ScheduleHADiscovery(const void* context, const char* return CMD_RES_OK; } +#endif static commandResult_t CMD_SetFlag(const void* context, const char* cmd, const char* args, int cmdFlags) { int flag, val; @@ -362,6 +363,7 @@ static commandResult_t CMD_StartupCommand(const void* context, const char* cmd, // so we know arguments count in Tokenizer. 'cmd' argument is // only for warning display if (Tokenizer_CheckArgsCountAndPrintWarning(cmd, 1)) { + ADDLOG_INFO(LOG_FEATURE_CMD, "Cmd is %s",g_cfg.initCommandLine); return CMD_RES_NOT_ENOUGH_ARGUMENTS; } cmdToSet = Tokenizer_GetArg(0); @@ -799,11 +801,13 @@ void CMD_Init_Early() { //cmddetail:"fn":"CMD_HTTPOTA","file":"cmnds/cmd_main.c","requires":"", //cmddetail:"examples":""} CMD_RegisterCommand("ota_http", CMD_HTTPOTA, NULL); +#if ENABLE_HA_DISCOVERY //cmddetail:{"name":"scheduleHADiscovery","args":"[Seconds]", //cmddetail:"descr":"This will schedule HA discovery, the discovery will happen with given number of seconds, but timer only counts when MQTT is connected. It will not work without MQTT online, so you must set MQTT credentials first.", //cmddetail:"fn":"CMD_ScheduleHADiscovery","file":"cmnds/cmd_main.c","requires":"", //cmddetail:"examples":""} CMD_RegisterCommand("scheduleHADiscovery", CMD_ScheduleHADiscovery, NULL); +#endif //cmddetail:{"name":"flags","args":"[IntegerValue]", //cmddetail:"descr":"Sets the device flags", //cmddetail:"fn":"CMD_Flags","file":"cmnds/cmd_main.c","requires":"", @@ -887,9 +891,11 @@ void CMD_Init_Early() { void CMD_Init_Delayed() { +#if ENABLE_TCP_COMMANDLINE if (CFG_HasFlag(OBK_FLAG_CMD_ENABLETCPRAWPUTTYSERVER)) { CMD_StartTCPCommandLine(); } +#endif #if defined(PLATFORM_BEKEN) || defined(WINDOWS) || defined(PLATFORM_BL602) || defined(PLATFORM_ESPIDF) \ || defined(PLATFORM_RTL87X0C) UART_AddCommands(); diff --git a/src/cmnds/cmd_newLEDDriver.c b/src/cmnds/cmd_newLEDDriver.c index 9adade1f5..a383a1ce6 100644 --- a/src/cmnds/cmd_newLEDDriver.c +++ b/src/cmnds/cmd_newLEDDriver.c @@ -1,9 +1,12 @@ +#include "../obk_config.h" + +#if ENABLE_LED_BASIC + #include "../logging/logging.h" #include "../new_pins.h" #include "../new_cfg.h" #include "cmd_public.h" -#include "../obk_config.h" #include "../driver/drv_public.h" #include "../driver/drv_local.h" #include "../hal/hal_flashVars.h" @@ -208,25 +211,6 @@ int shouldSendRGB() { } -// One user requested ability to broadcast full RGBCW -static void sendFullRGBCW_IfEnabled() { - char s[16]; - byte c[5]; - - if(CFG_HasFlag(OBK_FLAG_LED_BROADCAST_FULL_RGBCW) == false) { - return; - } - - c[0] = (byte)(finalColors[0]); - c[1] = (byte)(finalColors[1]); - c[2] = (byte)(finalColors[2]); - c[3] = (byte)(finalColors[3]); - c[4] = (byte)(finalColors[4]); - - snprintf(s, sizeof(s),"%02X%02X%02X%02X%02X",c[0],c[1],c[2],c[3],c[4]); - - MQTT_PublishMain_StringString_DeDuped(DEDUP_LED_FINALCOLOR_RGBCW,DEDUP_EXPIRE_TIME,"led_finalcolor_rgbcw",s, 0); -} float led_rawLerpCurrent[5] = { 0 }; float Mathf_MoveTowards(float cur, float tg, float dt) { @@ -444,6 +428,85 @@ float led_gamma_correction (int color, float iVal) { // apply LED gamma and RGB return oVal; } // + +#if ENABLE_MQTT + +OBK_Publish_Result sendColorChange() { + char s[16]; + byte c[3]; + + if (shouldSendRGB() == 0) { + return OBK_PUBLISH_WAS_NOT_REQUIRED; + } + + c[0] = (byte)(led_baseColors[0]); + c[1] = (byte)(led_baseColors[1]); + c[2] = (byte)(led_baseColors[2]); + + snprintf(s, sizeof(s), "%02X%02X%02X", c[0], c[1], c[2]); + + return MQTT_PublishMain_StringString_DeDuped(DEDUP_LED_BASECOLOR_RGB, DEDUP_EXPIRE_TIME, "led_basecolor_rgb", s, 0); +} +// One user requested ability to broadcast full RGBCW +static void sendFullRGBCW_IfEnabled() { + char s[16]; + byte c[5]; + + if (CFG_HasFlag(OBK_FLAG_LED_BROADCAST_FULL_RGBCW) == false) { + return; + } + + c[0] = (byte)(finalColors[0]); + c[1] = (byte)(finalColors[1]); + c[2] = (byte)(finalColors[2]); + c[3] = (byte)(finalColors[3]); + c[4] = (byte)(finalColors[4]); + + snprintf(s, sizeof(s), "%02X%02X%02X%02X%02X", c[0], c[1], c[2], c[3], c[4]); + + MQTT_PublishMain_StringString_DeDuped(DEDUP_LED_FINALCOLOR_RGBCW, DEDUP_EXPIRE_TIME, "led_finalcolor_rgbcw", s, 0); +} +OBK_Publish_Result LED_SendEnableAllState() { + return MQTT_PublishMain_StringInt_DeDuped(DEDUP_LED_ENABLEALL, DEDUP_EXPIRE_TIME, "led_enableAll", g_lightEnableAll, 0); +} +OBK_Publish_Result LED_SendCurrentLightModeParam_TempOrColor() { + + if (g_lightMode == Light_Temperature) { + return sendTemperatureChange(); + } + else if (g_lightMode == Light_RGB) { + return sendColorChange(); + } + return OBK_PUBLISH_WAS_NOT_REQUIRED; +} +OBK_Publish_Result sendFinalColor() { + char s[16]; + byte c[3]; + + if (shouldSendRGB() == 0) { + return OBK_PUBLISH_WAS_NOT_REQUIRED; + } + + c[0] = (byte)(finalColors[0]); + c[1] = (byte)(finalColors[1]); + c[2] = (byte)(finalColors[2]); + + snprintf(s, sizeof(s), "%02X%02X%02X", c[0], c[1], c[2]); + + return MQTT_PublishMain_StringString_DeDuped(DEDUP_LED_FINALCOLOR_RGB, DEDUP_EXPIRE_TIME, "led_finalcolor_rgb", s, 0); +} +OBK_Publish_Result LED_SendDimmerChange() { + int iValue; + + iValue = g_brightness0to100; + + return MQTT_PublishMain_StringInt_DeDuped(DEDUP_LED_DIMMER, DEDUP_EXPIRE_TIME, "led_dimmer", iValue, 0); +} +OBK_Publish_Result sendTemperatureChange() { + return MQTT_PublishMain_StringInt_DeDuped(DEDUP_LED_TEMPERATURE, DEDUP_EXPIRE_TIME, "led_temperature", (int)led_temperature_current, 0); +} +#endif + void LED_SaveStateToFlashVarsNow() { HAL_FlashVars_SaveLED(g_lightMode, g_brightness0to100, led_temperature_current, led_baseColors[0], led_baseColors[1], led_baseColors[2], g_lightEnableAll); } @@ -599,7 +662,9 @@ void apply_smart_light() { // I am not sure if it's the best place to do it // NOTE: this will broadcast MQTT only if a flag is set +#if ENABLE_MQTT sendFullRGBCW_IfEnabled(); +#endif } void led_gamma_list (void) { // list RGB gamma settings @@ -691,22 +756,7 @@ commandResult_t led_gamma_control (const void *context, const char *cmd, const c return CMD_RES_OK; } // -OBK_Publish_Result sendColorChange() { - char s[16]; - byte c[3]; - if(shouldSendRGB()==0) { - return OBK_PUBLISH_WAS_NOT_REQUIRED; - } - - c[0] = (byte)(led_baseColors[0]); - c[1] = (byte)(led_baseColors[1]); - c[2] = (byte)(led_baseColors[2]); - - snprintf(s, sizeof(s), "%02X%02X%02X",c[0],c[1],c[2]); - - return MQTT_PublishMain_StringString_DeDuped(DEDUP_LED_BASECOLOR_RGB,DEDUP_EXPIRE_TIME,"led_basecolor_rgb",s, 0); -} void LED_GetBaseColorString(char * s) { byte c[3]; @@ -716,32 +766,6 @@ void LED_GetBaseColorString(char * s) { sprintf(s, "%02X%02X%02X",c[0],c[1],c[2]); } -OBK_Publish_Result sendFinalColor() { - char s[16]; - byte c[3]; - - if(shouldSendRGB()==0) { - return OBK_PUBLISH_WAS_NOT_REQUIRED; - } - - c[0] = (byte)(finalColors[0]); - c[1] = (byte)(finalColors[1]); - c[2] = (byte)(finalColors[2]); - - snprintf(s, sizeof(s),"%02X%02X%02X",c[0],c[1],c[2]); - - return MQTT_PublishMain_StringString_DeDuped(DEDUP_LED_FINALCOLOR_RGB,DEDUP_EXPIRE_TIME,"led_finalcolor_rgb",s, 0); -} -OBK_Publish_Result LED_SendDimmerChange() { - int iValue; - - iValue = g_brightness0to100; - - return MQTT_PublishMain_StringInt_DeDuped(DEDUP_LED_DIMMER,DEDUP_EXPIRE_TIME,"led_dimmer", iValue, 0); -} -OBK_Publish_Result sendTemperatureChange(){ - return MQTT_PublishMain_StringInt_DeDuped(DEDUP_LED_TEMPERATURE,DEDUP_EXPIRE_TIME,"led_temperature", (int)led_temperature_current,0); -} float LED_GetTemperature() { return led_temperature_current; } @@ -778,19 +802,12 @@ void LED_SetBaseColorByIndex(int i, float f, bool bApply) { // set g_lightMode SET_LightMode(Light_RGB); +#if ENABLE_MQTT sendColorChange(); +#endif apply_smart_light(); } } -OBK_Publish_Result LED_SendCurrentLightModeParam_TempOrColor() { - - if(g_lightMode == Light_Temperature) { - return sendTemperatureChange(); - } else if(g_lightMode == Light_RGB) { - return sendColorChange(); - } - return OBK_PUBLISH_WAS_NOT_REQUIRED; -} void LED_SetTemperature0to1Range(float f) { led_temperature_current = led_temperature_min + (led_temperature_max-led_temperature_min) * f; } @@ -824,7 +841,9 @@ void LED_SetTemperature(int tmpInteger, bool bApply) { // set g_lightMode SET_LightMode(Light_Temperature); +#if ENABLE_MQTT sendTemperatureChange(); +#endif apply_smart_light(); } @@ -846,10 +865,6 @@ static commandResult_t temperature(const void *context, const char *cmd, const c //} //return 0; } -OBK_Publish_Result LED_SendEnableAllState() { - return MQTT_PublishMain_StringInt_DeDuped(DEDUP_LED_ENABLEALL,DEDUP_EXPIRE_TIME,"led_enableAll",g_lightEnableAll,0); -} - void LED_ToggleEnabled() { LED_SetEnableAll(!g_lightEnableAll); } @@ -887,6 +902,7 @@ void LED_SetEnableAll(int bEnable) { #if ENABLE_TASMOTADEVICEGROUPS DRV_DGR_OnLedEnableAllChange(bEnable); #endif +#if ENABLE_MQTT LED_SendEnableAllState(); if (bEnableAllWasSetTo1) { // if enable all was set to 1 this frame, also send dimmer @@ -894,6 +910,7 @@ void LED_SetEnableAll(int bEnable) { // TODO: check if it's OK LED_SendDimmerChange(); } +#endif } int LED_GetEnableAll() { return g_lightEnableAll; @@ -1070,6 +1087,7 @@ void LED_SetDimmer(int iVal) { #endif apply_smart_light(); +#if ENABLE_MQTT LED_SendDimmerChange(); if(shouldSendRGB()) { @@ -1080,6 +1098,7 @@ void LED_SetDimmer(int iVal) { sendFinalColor(); } } +#endif } static commandResult_t add_temperature(const void *context, const char *cmd, const char *args, int cmdFlags) { @@ -1241,6 +1260,7 @@ void LED_SetFinalRGB(byte r, byte g, byte b) { apply_smart_light(); +#if ENABLE_MQTT // TODO if(0) { sendColorChange(); @@ -1251,6 +1271,7 @@ void LED_SetFinalRGB(byte r, byte g, byte b) { sendFinalColor(); } } +#endif } static void onHSVChanged() { float r, g, b; @@ -1265,14 +1286,16 @@ static void onHSVChanged() { LED_SetEnableAll(true); } - sendColorChange(); apply_smart_light(); +#if ENABLE_MQTT + sendColorChange(); if (CFG_HasFlag(OBK_FLAG_MQTT_BROADCASTLEDFINALCOLOR)) { sendFinalColor(); } +#endif } commandResult_t LED_SetBaseColor_HSB(const void *context, const char *cmd, const char *args, int bAll) { int hue, sat, bri; @@ -1331,7 +1354,9 @@ commandResult_t LED_SetBaseColor(const void *context, const char *cmd, const cha if (CFG_HasFlag(OBK_FLAG_LED_SETTING_WHITE_RGB_ENABLES_CW)) { if (!stricmp(c, "FFFFFF")) { SET_LightMode(Light_Temperature); +#if ENABLE_MQTT sendTemperatureChange(); +#endif apply_smart_light(); return CMD_RES_OK; } @@ -1392,6 +1417,7 @@ commandResult_t LED_SetBaseColor(const void *context, const char *cmd, const cha LED_SetEnableAll(true); } apply_smart_light(); +#if ENABLE_MQTT sendColorChange(); if(CFG_HasFlag(OBK_FLAG_MQTT_BROADCASTLEDPARAMSTOGETHER)) { LED_SendDimmerChange(); @@ -1399,6 +1425,7 @@ commandResult_t LED_SetBaseColor(const void *context, const char *cmd, const cha if(CFG_HasFlag(OBK_FLAG_MQTT_BROADCASTLEDFINALCOLOR)) { sendFinalColor(); } +#endif return CMD_RES_OK; // } @@ -1766,3 +1793,4 @@ void NewLED_RestoreSavedStateIfNeeded() { // "cmnd/obk8D38570E/led_dimmer_get"" } +#endif diff --git a/src/cmnds/cmd_newLEDDriver_colors.c b/src/cmnds/cmd_newLEDDriver_colors.c index 88dad5e09..7560cb8ef 100644 --- a/src/cmnds/cmd_newLEDDriver_colors.c +++ b/src/cmnds/cmd_newLEDDriver_colors.c @@ -15,6 +15,8 @@ #include "../littlefs/our_lfs.h" #endif +#if ENABLE_LED_BASIC + static byte g_curColor = 0; // TODO: make this list consistent with // Tasmota colors standard: @@ -153,3 +155,7 @@ void LED_NextColor() { LED_SetColorByIndex(g_curColor); } + +#endif + + diff --git a/src/cmnds/cmd_public.h b/src/cmnds/cmd_public.h index deacfdad1..7b5509365 100644 --- a/src/cmnds/cmd_public.h +++ b/src/cmnds/cmd_public.h @@ -198,6 +198,7 @@ int EventHandlers_GetActiveCount(); // cmd_tasmota.c int taslike_commands_init(); // cmd_newLEDDriver.c +#if ENABLE_LED_BASIC void NewLED_InitCommands(); void NewLED_RestoreSavedStateIfNeeded(); float LED_GetDimmer(); @@ -253,6 +254,8 @@ OBK_Publish_Result LED_SendCurrentLightModeParam_TempOrColor(); void LED_ResetGlobalVariablesToDefaults(); extern float led_temperature_min; extern float led_temperature_max; +#endif + // cmd_test.c int CMD_InitTestCommands(); // cmd_channels.c diff --git a/src/cmnds/cmd_send.c b/src/cmnds/cmd_send.c index fee3080e2..a32967e7f 100644 --- a/src/cmnds/cmd_send.c +++ b/src/cmnds/cmd_send.c @@ -4,6 +4,8 @@ #include "../httpclient/http_client.h" #include "cmd_local.h" +#if ENABLE_SEND_POSTANDGET + // SendGet http://192.168.0.112/cm?cmnd=Power0%20Toggle // addRepeatingEvent 5 -1 SendGet http://192.168.0.112/cm?cmnd=Power0%20Toggle // addEventHandler OnClick 8 SendGet http://192.168.0.112/cm?cmnd=Power0%20Toggle @@ -17,12 +19,8 @@ static commandResult_t CMD_SendGET(const void* context, const char* cmd, const c Tokenizer_TokenizeString(args, TOKENIZER_ALLOW_QUOTES | TOKENIZER_ALLOW_ESCAPING_QUOTATIONS); -#if defined(PLATFORM_BEKEN) || defined(WINDOWS) HTTPClient_Async_SendGet(Tokenizer_GetArg(0), Tokenizer_GetArg(1)); -#else - ADDLOG_INFO(LOG_FEATURE_CMD, " CMD_SendGET not supported!"); -#endif return CMD_RES_OK; } // SendPOST http://localhost:3000/ 3000 "application/json" "{ \"a\":123, \"b\":77 }" @@ -31,33 +29,14 @@ static commandResult_t CMD_SendPOST(const void* context, const char* cmd, const Tokenizer_TokenizeString(args, TOKENIZER_ALLOW_QUOTES | TOKENIZER_ALLOW_ESCAPING_QUOTATIONS); -#if defined(PLATFORM_BEKEN) || defined(WINDOWS) HTTPClient_Async_SendPost(Tokenizer_GetArg(0), Tokenizer_GetArgIntegerDefault(1, 80), Tokenizer_GetArg(2), Tokenizer_GetArg(3), Tokenizer_GetArg(4)); -#else - ADDLOG_INFO(LOG_FEATURE_CMD, " CMD_SendPOST not supported!"); -#endif return CMD_RES_OK; } -static commandResult_t CMD_TestPOST(const void* context, const char* cmd, const char* args, int cmdFlags) { - -#if defined(PLATFORM_BEKEN) || defined(WINDOWS) - HTTPClient_Async_SendPost("http://localhost:3000/", - 3000, - "application/json", - "{ \"a\":123, \"b\":77 }", - 0); -#else - ADDLOG_INFO(LOG_FEATURE_CMD, " CMD_SendPOST not supported!"); - -#endif - return CMD_RES_OK; -} - int CMD_InitSendCommands() { //cmddetail:{"name":"sendGet","args":"[TargetURL]", @@ -75,6 +54,8 @@ int CMD_InitSendCommands() { //cmddetail:"examples":""} CMD_RegisterCommand("sendPOST", CMD_SendPOST, NULL); - //CMD_RegisterCommand("testPost", CMD_TestPOST, NULL); return 0; } + +#endif + diff --git a/src/cmnds/cmd_tasmota.c b/src/cmnds/cmd_tasmota.c index f3b4a3474..b020ff196 100644 --- a/src/cmnds/cmd_tasmota.c +++ b/src/cmnds/cmd_tasmota.c @@ -34,10 +34,13 @@ static commandResult_t power(const void *context, const char *cmd, const char *a if (strlen(cmd) > 5) { channel = atoi(cmd+5); +#if ENABLE_LED_BASIC if (LED_IsLEDRunning()) { channel = SPECIAL_CHANNEL_LEDPOWER; } - else { + else +#endif + { if (bRelayIndexingStartsWithZero) { channel--; if (channel < 0) @@ -45,10 +48,13 @@ static commandResult_t power(const void *context, const char *cmd, const char *a } } } else { +#if ENABLE_LED_BASIC // if new LED driver active if(LED_IsLEDRunning()) { channel = SPECIAL_CHANNEL_LEDPOWER; - } else { + } else +#endif + { // find first active channel, because some people index with 0 and some with 1 for(i = 0; i < CHANNEL_MAX; i++) { if (h_isChannelRelay(i) || CHANNEL_GetType(i) == ChType_Toggle) { diff --git a/src/cmnds/cmd_tcp.c b/src/cmnds/cmd_tcp.c index 31d0ff8ee..dbfaf71da 100644 --- a/src/cmnds/cmd_tcp.c +++ b/src/cmnds/cmd_tcp.c @@ -5,6 +5,7 @@ #include #include "cmd_local.h" +#if ENABLE_TCP_COMMANDLINE #define CMD_CLIENT_SLEEP_TIME_MS 50 #define CMD_CLIENT_DISCONNECT_AFTER_IDLE_MS (60 * 1000) @@ -138,3 +139,4 @@ void CMD_StartTCPCommandLine() } +#endif // ENABLE_TCP_COMMANDLINE diff --git a/src/driver/drv_battery.c b/src/driver/drv_battery.c index 84002608d..e9579afc5 100644 --- a/src/driver/drv_battery.c +++ b/src/driver/drv_battery.c @@ -74,8 +74,10 @@ static void Batt_Measure() { if (g_battlevel > 100) g_battlevel = 100; +#if ENABLE_MQTT MQTT_PublishMain_StringInt("voltage", (int)g_battvoltage, 0); MQTT_PublishMain_StringInt("battery", (int)g_battlevel, 0); +#endif g_lastbattlevel = (int)g_battlevel; g_lastbattvoltage = (int)g_battvoltage; ADDLOG_INFO(LOG_FEATURE_DRV, "DRV_BATTERY : battery voltage : %f and percentage %f%%", g_battvoltage, g_battlevel); diff --git a/src/driver/drv_bl0937.c b/src/driver/drv_bl0937.c index d4b5f4388..e2627d4a9 100644 --- a/src/driver/drv_bl0937.c +++ b/src/driver/drv_bl0937.c @@ -1,4 +1,9 @@ #include "drv_bl0937.h" +#include "../obk_config.h" + + +#if ENABLE_DRIVER_BL0937 + //dummy #include @@ -499,3 +504,7 @@ void BL0937_RunEverySecond(void) #endif BL_ProcessUpdate(final_v, final_c, final_p, NAN, NAN); } + +// close ENABLE_DRIVER_BL0937 +#endif + diff --git a/src/driver/drv_bl0942.c b/src/driver/drv_bl0942.c index 21d5f814d..2d1e38f4b 100644 --- a/src/driver/drv_bl0942.c +++ b/src/driver/drv_bl0942.c @@ -1,4 +1,9 @@ #include "drv_bl0942.h" +#include "../obk_config.h" + + + +#if ENABLE_DRIVER_BL0942 #include #include @@ -270,3 +275,7 @@ void BL0942_SPI_RunEverySecond(void) { SPI_ReadReg(BL0942_REG_FREQ, &data.freq); ScaleAndUpdate(&data); } + + +// close ENABLE_DRIVER_BL0942 +#endif diff --git a/src/driver/drv_bl_shared.c b/src/driver/drv_bl_shared.c index da54219c7..7a14083ff 100644 --- a/src/driver/drv_bl_shared.c +++ b/src/driver/drv_bl_shared.c @@ -1,4 +1,7 @@ #include "drv_bl_shared.h" +#include "../obk_config.h" + +#if ENABLE_BL_SHARED #include "../new_cfg.h" #include "../new_pins.h" @@ -572,6 +575,7 @@ void BL_ProcessUpdate(float voltage, float current, float power, sensors[OBK_CONSUMPTION_LAST_HOUR].lastReading += energyCounterMinutes[i]; } } +#if ENABLE_MQTT if ((energyCounterStatsJSONEnable == true) && (MQTT_IsReady() == true)) { root = cJSON_CreateObject(); @@ -632,6 +636,7 @@ void BL_ProcessUpdate(float voltage, float current, float power, stat_updatesSent++; os_free(msg); } +#endif if (energyCounterMinutes != NULL) { @@ -689,6 +694,7 @@ void BL_ProcessUpdate(float voltage, float current, float power, break; } +#if ENABLE_MQTT if (MQTT_IsReady() == true) { sensors[i].lastSentValue = sensors[i].lastReading; @@ -714,6 +720,7 @@ void BL_ProcessUpdate(float voltage, float current, float power, } stat_updatesSent++; } +#endif } else { // no change frame sensors[i].noChangeFrame++; @@ -826,3 +833,6 @@ energySensorNames_t* DRV_GetEnergySensorNames(energySensor_t type) { return &sensors[type].names; } + +#endif + diff --git a/src/driver/drv_bl_shared.h b/src/driver/drv_bl_shared.h index d85eee3c9..b9dbfdaff 100644 --- a/src/driver/drv_bl_shared.h +++ b/src/driver/drv_bl_shared.h @@ -1,9 +1,15 @@ #pragma once #include "../httpserver/new_http.h" +#include "../obk_config.h" + +#if ENABLE_BL_SHARED void BL_Shared_Init(void); void BL_ProcessUpdate(float voltage, float current, float power, float frequency, float energyWh); void BL09XX_AppendInformationToHTTPIndexPage(http_request_t *request); +void BL09XX_SaveEmeteringStatistics(); + +#endif diff --git a/src/driver/drv_cse7766.c b/src/driver/drv_cse7766.c index 750b14e97..acbf4e30d 100644 --- a/src/driver/drv_cse7766.c +++ b/src/driver/drv_cse7766.c @@ -1,6 +1,10 @@ // NOTE: this is the same as HLW8032 #include "drv_cse7766.h" +#include "../obk_config.h" + +#if ENABLE_DRIVER_CSE7766 + #include #include "../logging/logging.h" @@ -217,3 +221,7 @@ void CSE7766_RunEverySecond(void) { CSE7766_TryToGetNextCSE7766Packet(); } + +// close ENABLE_DRIVER_CSE7766 +#endif + diff --git a/src/driver/drv_ddp.c b/src/driver/drv_ddp.c index 3453293cf..c6a77b855 100644 --- a/src/driver/drv_ddp.c +++ b/src/driver/drv_ddp.c @@ -136,6 +136,7 @@ void DDP_Parse(byte *data, int len) { } else #endif { +#if ENABLE_LED_BASIC LED_SetDimmerIfChanged(100); if (data[9] == 4) { LED_SetFinalRGBW(r, g, b, data[13]); @@ -143,6 +144,7 @@ void DDP_Parse(byte *data, int len) { else { LED_SetFinalRGB(r, g, b); } +#endif } } } diff --git a/src/driver/drv_doorSensorWithDeepSleep.c b/src/driver/drv_doorSensorWithDeepSleep.c index 8f28395b9..2afa42b76 100644 --- a/src/driver/drv_doorSensorWithDeepSleep.c +++ b/src/driver/drv_doorSensorWithDeepSleep.c @@ -98,9 +98,11 @@ void DoorDeepSleep_QueueNewEvents() { if (curr_value != g_lastEventState) { g_lastEventState = curr_value; sprintf(sValue, "%i", curr_value); // get the value of the channel +#if ENABLE_MQTT MQTT_QueuePublish(CFG_GetMQTTClientId(), sChannel, sValue, 0); // queue the publishing // Current state (or state change) will be queued and published when device establishes // the connection to WiFi and MQTT Broker (300 seconds by default for that). +#endif } } } @@ -119,7 +121,9 @@ void DoorDeepSleep_OnEverySecond() { } else if (Main_HasMQTTConnected() && Main_HasWiFiConnected()) { // executes every second when connection is established DoorDeepSleep_QueueNewEvents(); +#if ENABLE_MQTT PublishQueuedItems(); // publish those items that were queued when device was offline +#endif g_noChangeTimePassed++; if (g_noChangeTimePassed >= setting_timeRequiredUntilDeepSleep) { diff --git a/src/driver/drv_ds1820_simple.c b/src/driver/drv_ds1820_simple.c index 8bbe02d83..f50a2117b 100644 --- a/src/driver/drv_ds1820_simple.c +++ b/src/driver/drv_ds1820_simple.c @@ -413,7 +413,7 @@ void DS1820_OnEverySecond() // if all is well, it should take 50ms and 100ms // if not, we need to "calibrate" the loop int tempsleep = 5000; - TickType_t actTick = portTICK_RATE_MS * xTaskGetTickCount(); + int actTick = portTICK_RATE_MS * xTaskGetTickCount(); usleepds(tempsleep); int duration = (int)(portTICK_RATE_MS * xTaskGetTickCount() - actTick); diff --git a/src/driver/drv_ir.cpp b/src/driver/drv_ir.cpp index a142bcbc4..13bfc8249 100644 --- a/src/driver/drv_ir.cpp +++ b/src/driver/drv_ir.cpp @@ -1,5 +1,7 @@ -#if PLATFORM_BEKEN +#include "../obk_config.h" + +#if ENABLE_DRIVER_IR extern "C" { // these cause error: conflicting declaration of 'int bk_wlan_mcu_suppress_and_sleep(unsigned int)' with 'C' linkage @@ -806,7 +808,9 @@ extern "C" void DRV_IR_RunFrame(){ //ADDLOG_INFO(LOG_FEATURE_IR, (char *)"IR MQTT publish %s", out); uint32_t counter_in = ir_counter; +#if ENABLE_MQTT MQTT_PublishMain_StringString("ir",out, 0); +#endif uint32_t counter_dur = ((ir_counter - counter_in)*50)/1000; ADDLOG_INFO(LOG_FEATURE_IR, (char *)"IR MQTT publish %s took %dms", out, counter_dur); } else { @@ -816,6 +820,7 @@ extern "C" void DRV_IR_RunFrame(){ ADDLOG_INFO(LOG_FEATURE_IR, (char *)"IR %s", out); } +#if ENABLE_MQTT if (CFG_HasFlag(OBK_FLAG_IR_PUBLISH_RECEIVED_IN_JSON)) { // {"IrReceived":{"Protocol":"RC_5","Bits":0x1,"Data":"0xC"}} // @@ -823,6 +828,7 @@ extern "C" void DRV_IR_RunFrame(){ name, (int)ourReceiver->decodedIRData.numberOfBits, (unsigned long)ourReceiver->decodedIRData.decodedRawData); MQTT_PublishMain_StringString("RESULT", out, OBK_PUBLISH_FLAG_FORCE_REMOVE_GET); } +#endif if(ourReceiver->decodedIRData.protocol != UNKNOWN) { snprintf(out, sizeof(out), "%X", ourReceiver->decodedIRData.command); @@ -904,5 +910,6 @@ void cpptest(){ } #endif -#endif +// close ENABLE_DRIVER_IR +#endif diff --git a/src/driver/drv_main.c b/src/driver/drv_main.c index 05d7b69b0..27bbe2be6 100644 --- a/src/driver/drv_main.c +++ b/src/driver/drv_main.c @@ -110,19 +110,21 @@ static driver_t g_drivers[] = { //drvdetail:"requires":""} { "NTP", NTP_Init, NTP_OnEverySecond, NTP_AppendInformationToHTTPIndexPage, NULL, NULL, NULL, false }, #endif -#if ENABLE_HTTPBUTTONS +#if ENABLE_DRIVER_HTTPBUTTONS //drvdetail:{"name":"HTTPButtons", //drvdetail:"title":"TODO", //drvdetail:"descr":"This driver allows you to create custom, scriptable buttons on main WWW page. You can create those buttons in autoexec.bat and assign commands to them", //drvdetail:"requires":""} { "HTTPButtons", DRV_InitHTTPButtons, NULL, NULL, NULL, NULL, NULL, false }, #endif -#if ENABLE_TEST_DRIVERS +#if ENABLE_DRIVER_TESTPOWER //drvdetail:{"name":"TESTPOWER", //drvdetail:"title":"TODO", //drvdetail:"descr":"This is a fake POWER measuring socket driver, only for testing", //drvdetail:"requires":""} { "TESTPOWER", Test_Power_Init, Test_Power_RunEverySecond, BL09XX_AppendInformationToHTTPIndexPage, NULL, NULL, NULL, false }, +#endif +#if ENABLE_DRIVER_TESTLED //drvdetail:{"name":"TESTLED", //drvdetail:"title":"TODO", //drvdetail:"descr":"This is a fake I2C LED driver, only for testing", @@ -136,7 +138,7 @@ static driver_t g_drivers[] = { //drvdetail:"requires":""} { "I2C", DRV_I2C_Init, DRV_I2C_EverySecond, NULL, NULL, DRV_I2C_Shutdown, NULL, false }, #endif -#if ENABLE_DRIVER_BL0942 +#if ENABLE_DRIVER_RN8209 //drvdetail:{"name":"RN8209", //drvdetail:"title":"TODO", //drvdetail:"descr":"WIP driver for power-metering chip RN8209 found in one of Zmai-90 versions.", @@ -220,7 +222,7 @@ static driver_t g_drivers[] = { //drvdetail:"requires":""} { "SM15155E", SM15155E_Init, NULL, NULL, NULL, NULL, NULL, false }, #endif -#if PLATFORM_BEKEN +#if ENABLE_DRIVER_IR //drvdetail:{"name":"IR", //drvdetail:"title":"TODO", //drvdetail:"descr":"IRLibrary wrapper, so you can receive remote signals and send them. See [forum discussion here](https://www.elektroda.com/rtvforum/topic3920360.html), also see [LED strip and IR YT video](https://www.youtube.com/watch?v=KU0tDwtjfjw)", diff --git a/src/driver/drv_openWeatherMap.c b/src/driver/drv_openWeatherMap.c index 340f1df8d..4b4097a43 100644 --- a/src/driver/drv_openWeatherMap.c +++ b/src/driver/drv_openWeatherMap.c @@ -12,6 +12,7 @@ #include "lwip/sockets.h" #include "lwip/ip_addr.h" #include "lwip/inet.h" +#include "lwip/netdb.h" #include "../cJSON/cJSON.h" #ifndef WINDOWS diff --git a/src/driver/drv_pixelAnim.c b/src/driver/drv_pixelAnim.c index c003cd5dc..92db2b07a 100644 --- a/src/driver/drv_pixelAnim.c +++ b/src/driver/drv_pixelAnim.c @@ -3,6 +3,9 @@ #include "../new_common.h" #include "../new_pins.h" #include "../new_cfg.h" + +#if ENABLE_DRIVER_PIXELANIM + // Commands register, execution API and cmd tokenizer #include "../cmnds/cmd_public.h" #include "../mqtt/new_mqtt.h" @@ -292,3 +295,7 @@ void PixelAnim_SetAnimQuickTick() { } + +//ENABLE_DRIVER_PIXELANIM +#endif + diff --git a/src/driver/drv_public.h b/src/driver/drv_public.h index 8f6d82d4e..0a375e3e0 100644 --- a/src/driver/drv_public.h +++ b/src/driver/drv_public.h @@ -72,7 +72,6 @@ energySensorNames_t* DRV_GetEnergySensorNames(energySensor_t type); bool DRV_IsMeasuringPower(); bool DRV_IsMeasuringBattery(); bool DRV_IsSensor(); -void BL09XX_SaveEmeteringStatistics(); // TuyaMCU exports for LED void TuyaMCU_OnRGBCWChange(const float *rgbcw, int bLightEnableAll, int iLightMode, float brightnessRange01, float temperatureRange01); diff --git a/src/driver/drv_pwmToggler.c b/src/driver/drv_pwmToggler.c index 6405c273d..884d40e7d 100644 --- a/src/driver/drv_pwmToggler.c +++ b/src/driver/drv_pwmToggler.c @@ -96,16 +96,20 @@ static float g_current[MAX_ONOFF_SLOTS]; int parsePowerArgument(const char *s); void publish_enableState(int index) { +#if ENABLE_MQTT char topic[32]; snprintf(topic, sizeof(topic), "toggler_enable%i", index); MQTT_PublishMain_StringInt(topic, g_enabled[index], 0); +#endif } void publish_value(int index) { +#if ENABLE_MQTT char topic[32]; snprintf(topic, sizeof(topic), "toggler_set%i", index); MQTT_PublishMain_StringInt(topic, g_values[index], 0); +#endif } void setTargetChannel(int index) { diff --git a/src/driver/drv_rn8209.c b/src/driver/drv_rn8209.c index e7988ddc8..293a5dcd4 100644 --- a/src/driver/drv_rn8209.c +++ b/src/driver/drv_rn8209.c @@ -3,6 +3,11 @@ // Use this for reference: // https://github.com/RN8209C/RN8209C-SDK/blob/master/src/rn8209c_u.c // Search for rn8209c_read_current + +#include "../obk_config.h" + +#if ENABLE_DRIVER_RN8209 + #include "../logging/logging.h" #include "../new_pins.h" #include "drv_bl_shared.h" @@ -164,3 +169,5 @@ Let's verify checksum (sum modulo 256 and negated): 77 -> 01001101 178 -> 10110010 */ + +#endif diff --git a/src/driver/drv_sm16703P.c b/src/driver/drv_sm16703P.c index 7c6c2ee4e..48cb8c0b4 100644 --- a/src/driver/drv_sm16703P.c +++ b/src/driver/drv_sm16703P.c @@ -155,9 +155,11 @@ void SM16703P_setPixel(int pixel, int r, int g, int b) { } extern float g_brightness0to100;//TODO void SM16703P_setPixelWithBrig(int pixel, int r, int g, int b) { +#if ENABLE_LED_BASIC r = (int)(r * g_brightness0to100*0.01f); g = (int)(g * g_brightness0to100*0.01f); b = (int)(b * g_brightness0to100*0.01f); +#endif SM16703P_setPixel(pixel,r, g, b); } #define SCALE8_PIXEL(x, scale) (uint8_t)(((uint32_t)x * (uint32_t)scale) / 256) diff --git a/src/driver/drv_sm2135.c b/src/driver/drv_sm2135.c index 0d6cfac5f..004d9830f 100644 --- a/src/driver/drv_sm2135.c +++ b/src/driver/drv_sm2135.c @@ -98,7 +98,9 @@ commandResult_t CMD_LEDDriver_WriteRGBCW(const void *context, const char *cmd, c break; } +#if ENABLE_LED_BASIC LED_I2CDriver_WriteRGBCW(col); +#endif return CMD_RES_OK; } diff --git a/src/driver/drv_tasmotaDeviceGroups.c b/src/driver/drv_tasmotaDeviceGroups.c index b629f0fef..be40569c2 100644 --- a/src/driver/drv_tasmotaDeviceGroups.c +++ b/src/driver/drv_tasmotaDeviceGroups.c @@ -325,11 +325,13 @@ void DRV_DGR_CreateSocket_Receive() { addLogAdv(LOG_INFO, LOG_FEATURE_DGR,"DRV_DGR_CreateSocket_Receive: Socket created, waiting for packets\n"); } +#if ENABLE_LED_BASIC void DRV_DGR_processRGBCW(byte *rgbcw) { addLogAdv(LOG_DEBUG, LOG_FEATURE_DGR, "DRV_DGR_setFinalRGBCW: %i,%i,%i,%i,%i\n", (int)rgbcw[0], (int)rgbcw[1], (int)rgbcw[2], (int)rgbcw[3], (int)rgbcw[4]); LED_SetFinalRGBCW(rgbcw); } +#endif void DRV_DGR_processPower(int relayStates, byte relaysCount) { int startIndex; int i; @@ -337,9 +339,12 @@ void DRV_DGR_processPower(int relayStates, byte relaysCount) { addLogAdv(LOG_DEBUG, LOG_FEATURE_DGR, "DRV_DGR_processPower: cnt %i, val %i\n", (int)relaysCount, relayStates); +#if ENABLE_LED_BASIC if(PIN_CountPinsWithRoleOrRole(IOR_PWM,IOR_PWM_n) > 0 || LED_IsLedDriverChipRunning()) { LED_SetEnableAll(BIT_CHECK(relayStates,0)); - } else { + } else +#endif + { // does indexing starts with zero? if(CHANNEL_HasChannelPinWithRoleOrRole(0, IOR_Relay, IOR_Relay_n)) { startIndex = 0; @@ -362,6 +367,7 @@ void DRV_DGR_processPower(int relayStates, byte relaysCount) { } } } +#if ENABLE_LED_BASIC void DRV_DGR_processBrightnessPowerOn(byte brightness) { addLogAdv(LOG_DEBUG, LOG_FEATURE_DGR,"DRV_DGR_processBrightnessPowerOn: %i\n",(int)brightness); @@ -377,6 +383,7 @@ void DRV_DGR_processLightBrightness(byte brightness) { LED_SetDimmer(Val255ToVal100(brightness)); } +#endif typedef struct dgrMmember_s { int ip; uint16_t lastSeq; @@ -472,11 +479,13 @@ void DGR_ProcessIncomingPacket(char *msgbuf, int nbytes) { strcpy(def.gr.groupName, CFG_DeviceGroups_GetName()); def.gr.devGroupShare_In = CFG_DeviceGroups_GetRecvFlags(); def.gr.devGroupShare_Out = CFG_DeviceGroups_GetSendFlags(); +#if ENABLE_LED_BASIC def.cbs.processBrightnessPowerOn = DRV_DGR_processBrightnessPowerOn; def.cbs.processLightBrightness = DRV_DGR_processLightBrightness; def.cbs.processLightFixedColor = DRV_DGR_processLightFixedColor; - def.cbs.processPower = DRV_DGR_processPower; def.cbs.processRGBCW = DRV_DGR_processRGBCW; +#endif + def.cbs.processPower = DRV_DGR_processPower; def.cbs.checkSequence = DGR_CheckSequence; // don't send things that result from something we rxed... diff --git a/src/driver/drv_test_drivers.c b/src/driver/drv_test_drivers.c index 4b15b4422..659344920 100644 --- a/src/driver/drv_test_drivers.c +++ b/src/driver/drv_test_drivers.c @@ -1,8 +1,12 @@ #include "drv_test_drivers.h" +#include "../obk_config.h" + #include #include "../cmnds/cmd_public.h" + +#if ENABLE_DRIVER_TESTPOWER #include "drv_bl_shared.h" static float base_v = 120; @@ -50,6 +54,7 @@ void Test_Power_RunEverySecond(void) { } BL_ProcessUpdate(final_v, final_c, final_p, NAN, NAN); } +#endif //Test LED driver void Test_LED_Driver_Init(void) {} diff --git a/src/driver/drv_tuyaMCU.c b/src/driver/drv_tuyaMCU.c index 337a2e80c..083260bc7 100644 --- a/src/driver/drv_tuyaMCU.c +++ b/src/driver/drv_tuyaMCU.c @@ -1067,6 +1067,7 @@ void TuyaMCU_SendNetworkStatus() TuyaMCU_SendCommandWithData(0x2B, &state, 1); } void TuyaMCU_ForcePublishChannelValues() { +#if ENABLE_MQTT tuyaMCUMapping_t* cur; cur = g_tuyaMappings; @@ -1074,6 +1075,7 @@ void TuyaMCU_ForcePublishChannelValues() { MQTT_ChannelPublish(cur->channel, 0); cur = cur->next; } +#endif } // ntp_timeZoneOfs 2 // addRepeatingEvent 10 -1 uartSendHex 55AA0008000007 @@ -1090,6 +1092,7 @@ void TuyaMCU_ApplyMapping(tuyaMCUMapping_t* mapping, int dpID, int value) { int mappedValue = value; // hardcoded values +#if ENABLE_LED_BASIC if (dpID == g_tuyaMCUled_id_power) { LED_SetEnableAll(value); } @@ -1101,7 +1104,7 @@ void TuyaMCU_ApplyMapping(tuyaMCUMapping_t* mapping, int dpID, int value) { // TuyaMCU sends in 0-1000 range, we need 0-100 LED_SetDimmerForDisplayOnly(value*0.1f); } - +#endif if (mapping == 0) { addLogAdv(LOG_DEBUG, LOG_FEATURE_TUYAMCU, "ApplyMapping: id %i (val %i) not mapped\n", dpID, value); @@ -1504,7 +1507,9 @@ void TuyaMCU_PublishDPToMQTT(const byte *data, int ofs) { if (*s == 0) return; +#if ENABLE_MQTT MQTT_PublishMain_StringString(sName, s, OBK_PUBLISH_FLAG_FORCE_REMOVE_GET); +#endif } void TuyaMCU_ParseStateMessage(const byte* data, int len) { tuyaMCUMapping_t* mapping; diff --git a/src/driver/drv_wemo.c b/src/driver/drv_wemo.c index 0b9921e16..0e48c46f0 100644 --- a/src/driver/drv_wemo.c +++ b/src/driver/drv_wemo.c @@ -200,10 +200,13 @@ void WEMO_AppendInformationToHTTPIndexPage(http_request_t* request) { bool Main_GetFirstPowerState() { int i; +#if ENABLE_LED_BASIC if (LED_IsLEDRunning()) { return LED_GetEnableAll(); } - else { + else +#endif + { // relays driver for (i = 0; i < CHANNEL_MAX; i++) { if (h_isChannelRelay(i) || CHANNEL_GetType(i) == ChType_Toggle) { diff --git a/src/hal/bk7231/hal_main_bk7231.c b/src/hal/bk7231/hal_main_bk7231.c index 08d6c76a9..09b2bdb6d 100644 --- a/src/hal/bk7231/hal_main_bk7231.c +++ b/src/hal/bk7231/hal_main_bk7231.c @@ -98,7 +98,9 @@ void OBK_TriggerButtonPoll(){ void process_oneshot_timer(void *a, void*b){ // if mqtt process incomming data requested if (g_timer_triggers & ONESHOT_MQTT_PROCESS){ +#if ENABLE_MQTT MQTT_process_received(); +#endif g_timer_triggers &= ~ONESHOT_MQTT_PROCESS; } diff --git a/src/hal/w800/hal_pins_w800.c b/src/hal/w800/hal_pins_w800.c index 0f90f23c6..cc885429b 100644 --- a/src/hal/w800/hal_pins_w800.c +++ b/src/hal/w800/hal_pins_w800.c @@ -33,17 +33,17 @@ static wmPin_t g_pins[] = { {"PA13",WM_IO_PA_13, -1}, {"PA14",WM_IO_PA_14, -1}, {"PA15",WM_IO_PA_15, -1}, - {"PB0",WM_IO_PB_00, 0}, - {"PB1",WM_IO_PB_01, 1}, - {"PB2",WM_IO_PB_02, 2}, + {"PB0",WM_IO_PB_00, 0}, // 16 + {"PB1",WM_IO_PB_01, 1}, // 17 + {"PB2",WM_IO_PB_02, 2}, // 18 {"PB3",WM_IO_PB_03, 3}, - {"PB4",WM_IO_PB_04, -1}, + {"PB4",WM_IO_PB_04, -1}, // 20 {"PB5",WM_IO_PB_05, -1}, - {"PB6",WM_IO_PB_06, -1}, + {"PB6",WM_IO_PB_06, -1}, // 22 {"PB7",WM_IO_PB_07, -1}, - {"PB8",WM_IO_PB_08, -1}, - {"PB9",WM_IO_PB_09, -1}, + {"PB8",WM_IO_PB_08, -1}, // 24 + {"PB9",WM_IO_PB_09, -1}, // 25 {"PB10",WM_IO_PB_10, -1}, {"PB11",WM_IO_PB_11, -1}, {"PB12",WM_IO_PB_12, -1}, diff --git a/src/httpclient/http_client.c b/src/httpclient/http_client.c index 1dbb6e077..e00f115a7 100644 --- a/src/httpclient/http_client.c +++ b/src/httpclient/http_client.c @@ -7,6 +7,7 @@ */ #include "../new_common.h" +#include "../obk_config.h" #include "../cmnds/cmd_public.h" #include "include.h" #include "utils_timer.h" @@ -15,6 +16,8 @@ #include "rtos_pub.h" #include "../logging/logging.h" +#if ENABLE_SEND_POSTANDGET + #include "iot_export_errno.h" #define log_err(a, ...) @@ -1321,3 +1324,6 @@ int HTTPClient_Async_SendPost(const char *url_in, int http_port, const char *con return 0; } + +#endif // ENABLE_SEND_POSTANDGET + diff --git a/src/httpclient/http_client.h b/src/httpclient/http_client.h index 848017006..e286d52b6 100644 --- a/src/httpclient/http_client.h +++ b/src/httpclient/http_client.h @@ -5,6 +5,10 @@ #ifndef _UTILS_HTTPC_H_ #define _UTILS_HTTPC_H_ +#include "../obk_config.h" + +#if ENABLE_SEND_POSTANDGET + #include "utils_net.h" #ifdef __cplusplus @@ -165,5 +169,7 @@ void HTTPClient_SetCustomHeader(httpclient_t *client, const char *header); } #endif +#endif /* ENABLE_SEND_POSTANDGET */ + #endif /* __HTTPCLIENT_H__ */ diff --git a/src/httpclient/utils_net.h b/src/httpclient/utils_net.h index f17b93188..905a77115 100644 --- a/src/httpclient/utils_net.h +++ b/src/httpclient/utils_net.h @@ -3,9 +3,6 @@ */ #ifndef _UTILS_NET_H_ #define _UTILS_NET_H_ -#ifndef PLATFORM_BL602 -#include "flash_pub.h" -#endif /** * @brief The structure of network connection(TCP or SSL). diff --git a/src/httpserver/hass.c b/src/httpserver/hass.c index 31741130f..e3136df4d 100644 --- a/src/httpserver/hass.c +++ b/src/httpserver/hass.c @@ -6,6 +6,8 @@ #include "../driver/drv_public.h" #include "../new_pins.h" +#if ENABLE_HA_DISCOVERY + /* Abbreviated node names - https://www.home-assistant.io/docs/mqtt/discovery/ Light - https://www.home-assistant.io/integrations/light.mqtt/ @@ -367,6 +369,7 @@ HassDeviceInfo* hass_init_relay_device_info(int index, ENTITY_TYPE type, bool bT return info; } +#if ENABLE_LED_BASIC /// @brief Initializes HomeAssistant light device discovery storage. /// @param type /// @return @@ -433,6 +436,7 @@ HassDeviceInfo* hass_init_light_device_info(ENTITY_TYPE type) { return info; } +#endif /// @brief Initializes HomeAssistant binary sensor device discovery storage. /// @param index @@ -758,3 +762,5 @@ void hass_free_device_info(HassDeviceInfo* info) { os_free(info); } + +#endif // ENABLE_HA_DISCOVERY diff --git a/src/httpserver/hass.h b/src/httpserver/hass.h index 8e418a036..53fdee907 100644 --- a/src/httpserver/hass.h +++ b/src/httpserver/hass.h @@ -1,5 +1,9 @@ #include "new_http.h" +#include "../obk_config.h" + +#if ENABLE_HA_DISCOVERY + #include "../cJSON/cJSON.h" #include "../new_pins.h" #include "../mqtt/new_mqtt.h" @@ -128,3 +132,4 @@ const char* hass_build_discovery_json(HassDeviceInfo* info); void hass_free_device_info(HassDeviceInfo* info); char *hass_generate_multiplyAndRound_template(int decimalPlacesForRounding, int decimalPointOffset, int divider); +#endif // ENABLE_HA_DISCOVERY diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index 5166954e4..31fcea2e6 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -208,11 +208,16 @@ int http_fn_index(http_request_t* request) { if (DRV_IsRunning("SM16703P")) { bForceShowRGB = true; } - else + else #endif +#if ENABLE_LED_BASIC if (LED_IsLedDriverChipRunning()) { bForceShowRGBCW = true; } +#else + { + } +#endif } http_setup(request, httpMimeTypeHTML); //Add mimetype regardless of the request @@ -246,6 +251,7 @@ int http_fn_index(http_request_t* request) { hprintf255(request, "

Enabled %s!

", CHANNEL_GetLabel(j)); CHANNEL_Set(j, 255, 1); } +#if ENABLE_LED_BASIC if (http_getArg(request->url, "rgb", tmpA, sizeof(tmpA))) { hprintf255(request, "

Set RGB to %s!

", tmpA); LED_SetBaseColor(0, "led_basecolor", tmpA, 0); @@ -255,7 +261,7 @@ int http_fn_index(http_request_t* request) { LED_SetEnableAll(true); } } - +#endif if (http_getArg(request->url, "off", tmpA, sizeof(tmpA))) { j = atoi(tmpA); hprintf255(request, "

Disabled %s!

", CHANNEL_GetLabel(j)); @@ -273,6 +279,7 @@ int http_fn_index(http_request_t* request) { } CHANNEL_Set(j, newPWMValue, 1); +#if ENABLE_LED_BASIC if (j == SPECIAL_CHANNEL_TEMPERATURE) { // auto enable - but only for changes made from WWW panel // This happens when users changes TEMPERATURE @@ -280,6 +287,7 @@ int http_fn_index(http_request_t* request) { LED_SetEnableAll(true); } } +#endif } if (http_getArg(request->url, "dim", tmpA, sizeof(tmpA))) { int newDimmerValue = atoi(tmpA); @@ -293,6 +301,7 @@ int http_fn_index(http_request_t* request) { } CHANNEL_Set(j, newDimmerValue, 1); +#if ENABLE_LED_BASIC if (j == SPECIAL_CHANNEL_BRIGHTNESS) { // auto enable - but only for changes made from WWW panel // This happens when users changes DIMMER @@ -300,6 +309,7 @@ int http_fn_index(http_request_t* request) { LED_SetEnableAll(true); } } +#endif } if (http_getArg(request->url, "set", tmpA, sizeof(tmpA))) { int newSetValue = atoi(tmpA); @@ -615,6 +625,7 @@ int http_fn_index(http_request_t* request) { } } +#if ENABLE_LED_BASIC if (bRawPWMs == 0 || bForceShowRGBCW || bForceShowRGB) { int c_pwms; int lm; @@ -722,6 +733,7 @@ int http_fn_index(http_request_t* request) { } } +#endif #if defined(PLATFORM_BEKEN) || defined(WINDOWS) if (DRV_IsRunning("PWMToggler")) { DRV_Toggler_AddToHtmlPage(request); @@ -790,6 +802,7 @@ int http_fn_index(http_request_t* request) { hprintf255(request, "
Chip temperature: %.1f°C
", g_wifi_temperature); #endif +#if ENABLE_PING_WATCHDOG inputName = CFG_GetPingHost(); if (inputName && *inputName && CFG_GetPingDisconnectedSecondsToRestart()) { hprintf255(request, "
Ping watchdog (%s) - ", inputName); @@ -801,6 +814,7 @@ int http_fn_index(http_request_t* request) { PingWatchDog_GetTotalLost(), PingWatchDog_GetTotalReceived(), g_timeSinceLastPingReply); } } +#endif if (Main_HasWiFiConnected()) { int rssi = HAL_GetWifiStrength(); @@ -893,6 +907,7 @@ typedef enum { hprintf255(request, "
Reboot reason: %i - %s
", reset_reason, s); hprintf255(request, "
Current fw: FW%i
", current_fw_idx); #endif +#if ENABLE_MQTT if (CFG_GetMQTTHost()[0] == 0) { hprintf255(request, "
MQTT State: not configured
"); } @@ -917,6 +932,7 @@ typedef enum { hprintf255(request, "MQTT Stats:CONN: %d PUB: %d RECV: %d ERR: %d
", MQTT_GetConnectEvents(), MQTT_GetPublishEventCounter(), MQTT_GetReceivedEventCounter(), MQTT_GetPublishErrorCounter()); } +#endif /* Format current PINS input state for all unused pins */ if (CFG_HasFlag(OBK_FLAG_HTTP_PINMONITOR)) { @@ -1034,7 +1050,45 @@ int http_fn_about(http_request_t* request) { poststr(request, NULL); return 0; } +#if ENABLE_HTTP_MQTT +int http_fn_cfg_mqtt_set(http_request_t* request) { + char tmpA[128]; + http_setup(request, httpMimeTypeHTML); + http_html_start(request, "Saving MQTT"); + + if (http_getArg(request->url, "host", tmpA, sizeof(tmpA))) { + } + // FIX: always set, so people can clear field + CFG_SetMQTTHost(tmpA); + if (http_getArg(request->url, "port", tmpA, sizeof(tmpA))) { + CFG_SetMQTTPort(atoi(tmpA)); + } + if (http_getArg(request->url, "user", tmpA, sizeof(tmpA))) { + CFG_SetMQTTUserName(tmpA); + } + if (http_getArg(request->url, "password", tmpA, sizeof(tmpA))) { + CFG_SetMQTTPass(tmpA); + } + if (http_getArg(request->url, "client", tmpA, sizeof(tmpA))) { + CFG_SetMQTTClientId(tmpA); + } + if (http_getArg(request->url, "group", tmpA, sizeof(tmpA))) { + CFG_SetMQTTGroupTopic(tmpA); + } + + CFG_Save_SetupTimer(); + + poststr(request, "Please wait for module to connect... if there is problem, restart it from Index html page..."); +#if ENABLE_MQTT + g_mqtt_bBaseTopicDirty = 1; +#endif + poststr(request, "
Return to MQTT settings
"); + poststr(request, htmlFooterReturnToCfgOrMainPage); + http_html_end(request); + poststr(request, NULL); + return 0; +} int http_fn_cfg_mqtt(http_request_t* request) { http_setup(request, httpMimeTypeHTML); http_html_start(request, "MQTT"); @@ -1057,7 +1111,8 @@ int http_fn_cfg_mqtt(http_request_t* request) { poststr(request, NULL); return 0; } - +#endif +#if ENABLE_HTTP_IP int http_fn_cfg_ip(http_request_t* request) { char tmp[64]; int g_changes = 0; @@ -1107,45 +1162,9 @@ int http_fn_cfg_ip(http_request_t* request) { poststr(request, NULL); return 0; } +#endif -int http_fn_cfg_mqtt_set(http_request_t* request) { - char tmpA[128]; - http_setup(request, httpMimeTypeHTML); - http_html_start(request, "Saving MQTT"); - - if (http_getArg(request->url, "host", tmpA, sizeof(tmpA))) { - } - // FIX: always set, so people can clear field - CFG_SetMQTTHost(tmpA); - if (http_getArg(request->url, "port", tmpA, sizeof(tmpA))) { - CFG_SetMQTTPort(atoi(tmpA)); - } - if (http_getArg(request->url, "user", tmpA, sizeof(tmpA))) { - CFG_SetMQTTUserName(tmpA); - } - if (http_getArg(request->url, "password", tmpA, sizeof(tmpA))) { - CFG_SetMQTTPass(tmpA); - } - if (http_getArg(request->url, "client", tmpA, sizeof(tmpA))) { - CFG_SetMQTTClientId(tmpA); - } - if (http_getArg(request->url, "group", tmpA, sizeof(tmpA))) { - CFG_SetMQTTGroupTopic(tmpA); - } - - CFG_Save_SetupTimer(); - - poststr(request, "Please wait for module to connect... if there is problem, restart it from Index html page..."); - - g_mqtt_bBaseTopicDirty = 1; - - poststr(request, "
Return to MQTT settings
"); - poststr(request, htmlFooterReturnToCfgOrMainPage); - http_html_end(request); - poststr(request, NULL); - return 0; -} - +#if ENABLE_HTTP_WEBAPP int http_fn_cfg_webapp(http_request_t* request) { http_setup(request, httpMimeTypeHTML); http_html_start(request, "Set Webapp"); @@ -1177,11 +1196,12 @@ int http_fn_cfg_webapp_set(http_request_t* request) { poststr(request, NULL); return 0; } +#endif - +#if ENABLE_HTTP_PING int http_fn_cfg_ping(http_request_t* request) { char tmpA[128]; int bChanged; @@ -1238,6 +1258,7 @@ int http_fn_cfg_ping(http_request_t* request) { poststr(request, NULL); return 0; } +#endif int http_fn_cfg_wifi(http_request_t* request) { // for a test, show password as well... char tmpA[128]; @@ -1367,6 +1388,7 @@ int http_fn_cfg_wifi(http_request_t* request) { poststr(request, NULL); return 0; } +#if ENABLE_HTTP_NAMES int http_fn_cfg_name(http_request_t* request) { // for a test, show password as well... char tmpA[128]; @@ -1404,7 +1426,7 @@ int http_fn_cfg_name(http_request_t* request) { poststr(request, NULL); return 0; } - +#endif int http_fn_cfg_wifi_set(http_request_t* request) { char tmpA[128]; int bChanged; @@ -1495,7 +1517,7 @@ int http_fn_cfg_loglevel_set(http_request_t* request) { return 0; } - +#if ENABLE_HTTP_MAC int http_fn_cfg_mac(http_request_t* request) { // must be unsigned, else print below prints negatives as e.g. FFFFFFFe unsigned char mac[6]; @@ -1535,97 +1557,8 @@ int http_fn_cfg_mac(http_request_t* request) { poststr(request, NULL); return 0; } -// -//int http_fn_flash_read_tool(http_request_t* request) { -// int len = 16; -// int ofs = 1970176; -// int res; -// int rem; -// int now; -// int nowOfs; -// int hex; -// int i; -// char tmpA[128]; -// char tmpB[64]; -// -// http_setup(request, httpMimeTypeHTML); -// http_html_start(request, "Flash read"); -// poststr_h4(request, "Flash Read Tool"); -// if (http_getArg(request->url, "hex", tmpA, sizeof(tmpA))) { -// hex = atoi(tmpA); -// } -// else { -// hex = 0; -// } -// -// if (http_getArg(request->url, "offset", tmpA, sizeof(tmpA)) && -// http_getArg(request->url, "len", tmpB, sizeof(tmpB))) { -// unsigned char buffer[128]; -// len = atoi(tmpB); -// ofs = atoi(tmpA); -// hprintf255(request, "Memory at %i with len %i reads: ", ofs, len); -// poststr(request, "
"); -// -// ///res = bekken_hal_flash_read (ofs, buffer,len); -// //sprintf(tmpA,"Result %i",res); -// // strcat(outbuf,tmpA); -// /// strcat(outbuf,"
"); -// -// nowOfs = ofs; -// rem = len; -// while (1) { -// if (rem > sizeof(buffer)) { -// now = sizeof(buffer); -// } -// else { -// now = rem; -// } -//#if PLATFORM_XR809 -// //uint32_t flash_read(uint32_t flash, uint32_t addr,void *buf, uint32_t size) -//#define FLASH_INDEX_XR809 0 -// res = flash_read(FLASH_INDEX_XR809, nowOfs, buffer, now); -//#elif PLATFORM_BL602 -// -//#elif PLATFORM_W600 || PLATFORM_W800 -// -//#else -// res = bekken_hal_flash_read(nowOfs, buffer, now); -//#endif -// for (i = 0; i < now; i++) { -// unsigned char val = buffer[i]; -// if (!hex && isprint(val)) { -// hprintf255(request, "'%c' ", val); -// } -// else { -// hprintf255(request, "%02X ", val); -// } -// } -// rem -= now; -// nowOfs += now; -// if (rem <= 0) { -// break; -// } -// } -// -// poststr(request, "
"); -// } -// poststr(request, "
"); -// -// poststr(request, "
"); -// -// add_label_numeric_field(request, "Offset", "offset", ofs, ""); -// add_label_numeric_field(request, "Length", "len", len, "
"); -// poststr(request, SUBMIT_AND_END_FORM); -// -// poststr(request, htmlFooterReturnToCfgOrMainPage); -// http_html_end(request); -// poststr(request, NULL); -// return 0; -//} +#endif + const char* CMD_GetResultString(commandResult_t r) { if (r == CMD_RES_OK) return "OK"; @@ -1693,6 +1626,7 @@ int http_fn_cmd_tool(http_request_t* request) { return 0; } +#if ENABLE_HTTP_STARTUP int http_fn_startup_command(http_request_t* request) { char tmpA[512]; http_setup(request, httpMimeTypeHTML); @@ -1721,7 +1655,9 @@ int http_fn_startup_command(http_request_t* request) { poststr(request, NULL); return 0; } +#endif +#if ENABLE_HA_DISCOVERY void doHomeAssistantDiscovery(const char* topic, http_request_t* request) { int i; int relayCount; @@ -1762,7 +1698,11 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) { PIN_get_Relay_PWM_Count(&relayCount, &pwmCount, &dInputCount); addLogAdv(LOG_INFO, LOG_FEATURE_HTTP, "HASS counts: %i rels, %i pwms, %i inps, %i excluded", relayCount, pwmCount, dInputCount, excludedCount); +#if ENABLE_LED_BASIC ledDriverChipRunning = LED_IsLedDriverChipRunning(); +#else + ledDriverChipRunning = 0; +#endif hooks.malloc_fn = os_malloc; hooks.free_fn = os_free; @@ -1825,6 +1765,7 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) { #endif +#if ENABLE_LED_BASIC if (pwmCount == 5 || ledDriverChipRunning || (pwmCount == 4 && CFG_HasFlag(OBK_FLAG_LED_EMULATE_COOL_WITH_RGB))) { if (dev_info == NULL) { dev_info = hass_init_light_device_info(LIGHT_RGBCW); @@ -1858,6 +1799,7 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) { discoveryQueued = true; } } +#endif #ifdef ENABLE_DRIVER_BL0937 if (measuringPower == true) { @@ -2220,7 +2162,9 @@ int http_fn_ha_discovery(http_request_t* request) { poststr(request, NULL); return 0; } +#endif +#if ENABLE_OLD_YAML_GENERATOR void http_generate_singleColor_cfg(http_request_t* request, const char* clientId) { hprintf255(request, " command_topic: \"cmnd/%s/led_enableAll\"\n", clientId); hprintf255(request, " state_topic: \"%s/led_enableAll/get\"\n", clientId); @@ -2253,6 +2197,8 @@ void hprintf_qos_payload(http_request_t* request, const char* clientId) { hprintf255(request, " availability:\n"); hprintf255(request, " - topic: \"%s/connected\"\n", clientId); } +#endif +#if ENABLE_HA_DISCOVERY int http_fn_ha_cfg(http_request_t* request) { int relayCount; int pwmCount; @@ -2273,6 +2219,7 @@ int http_fn_ha_cfg(http_request_t* request) { http_html_start(request, "Home Assistant Setup"); poststr_h4(request, "Home Assistant Cfg"); hprintf255(request, "

Note that your short device name is: %s

", shortDeviceName); +#if ENABLE_OLD_YAML_GENERATOR poststr_h4(request, "Paste this to configuration yaml"); poststr(request, "
Make sure that you have \"switch:\" keyword only once! Home Assistant doesn't like dup keywords.
"); poststr(request, "
You can also use \"switch MyDeviceName:\" to avoid keyword duplication!
"); @@ -2321,6 +2268,7 @@ int http_fn_ha_cfg(http_request_t* request) { } } } +#if ENABLE_LED_BASIC if (pwmCount == 5 || LED_IsLedDriverChipRunning()) { // Enable + RGB control + CW control if (mqttAdded == 0) { @@ -2416,8 +2364,10 @@ int http_fn_ha_cfg(http_request_t* request) { } } } +#endif poststr(request, ""); +#endif poststr(request, "
 

"); poststr(request, htmlFooterReturnToCfgOrMainPage); http_html_end(request); @@ -2426,6 +2376,8 @@ int http_fn_ha_cfg(http_request_t* request) { return 0; } +#endif + void runHTTPCommandInternal(http_request_t* request, const char *cmd) { bool bEchoHack = strncmp(cmd, "echo", 4) == 0; CMD_ExecuteCommand(cmd, COMMAND_FLAG_SOURCE_HTTP); @@ -2485,21 +2437,40 @@ int http_fn_cfg(http_request_t* request) { http_setup(request, httpMimeTypeHTML); http_html_start(request, "Config"); postFormAction(request, "cfg_pins", "Configure Module"); +#if ENABLE_HTTP_FLAGS postFormAction(request, "cfg_generic", "Configure General/Flags"); +#endif +#if ENABLE_HTTP_STARTUP postFormAction(request, "cfg_startup", "Configure Startup"); +#endif +#if ENABLE_HTTP_DGR postFormAction(request, "cfg_dgr", "Configure Device Groups"); +#endif postFormAction(request, "cfg_wifi", "Configure WiFi & Web"); +#if ENABLE_HTTP_IP postFormAction(request, "cfg_ip", "Configure IP"); +#endif postFormAction(request, "cfg_mqtt", "Configure MQTT"); +#if ENABLE_HTTP_NAMES postFormAction(request, "cfg_name", "Configure Names"); +#endif +#if ENABLE_HTTP_MAC postFormAction(request, "cfg_mac", "Change MAC"); +#endif +#if ENABLE_HTTP_PING postFormAction(request, "cfg_ping", "Ping Watchdog (network lost restarter)"); +#endif +#if ENABLE_HTTP_WEBAPP postFormAction(request, "cfg_webapp", "Configure WebApp"); +#endif +#if ENABLE_HA_DISCOVERY postFormAction(request, "ha_cfg", "Home Assistant Configuration"); +#endif postFormAction(request, "ota", "OTA (update software by WiFi)"); postFormAction(request, "cmd_tool", "Execute Custom Command"); - //postFormAction(request, "flash_read_tool", "Flash Read Tool"); +#if ENABLE_HTTP_STARTUP postFormAction(request, "startup_command", "Change Startup Command Text"); +#endif #if 0 #if PLATFORM_BK7231T | PLATFORM_BK7231N @@ -2598,9 +2569,11 @@ int http_fn_cfg_pins(http_request_t* request) { CFG_Save_IfThereArePendingChanges(); // Invoke Hass discovery if configuration has changed and not in safe mode. +#if ENABLE_HA_DISCOVERY if (!bSafeMode && CFG_HasFlag(OBK_FLAG_AUTOMAIC_HASS_DISCOVERY)) { Main_ScheduleHomeAssistantDiscovery(1); } +#endif hprintf255(request, "Pins update - %i reqs, %i changed!

", iChangedRequested, iChanged); } // strcat(outbuf,""); @@ -2723,6 +2696,7 @@ int http_fn_cfg_pins(http_request_t* request) { return 0; } +#if ENABLE_HTTP_FLAGS 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)", @@ -2850,6 +2824,8 @@ int http_fn_cfg_generic(http_request_t* request) { poststr(request, NULL); return 0; } +#endif +#if ENABLE_HTTP_STARTUP int http_fn_cfg_startup(http_request_t* request) { int channelIndex; int newValue; @@ -2904,7 +2880,8 @@ int http_fn_cfg_startup(http_request_t* request) { poststr(request, NULL); return 0; } - +#endif +#if ENABLE_HTTP_DGR int http_fn_cfg_dgr(http_request_t* request) { char tmpA[128]; bool bForceSet; @@ -3002,6 +2979,7 @@ int http_fn_cfg_dgr(http_request_t* request) { poststr(request, NULL); return 0; } +#endif void XR809_RequestOTAHTTP(const char* s); diff --git a/src/httpserver/json_interface.c b/src/httpserver/json_interface.c index e92a50159..c28546b71 100644 --- a/src/httpserver/json_interface.c +++ b/src/httpserver/json_interface.c @@ -42,6 +42,7 @@ void JSON_PrintKeyValue_Float(void* request, jsonCb_t printer, const char* key, } } +#if ENABLE_LED_BASIC static int http_tasmota_json_Dimmer(void* request, jsonCb_t printer) { int dimmer; dimmer = LED_GetDimmer(); @@ -56,6 +57,7 @@ static int http_tasmota_json_CT(void* request, jsonCb_t printer) { JSON_PrintKeyValue_Int(request, printer, "CT", temperature, false); return 0; } +#endif // https://tasmota.github.io/docs/Commands/#with-mqtt /* http:///cm?cmnd=Power%20TOGGLE @@ -87,6 +89,7 @@ static int http_tasmota_json_power(void* request, jsonCb_t printer) { numPWMs = PIN_CountPinsWithRoleOrRole(IOR_PWM, IOR_PWM_n); numRelays = 0; +#if ENABLE_LED_BASIC // LED driver (if has PWMs) if (LED_IsLEDRunning()) { http_tasmota_json_Dimmer(request, printer); @@ -141,7 +144,9 @@ static int http_tasmota_json_power(void* request, jsonCb_t printer) { JSON_PrintKeyValue_String(request, printer, "POWER", "ON", false); } } - else { + else +#endif + { // relays driver for (i = 0; i < CHANNEL_MAX; i++) { if (h_isChannelRelay(i) || CHANNEL_GetType(i) == ChType_Toggle) { @@ -615,10 +620,14 @@ static int http_tasmota_json_status_generic(void* request, jsonCb_t printer) { PIN_get_Relay_PWM_Count(&relayCount, &pwmCount, &dInputCount); +#if ENABLE_LED_BASIC if (LED_IsLEDRunning()) { powerCode = LED_GetEnableAll(); } - else { + else +#endif + + { powerCode = 0; for (i = 0; i < CHANNEL_MAX; i++) { bool bRelay; @@ -784,13 +793,15 @@ int JSON_ProcessCommandReply(const char* cmd, const char* arg, void* request, js printer(request, "{"); http_tasmota_json_power(request, printer); printer(request, "}"); +#if ENABLE_MQTT if (flags == COMMAND_FLAG_SOURCE_MQTT) { MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "RESULT"); } +#endif } else if (!wal_strnicmp(cmd, "SensorRetain", 12)) { printer(request, "{"); - if (CFG_HasFlag(OBK_PUBLISH_FLAG_RETAIN)) + if (CFG_HasFlag(OBK_FLAG_MQTT_ALWAYSSETRETAIN)) { JSON_PrintKeyValue_String(request, printer, "SensorRetain", "ON", false); } @@ -874,6 +885,7 @@ int JSON_ProcessCommandReply(const char* cmd, const char* arg, void* request, js JSON_PrintKeyValue_String(request, printer, "TelePeriod", "300", false); printer(request, "}"); } +#if ENABLE_LED_BASIC else if (!wal_strnicmp(cmd, "CT", 2)) { printer(request, "{"); if (*arg == 0) { @@ -883,9 +895,11 @@ int JSON_ProcessCommandReply(const char* cmd, const char* arg, void* request, js http_tasmota_json_power(request, printer); } printer(request, "}"); +#if ENABLE_MQTT if (flags == COMMAND_FLAG_SOURCE_MQTT) { MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "RESULT"); } +#endif } else if (!wal_strnicmp(cmd, "Dimmer", 6)) { printer(request, "{"); @@ -896,9 +910,11 @@ int JSON_ProcessCommandReply(const char* cmd, const char* arg, void* request, js http_tasmota_json_power(request, printer); } printer(request, "}"); +#if ENABLE_MQTT if (flags == COMMAND_FLAG_SOURCE_MQTT) { MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "RESULT"); } +#endif } else if (!wal_strnicmp(cmd, "Color", 5) || !wal_strnicmp(cmd, "HsbColor", 8)) { printer(request, "{"); @@ -909,31 +925,39 @@ int JSON_ProcessCommandReply(const char* cmd, const char* arg, void* request, js http_tasmota_json_power(request, printer); //} printer(request, "}"); +#if ENABLE_MQTT if (flags == COMMAND_FLAG_SOURCE_MQTT) { MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "RESULT"); } +#endif } +#endif else if (!wal_strnicmp(cmd, "STATE", 5)) { http_tasmota_json_status_STS(request, printer, false); +#if ENABLE_MQTT if (flags == COMMAND_FLAG_SOURCE_MQTT) { MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "RESULT"); } if (flags == COMMAND_FLAG_SOURCE_TELESENDER) { MQTT_PublishPrinterContentsToTele((struct obk_mqtt_publishReplyPrinter_s*)request, "STATE"); } +#endif } else if (!wal_strnicmp(cmd, "SENSOR", 5)) { // not a Tasmota command, but still required for us http_tasmota_json_status_SNS(request, printer, false); +#if ENABLE_MQTT if (flags == COMMAND_FLAG_SOURCE_TELESENDER) { MQTT_PublishPrinterContentsToTele((struct obk_mqtt_publishReplyPrinter_s*)request, "SENSOR"); } +#endif } else if (!wal_strnicmp(cmd, "STATUS", 6)) { if (!stricmp(arg, "8") || !stricmp(arg, "10")) { printer(request, "{"); http_tasmota_json_status_SNS(request, printer, true); printer(request, "}"); +#if ENABLE_MQTT if (flags == COMMAND_FLAG_SOURCE_MQTT) { if (arg[0] == '8') { MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "STATUS8"); @@ -942,60 +966,75 @@ int JSON_ProcessCommandReply(const char* cmd, const char* arg, void* request, js MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "STATUS10"); } } +#endif } else if (!stricmp(arg, "6")) { printer(request, "{"); http_tasmota_json_status_MQT(request, printer); printer(request, "}"); +#if ENABLE_MQTT if (flags == COMMAND_FLAG_SOURCE_MQTT) { MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "STATUS6"); } +#endif } else if (!stricmp(arg, "7")) { printer(request, "{"); http_tasmota_json_status_TIM(request, printer); printer(request, "}"); +#if ENABLE_MQTT if (flags == COMMAND_FLAG_SOURCE_MQTT) { MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "STATUS7"); } +#endif } else if (!stricmp(arg, "5")) { printer(request, "{"); http_tasmota_json_status_NET(request, printer); printer(request, "}"); +#if ENABLE_MQTT if (flags == COMMAND_FLAG_SOURCE_MQTT) { MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "STATUS5"); } +#endif } else if (!stricmp(arg, "4")) { printer(request, "{"); http_tasmota_json_status_MEM(request, printer); printer(request, "}"); +#if ENABLE_MQTT if (flags == COMMAND_FLAG_SOURCE_MQTT) { MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "STATUS4"); } +#endif } else if (!stricmp(arg, "11")) { printer(request, "{"); http_tasmota_json_status_STS(request, printer, true); printer(request, "}"); +#if ENABLE_MQTT if (flags == COMMAND_FLAG_SOURCE_MQTT) { MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "STATUS11"); } +#endif } else if (!stricmp(arg, "2")) { printer(request, "{"); http_tasmota_json_status_FWR(request, printer); printer(request, "}"); +#if ENABLE_MQTT if (flags == COMMAND_FLAG_SOURCE_MQTT) { MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "STATUS2"); } +#endif } else { http_tasmota_json_status_generic(request, printer); +#if ENABLE_MQTT if (flags == COMMAND_FLAG_SOURCE_MQTT) { MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "STATUS"); } +#endif } } else if (!wal_strnicmp(cmd, "SetChannelType", 14)) { @@ -1012,6 +1051,7 @@ int JSON_ProcessCommandReply(const char* cmd, const char* arg, void* request, js printer(request, "%i", i); } +#if ENABLE_LED_BASIC else if (!wal_strnicmp(cmd, "led_basecolor_rgb", 17)) { // OBK-specific char tmp[16]; @@ -1020,6 +1060,7 @@ int JSON_ProcessCommandReply(const char* cmd, const char* arg, void* request, js JSON_PrintKeyValue_String(request, printer, "led_basecolor_rgb", tmp, false); printer(request, "}"); } +#endif else if (!wal_strnicmp(cmd, "MQTTClient", 8)) { printer(request, "{"); JSON_PrintKeyValue_String(request, printer, "MQTTClient", CFG_GetMQTTClientId(), false); @@ -1071,9 +1112,11 @@ int JSON_ProcessCommandReply(const char* cmd, const char* arg, void* request, js sscanf(cmd + 2, "%i", &id); } http_obk_json_dps(id,request, printer); +#if ENABLE_MQTT if (flags == COMMAND_FLAG_SOURCE_MQTT) { MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "DP"); } +#endif } #endif #endif diff --git a/src/httpserver/new_http.c b/src/httpserver/new_http.c index 3acf246c3..c0552c257 100644 --- a/src/httpserver/new_http.c +++ b/src/httpserver/new_http.c @@ -764,34 +764,56 @@ int HTTP_ProcessPacket(http_request_t* request) { if (http_checkUrlBase(urlStr, "index")) return http_fn_index(request); if (http_checkUrlBase(urlStr, "about")) return http_fn_about(request); - + +#if ENABLE_HTTP_MQTT if (http_checkUrlBase(urlStr, "cfg_mqtt")) return http_fn_cfg_mqtt(request); - if (http_checkUrlBase(urlStr, "cfg_ip")) return http_fn_cfg_ip(request); if (http_checkUrlBase(urlStr, "cfg_mqtt_set")) return http_fn_cfg_mqtt_set(request); +#endif +#if ENABLE_HTTP_IP + if (http_checkUrlBase(urlStr, "cfg_ip")) return http_fn_cfg_ip(request); +#endif +#if ENABLE_HTTP_WEBAPP if (http_checkUrlBase(urlStr, "cfg_webapp")) return http_fn_cfg_webapp(request); if (http_checkUrlBase(urlStr, "cfg_webapp_set")) return http_fn_cfg_webapp_set(request); +#endif if (http_checkUrlBase(urlStr, "cfg_wifi")) return http_fn_cfg_wifi(request); +#if ENABLE_HTTP_NAMES if (http_checkUrlBase(urlStr, "cfg_name")) return http_fn_cfg_name(request); +#endif if (http_checkUrlBase(urlStr, "cfg_wifi_set")) return http_fn_cfg_wifi_set(request); if (http_checkUrlBase(urlStr, "cfg_loglevel_set")) return http_fn_cfg_loglevel_set(request); +#if ENABLE_HTTP_MAC if (http_checkUrlBase(urlStr, "cfg_mac")) return http_fn_cfg_mac(request); - -// if (http_checkUrlBase(urlStr, "flash_read_tool")) return http_fn_flash_read_tool(request); +#endif if (http_checkUrlBase(urlStr, "cmd_tool")) return http_fn_cmd_tool(request); - if (http_checkUrlBase(urlStr, "startup_command")) return http_fn_startup_command(request); - if (http_checkUrlBase(urlStr, "cfg_generic")) return http_fn_cfg_generic(request); - if (http_checkUrlBase(urlStr, "cfg_startup")) return http_fn_cfg_startup(request); - if (http_checkUrlBase(urlStr, "cfg_dgr")) return http_fn_cfg_dgr(request); +#if ENABLE_HTTP_STARTUP + if (http_checkUrlBase(urlStr, "startup_command")) return http_fn_startup_command(request); +#endif +#if ENABLE_HTTP_FLAGS + if (http_checkUrlBase(urlStr, "cfg_generic")) return http_fn_cfg_generic(request); +#endif +#if ENABLE_HTTP_STARTUP + if (http_checkUrlBase(urlStr, "cfg_startup")) return http_fn_cfg_startup(request); +#endif +#if ENABLE_HTTP_DGR + if (http_checkUrlBase(urlStr, "cfg_dgr")) return http_fn_cfg_dgr(request); +#endif + +#if ENABLE_HA_DISCOVERY if (http_checkUrlBase(urlStr, "ha_cfg")) return http_fn_ha_cfg(request); if (http_checkUrlBase(urlStr, "ha_discovery")) return http_fn_ha_discovery(request); +#endif if (http_checkUrlBase(urlStr, "cfg")) return http_fn_cfg(request); if (http_checkUrlBase(urlStr, "cfg_pins")) return http_fn_cfg_pins(request); +#if ENABLE_HTTP_PING if (http_checkUrlBase(urlStr, "cfg_ping")) return http_fn_cfg_ping(request); +#endif + if (http_checkUrlBase(urlStr, "ota")) return http_fn_ota(request); if (http_checkUrlBase(urlStr, "ota_exec")) return http_fn_ota_exec(request); diff --git a/src/i2c/drv_i2c_main.c b/src/i2c/drv_i2c_main.c index 2d65d7b12..b45e78e09 100644 --- a/src/i2c/drv_i2c_main.c +++ b/src/i2c/drv_i2c_main.c @@ -192,6 +192,7 @@ i2cDevice_t *DRV_I2C_FindDeviceExt(int busType,int address, int devType) { // set SoftSDA and SoftSCL pins // startDriver I2C // scanI2C Soft +// backlog startDriver I2C; scanI2C Soft commandResult_t DRV_I2C_Scan(const void *context, const char *cmd, const char *args, int cmdFlags) { const char *i2cModuleStr; i2cBusType_t busType; diff --git a/src/mqtt/new_mqtt.c b/src/mqtt/new_mqtt.c index 6121966fa..fe809a6a9 100644 --- a/src/mqtt/new_mqtt.c +++ b/src/mqtt/new_mqtt.c @@ -1,4 +1,8 @@ +#include "../obk_config.h" + +#if ENABLE_MQTT + #include "new_mqtt.h" #include "../new_common.h" #include "../new_pins.h" @@ -560,7 +564,7 @@ int channelGet(obk_mqtt_request_t* request) { } addLogAdv(LOG_INFO, LOG_FEATURE_MQTT, "channelGet part topic %s", p); - +#if ENABLE_LED_BASIC if (stribegins(p, "led_enableAll")) { LED_SendEnableAllState(); return 1; @@ -581,6 +585,7 @@ int channelGet(obk_mqtt_request_t* request) { sendColorChange(); return 1; } +#endif // atoi won't parse any non-decimal chars, so it should skip over the rest of the topic. channel = atoi(p); @@ -1862,23 +1867,29 @@ OBK_Publish_Result MQTT_DoItemPublish(int idx) case PUBLISHITEM_SELF_DYNAMIC_LIGHTSTATE: { +#if ENABLE_LED_BASIC if (LED_IsLEDRunning()) { return LED_SendEnableAllState(); } +#endif return OBK_PUBLISH_WAS_NOT_REQUIRED; } case PUBLISHITEM_SELF_DYNAMIC_LIGHTMODE: { +#if ENABLE_LED_BASIC if (LED_IsLEDRunning()) { return LED_SendCurrentLightModeParam_TempOrColor(); } +#endif return OBK_PUBLISH_WAS_NOT_REQUIRED; } case PUBLISHITEM_SELF_DYNAMIC_DIMMER: { +#if ENABLE_LED_BASIC if (LED_IsLEDRunning()) { return LED_SendDimmerChange(); } +#endif return OBK_PUBLISH_WAS_NOT_REQUIRED; } @@ -2365,3 +2376,4 @@ bool MQTT_IsReady() { return mqtt_client && res; } +#endif // ENABLE_MQTT diff --git a/src/mqtt/new_mqtt.h b/src/mqtt/new_mqtt.h index a8c8b2c36..0d4936744 100644 --- a/src/mqtt/new_mqtt.h +++ b/src/mqtt/new_mqtt.h @@ -1,6 +1,10 @@ #ifndef __NEW_MQTT_H__ #define __NEW_MQTT_H__ +#include "../obk_config.h" + +#if ENABLE_MQTT + #include "../new_common.h" #include "lwip/sockets.h" @@ -171,5 +175,7 @@ typedef struct obk_mqtt_publishReplyPrinter_s { void MQTT_PublishPrinterContentsToStat(obk_mqtt_publishReplyPrinter_t *printer, const char *statName); void MQTT_PublishPrinterContentsToTele(obk_mqtt_publishReplyPrinter_t *printer, const char *statName); +#endif // ENABLE_MQTT + #endif // __NEW_MQTT_H__ diff --git a/src/mqtt/new_mqtt_deduper.c b/src/mqtt/new_mqtt_deduper.c index 1ef741926..bbe0e2d80 100644 --- a/src/mqtt/new_mqtt_deduper.c +++ b/src/mqtt/new_mqtt_deduper.c @@ -1,5 +1,8 @@ #include "new_mqtt.h" + +#if ENABLE_MQTT + #include "../new_common.h" #include "../new_pins.h" #include "../new_cfg.h" @@ -151,3 +154,5 @@ OBK_Publish_Result MQTT_PublishMain_StringString_DeDuped(int slotCode, int expir stat_deduper_send++; return res; } + +#endif // ENABLE_MQTT diff --git a/src/mqtt/new_mqtt_deduper.h b/src/mqtt/new_mqtt_deduper.h index 2472da7d0..6a4ddf1a8 100644 --- a/src/mqtt/new_mqtt_deduper.h +++ b/src/mqtt/new_mqtt_deduper.h @@ -1,5 +1,11 @@ +#include "../obk_config.h" + + + +#if ENABLE_MQTT + // i didn't choose the "automatic, per string name" approach because it would be slower // I think we only need to dedup the built-in MQTT publishes, which can be listed here and defined as constants typedef enum MQTT_Dedup_Slot_e { @@ -19,3 +25,6 @@ typedef enum MQTT_Dedup_Slot_e { OBK_Publish_Result MQTT_PublishMain_StringString_DeDuped(int slotCode, int expireTime, const char* sChannel, const char* valueStr, int flags); OBK_Publish_Result MQTT_PublishMain_StringInt_DeDuped(int slotCode, int expireTime, const char* sChannel, int val, int flags); void MQTT_Dedup_Tick(); + +#endif + diff --git a/src/new_cfg.c b/src/new_cfg.c index 4f9e2a70f..22b71c672 100644 --- a/src/new_cfg.c +++ b/src/new_cfg.c @@ -430,7 +430,9 @@ void CFG_SetMQTTClientId(const char *s) { if(strcpy_safe_checkForChanges(g_cfg.mqtt_clientId, s,sizeof(g_cfg.mqtt_clientId))) { // mark as dirty (value has changed) g_cfg_pendingChanges++; +#if ENABLE_MQTT g_mqtt_bBaseTopicDirty++; +#endif } } void CFG_SetMQTTGroupTopic(const char *s) { @@ -438,7 +440,9 @@ void CFG_SetMQTTGroupTopic(const char *s) { if (strcpy_safe_checkForChanges(g_cfg.mqtt_group, s, sizeof(g_cfg.mqtt_group))) { // mark as dirty (value has changed) g_cfg_pendingChanges++; +#if ENABLE_MQTT g_mqtt_bBaseTopicDirty++; +#endif } } void CFG_SetMQTTUserName(const char *s) { @@ -533,12 +537,16 @@ void CFG_SetFlag(int flag, bool bValue) { *cfgValue = nf; g_cfg_pendingChanges++; // this will start only if it wasnt running +#if ENABLE_TCP_COMMANDLINE if(bValue && flag == OBK_FLAG_CMD_ENABLETCPRAWPUTTYSERVER) { CMD_StartTCPCommandLine(); } +#endif +#if ENABLE_LED_BASIC if (bValue && flag == OBK_FLAG_LED_REMEMBERLASTSTATE) { LED_SaveStateToFlashVarsNow(); } +#endif } } void CFG_SetLoggerFlag(int flag, bool bValue) { diff --git a/src/new_common.h b/src/new_common.h index b0e5da9e7..2190544be 100644 --- a/src/new_common.h +++ b/src/new_common.h @@ -632,7 +632,9 @@ const char* strcasestr(const char* str1, const char* str2); char Tiny_CRC8(const char *data,int length); void RESET_ScheduleModuleReset(int delSeconds); void MAIN_ScheduleUnsafeInit(int delSeconds); +#if ENABLE_HA_DISCOVERY void Main_ScheduleHomeAssistantDiscovery(int seconds); +#endif int Main_IsConnectedToWiFi(); int Main_IsOpenAccessPointMode(); void Main_Init(); @@ -643,9 +645,11 @@ int Main_HasWiFiConnected(); void Main_OnPingCheckerReply(int ms); // new_ping.c +#if ENABLE_PING_WATCHDOG void Main_SetupPingWatchDog(const char *target/*, int delayBetweenPings_Seconds*/); int PingWatchDog_GetTotalLost(); int PingWatchDog_GetTotalReceived(); +#endif // my addon to LWIP library diff --git a/src/new_ping.c b/src/new_ping.c index b90509256..2ce550a02 100644 --- a/src/new_ping.c +++ b/src/new_ping.c @@ -10,6 +10,10 @@ // One ping for "ping watchdog", second ran from console by user, etc etc // +#include "obk_config.h" + +#if ENABLE_PING_WATCHDOG + #include "lwip/mem.h" #include "lwip/raw.h" #include "lwip/icmp.h" @@ -205,3 +209,4 @@ void Main_SetupPingWatchDog(const char *target/*, int delayBetweenPings_Seconds* } +#endif // ENABLE_PING_WATCHDOG diff --git a/src/new_pins.c b/src/new_pins.c index fb762e285..79253af52 100644 --- a/src/new_pins.c +++ b/src/new_pins.c @@ -417,11 +417,13 @@ void Button_OnInitialPressDown(int index) CHANNEL_DoSpecialToggleAll(); return; } +#if ENABLE_LED_BASIC if (g_cfg.pins.roles[index] == IOR_Button_NextColor || g_cfg.pins.roles[index] == IOR_Button_NextColor_n) { LED_NextColor(); return; } +#endif if (g_cfg.pins.roles[index] == IOR_Button_NextDimmer || g_cfg.pins.roles[index] == IOR_Button_NextDimmer_n) { @@ -437,11 +439,14 @@ void Button_OnInitialPressDown(int index) return; } +#if ENABLE_LED_BASIC // is it a device with RGB/CW/single color/etc LED driver? if (LED_IsLEDRunning()) { LED_ToggleEnabled(); } - else { + else +#endif + { // Relays CHANNEL_Toggle(g_cfg.pins.channels[index]); } @@ -464,11 +469,13 @@ void Button_OnShortClick(int index) CHANNEL_DoSpecialToggleAll(); return; } +#if ENABLE_LED_BASIC if (g_cfg.pins.roles[index] == IOR_Button_NextColor || g_cfg.pins.roles[index] == IOR_Button_NextColor_n) { LED_NextColor(); return; } +#endif if (g_cfg.pins.roles[index] == IOR_Button_NextDimmer || g_cfg.pins.roles[index] == IOR_Button_NextDimmer_n) { return; @@ -481,11 +488,14 @@ void Button_OnShortClick(int index) { return; } +#if ENABLE_LED_BASIC // is it a device with RGB/CW/single color/etc LED driver? if (LED_IsLEDRunning()) { LED_ToggleEnabled(); } - else { + else +#endif + { // Relays CHANNEL_Toggle(g_cfg.pins.channels[index]); } @@ -511,11 +521,13 @@ void Button_OnDoubleClick(int index) // double click toggles SECOND CHANNEL linked to this button CHANNEL_Toggle(g_cfg.pins.channels2[index]); } +#if ENABLE_LED_BASIC if (g_cfg.pins.roles[index] == IOR_SmartButtonForLEDs || g_cfg.pins.roles[index] == IOR_SmartButtonForLEDs_n) { LED_NextColor(); // make it easier for users, enable LED by default LED_SetEnableAll(true); } +#endif if (g_doubleClickCallback != 0) { g_doubleClickCallback(index); } @@ -529,11 +541,13 @@ void Button_OnTripleClick(int index) } // fire event - button on pin was 3clicked EventHandlers_FireEvent(CMD_EVENT_PIN_ON3CLICK, index); +#if ENABLE_LED_BASIC if (g_cfg.pins.roles[index] == IOR_SmartButtonForLEDs || g_cfg.pins.roles[index] == IOR_SmartButtonForLEDs_n) { LED_NextTemperature(); // make it easier for users, enable LED by default LED_SetEnableAll(true); } +#endif } void Button_OnQuadrupleClick(int index) { @@ -564,6 +578,7 @@ void Button_OnLongPressHold(int index) { // fire event - button on pin was held EventHandlers_FireEvent(CMD_EVENT_PIN_ONHOLD, index); +#if ENABLE_LED_BASIC if (g_cfg.pins.roles[index] == IOR_Button_NextDimmer || g_cfg.pins.roles[index] == IOR_Button_NextDimmer_n) { LED_NextDimmerHold(); } @@ -575,6 +590,7 @@ void Button_OnLongPressHold(int index) { // make it easier for users, enable LED by default LED_SetEnableAll(true); } +#endif } void Button_OnLongPressHoldStart(int index) { addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, "%i Button_OnLongPressHoldStart\r\n", index); @@ -1084,11 +1100,13 @@ static void Channel_OnChanged(int ch, int prevValue, int iFlags) { } } } +#if ENABLE_MQTT if ((iFlags & CHANNEL_SET_FLAG_SKIP_MQTT) == 0) { if (CHANNEL_ShouldBePublished(ch)) { MQTT_ChannelPublish(ch, 0); } } +#endif // Simple event - it just says that there was a change EventHandlers_FireEvent(CMD_EVENT_CHANNEL_ONCHANGE, ch); // more advanced events - change FROM value TO value @@ -1282,6 +1300,7 @@ float CHANNEL_GetFloat(int ch) { return g_channelValuesFloats[ch]; } int CHANNEL_Get(int ch) { +#if ENABLE_LED_BASIC // special channels if (ch == SPECIAL_CHANNEL_LEDPOWER) { return LED_GetEnableAll(); @@ -1292,6 +1311,7 @@ int CHANNEL_Get(int ch) { if (ch == SPECIAL_CHANNEL_TEMPERATURE) { return LED_GetTemperature(); } +#endif if (ch >= SPECIAL_CHANNEL_BASECOLOR_FIRST && ch <= SPECIAL_CHANNEL_BASECOLOR_LAST) { return 0; // TODO } @@ -1343,6 +1363,7 @@ void CHANNEL_Set(int ch, int iVal, int iFlags) { bForce = iFlags & CHANNEL_SET_FLAG_FORCE; bSilent = iFlags & CHANNEL_SET_FLAG_SILENT; +#if ENABLE_LED_BASIC // special channels if (ch == SPECIAL_CHANNEL_LEDPOWER) { LED_SetEnableAll(iVal); @@ -1360,6 +1381,7 @@ void CHANNEL_Set(int ch, int iVal, int iFlags) { LED_SetBaseColorByIndex(ch - SPECIAL_CHANNEL_BASECOLOR_FIRST, iVal, 1); return; } +#endif if (ch >= SPECIAL_CHANNEL_FLASHVARS_FIRST && ch <= SPECIAL_CHANNEL_FLASHVARS_LAST) { HAL_FlashVars_SaveChannel(ch - SPECIAL_CHANNEL_FLASHVARS_FIRST, iVal); return; @@ -1484,11 +1506,13 @@ int CHANNEL_FindMaxValueForChannel(int ch) { void CHANNEL_Toggle(int ch) { int prev; +#if ENABLE_LED_BASIC // special channels if (ch == SPECIAL_CHANNEL_LEDPOWER) { LED_SetEnableAll(!LED_GetEnableAll()); return; } +#endif if (ch < 0 || ch >= CHANNEL_MAX) { addLogAdv(LOG_ERROR, LOG_FEATURE_GENERAL, "CHANNEL_Toggle: Channel index %i is out of range <0,%i)\n\r", ch, CHANNEL_MAX); return; @@ -1534,9 +1558,11 @@ int CHANNEL_HasChannelPinWithRole(int ch, int iorType) { return 0; } bool CHANNEL_Check(int ch) { +#if ENABLE_LED_BASIC if (ch == SPECIAL_CHANNEL_LEDPOWER) { return LED_GetEnableAll(); } +#endif if (ch < 0 || ch >= CHANNEL_MAX) { addLogAdv(LOG_ERROR, LOG_FEATURE_GENERAL, "CHANNEL_Check: Channel index %i is out of range <0,%i)\n\r", ch, CHANNEL_MAX); return 0; diff --git a/src/obk_config.h b/src/obk_config.h index 114986967..ebde3ed02 100644 --- a/src/obk_config.h +++ b/src/obk_config.h @@ -4,44 +4,66 @@ #ifndef OBK_CONFIG_H #define OBK_CONFIG_H -//Start with all driver flags undefined +// Starts with all driver flags undefined -//ENABLE_NTP - Enable support for Test drivers, NTP and HttpButton -//ENABLE_DRIVER_LED - Enable support for all LED drivers -//ENABLE_I2C - Enable support for I2C -//ENABLE_DRIVER_BL0937 - Enable support for BL0937 -//ENABLE_DRIVER_BL0942 - Enable support for BL0942 -//ENABLE_DRIVER_CSE7766 - Enable support for CSE7766 -//ENABLE_DRIVER_TUYAMCU - Enable support for TuyaMCU and tmSensor +// NOTE: +// Defines for HTTP/HTMP (UI) pages: ENABLE_HTTP_* +// Defines for drivers from drv_main.c: ENABLE_DRIVER_* +// Other defines: ENABLE_* , for example: ENABLE_LED_BASIC + +#define ENABLE_HTTP_MQTT 1 +#define ENABLE_HTTP_IP 1 +#define ENABLE_HTTP_WEBAPP 1 +#define ENABLE_HTTP_NAMES 1 +#define ENABLE_HTTP_MAC 1 +#define ENABLE_HTTP_FLAGS 1 +#define ENABLE_HTTP_STARTUP 1 +#define ENABLE_HTTP_PING 1 +#define ENABLE_LED_BASIC 1 #if PLATFORM_XR809 +#define ENABLE_MQTT 1 #define NO_CHIP_TEMPERATURE 1 #define OBK_DISABLE_ALL_DRIVERS 1 #elif PLATFORM_W600 // Some limited drivers are supported on W600, OBK_DISABLE_ALL_DRIVERS is not defined +#define ENABLE_HA_DISCOVERY 1 +#define ENABLE_MQTT 1 #define ENABLE_TASMOTADEVICEGROUPS 1 #define ENABLE_NTP 1 //#define ENABLE_NTP_DST 1 #define ENABLE_DRIVER_BL0937 1 #define ENABLE_DRIVER_DHT 1 #define ENABLE_TASMOTA_JSON 1 +#define ENABLE_DRIVER_DS1820 1 #define OBK_OTA_EXTENSION ".img" #elif PLATFORM_W800 -// try enabling drivers - e.g. to access charts -//#define OBK_DISABLE_ALL_DRIVERS 1 +#define ENABLE_HA_DISCOVERY 1 +#define ENABLE_DRIVER_OPENWEATHERMAP 1 +#define ENABLE_DRIVER_SSDP 1 +#define ENABLE_DRIVER_CHARTS 1 +#define ENABLE_MQTT 1 #define ENABLE_TASMOTA_JSON 1 #define ENABLE_DRIVER_DS1820 1 +#define ENABLE_DRIVER_DHT 1 +#define ENABLE_NTP 1 +#define ENABLE_DRIVER_BMP280 1 #define OBK_OTA_EXTENSION ".img" +#define ENABLE_I2C 1 #elif WINDOWS + +#define ENABLE_HA_DISCOVERY 1 +#define ENABLE_SEND_POSTANDGET 1 +#define ENABLE_MQTT 1 #define ENABLE_TASMOTADEVICEGROUPS 1 #define ENABLE_LITTLEFS 1 #define ENABLE_NTP 1 @@ -51,6 +73,7 @@ #define ENABLE_DRIVER_BL0942 1 #define ENABLE_DRIVER_BL0942SPI 1 #define ENABLE_DRIVER_CSE7766 1 +#define ENABLE_DRIVER_TESTPOWER 1 #define ENABLE_DRIVER_HT16K33 1 #define ENABLE_DRIVER_MAX72XX 1 #define ENABLE_DRIVER_TUYAMCU 1 @@ -58,7 +81,7 @@ #define ENABLE_CALENDAR_EVENTS 1 #define ENABLE_TEST_DRIVERS 1 #define ENABLE_DRIVER_BRIDGE 1 -#define ENABLE_HTTPBUTTONS 1 +#define ENABLE_DRIVER_HTTPBUTTONS 1 #define ENABLE_ADVANCED_CHANNELTYPES_DISCOVERY 1 #define ENABLE_DRIVER_WEMO 1 #define ENABLE_DRIVER_HUE 1 @@ -80,7 +103,8 @@ #define ENABLE_DRIVER_SSDP 1 #define ENABLE_DRIVER_ADCBUTTON 1 #define ENABLE_DRIVER_SM15155E 1 -#define ENABLE_DRIVER_IR2 0 +//#define ENABLE_DRIVER_IR 1 +//#define ENABLE_DRIVER_IR2 1 #define ENABLE_DRIVER_CHARTS 1 #define ENABLE_DRIVER_WIDGET 1 #define ENABLE_DRIVER_OPENWEATHERMAP 1 @@ -93,7 +117,10 @@ #elif PLATFORM_BL602 + +#define ENABLE_HA_DISCOVERY 1 // I have enabled drivers on BL602 +#define ENABLE_MQTT 1 #define ENABLE_TASMOTADEVICEGROUPS 1 #define ENABLE_LITTLEFS 1 #define ENABLE_NTP 1 @@ -119,7 +146,10 @@ #elif PLATFORM_BEKEN -// set to 0 to disable + +#define ENABLE_HA_DISCOVERY 1 +#define ENABLE_SEND_POSTANDGET 1 +#define ENABLE_MQTT 1 #define ENABLE_TASMOTADEVICEGROUPS 1 #define ENABLE_LITTLEFS 1 #define ENABLE_NTP 1 @@ -142,7 +172,7 @@ //#define ENABLE_TEST_COMMANDS 1 #define ENABLE_CALENDAR_EVENTS 1 #define ENABLE_DRIVER_BRIDGE 1 -#define ENABLE_HTTPBUTTONS 1 +#define ENABLE_DRIVER_HTTPBUTTONS 1 #define ENABLE_ADVANCED_CHANNELTYPES_DISCOVERY 1 #define ENABLE_DRIVER_WEMO 1 #define ENABLE_DRIVER_HUE 1 @@ -164,7 +194,8 @@ //#define ENABLE_DRIVER_BMPI2C 1 #define ENABLE_DRIVER_DDP 1 #define ENABLE_DRIVER_SSDP 1 -#define ENABLE_DRIVER_IR2 0 +#define ENABLE_DRIVER_IR 1 +//#define ENABLE_DRIVER_IR2 1 #define ENABLE_DRIVER_DS1820 1 #define ENABLE_DRIVER_CHT83XX 1 #define ENABLE_DRIVER_KP18058 1 @@ -180,6 +211,9 @@ #elif PLATFORM_LN882H + +#define ENABLE_HA_DISCOVERY 1 +#define ENABLE_MQTT 1 //#define OBK_DISABLE_ALL_DRIVERS 1 #define ENABLE_TASMOTADEVICEGROUPS 1 #define ENABLE_NTP 1 @@ -200,6 +234,9 @@ #elif PLATFORM_ESPIDF + +#define ENABLE_HA_DISCOVERY 1 +#define ENABLE_MQTT 1 #define ENABLE_I2C 1 #define ENABLE_NTP 1 //#define ENABLE_NTP_DST 1 @@ -226,6 +263,9 @@ #elif PLATFORM_TR6260 + +#define ENABLE_HA_DISCOVERY 1 +#define ENABLE_MQTT 1 #define NO_CHIP_TEMPERATURE 1 #define ENABLE_LITTLEFS 1 #define NEW_TCP_SERVER 1 @@ -240,6 +280,9 @@ #elif PLATFORM_RTL87X0C + +#define ENABLE_HA_DISCOVERY 1 +#define ENABLE_MQTT 1 #define NO_CHIP_TEMPERATURE 1 #define ENABLE_LITTLEFS 1 #define NEW_TCP_SERVER 1 @@ -263,9 +306,22 @@ #else -#error "Platform not defined" +//#error "Platform not defined" +#warning "Platform not defined" #endif +// if Tasmota DGR driver is enabled, +// then also enable HTTP config page for that +#if ENABLE_TASMOTADEVICEGROUPS +#define ENABLE_HTTP_DGR 1 +#endif + +// if power metering chip is enabled, also enable backend for that +#if ENABLE_DRIVER_BL0937 || ENABLE_DRIVER_BL0942 || ENABLE_DRIVER_BL0942SPI || ENABLE_DRIVER_CSE7766 +#define ENABLE_BL_SHARED 1 +#endif + // closing OBK_CONFIG_H #endif + diff --git a/src/ota/ota.c b/src/ota/ota.c index 7ce3eaa74..7e4be0e86 100644 --- a/src/ota/ota.c +++ b/src/ota/ota.c @@ -14,6 +14,7 @@ #include "../logging/logging.h" #include "../httpclient/http_client.h" #include "../driver/drv_public.h" +#include "../driver/drv_bl_shared.h" static unsigned char *sector = (void *)0; int sectorlen = 0; @@ -111,6 +112,7 @@ static void store_sector(unsigned int addr, unsigned char *data){ OTA_IncrementProgress(SECTOR_SIZE); } +#if ENABLE_SEND_POSTANDGET httprequest_t httprequest; @@ -148,10 +150,12 @@ int myhttpclientcallback(httprequest_t* request){ CFG_IncrementOTACount(); // make sure it's saved before reboot CFG_Save_IfThereArePendingChanges(); +#if ENABLE_BL_SHARED if (DRV_IsMeasuringPower()) { BL09XX_SaveEmeteringStatistics(); } +#endif rtos_delay_milliseconds(1000); bk_reboot(); break; @@ -217,6 +221,12 @@ void otarequest(const char *urlin){ OTA_ResetProgress(); OTA_IncrementProgress(1); } +#else + +void otarequest(const char *urlin) { + addLogAdv(LOG_INFO, LOG_FEATURE_OTA, ""); +} +#endif #endif diff --git a/src/selftest/selftest_energyMeter.c b/src/selftest/selftest_energyMeter.c index 6d9009b5e..bb4e094d5 100644 --- a/src/selftest/selftest_energyMeter.c +++ b/src/selftest/selftest_energyMeter.c @@ -2,6 +2,9 @@ #include "selftest_local.h" +#if ENABLE_BL_SHARED + + void Test_EnergyMeter_Basic() { SIM_ClearOBK(0); SIM_ClearAndPrepareForMQTTTesting("miscDevice", "bekens"); @@ -345,3 +348,4 @@ void Test_EnergyMeter() { } #endif +#endif diff --git a/src/selftest/selftest_hass_discovery.c b/src/selftest/selftest_hass_discovery.c index 821eb60e0..f1a117b4e 100644 --- a/src/selftest/selftest_hass_discovery.c +++ b/src/selftest/selftest_hass_discovery.c @@ -486,16 +486,22 @@ void Test_HassDiscovery_digitalInputNoAVTY() { void Test_HassDiscovery() { Test_HassDiscovery_SHTSensor(); +#if ENABLE_DRIVER_BL0942 Test_HassDiscovery_BL0942(); +#endif +#if ENABLE_DRIVER_BL0937 Test_HassDiscovery_BL0937(); +#endif Test_HassDiscovery_Battery(); Test_HassDiscovery_Relay_1x(); Test_HassDiscovery_Relay_2x(); +#if ENABLE_LED_BASIC Test_HassDiscovery_LED_CW(); Test_HassDiscovery_LED_RGB(); Test_HassDiscovery_LED_RGBCW(); Test_HassDiscovery_LED_SingleColor(); Test_HassDiscovery_LED_RGBW(); +#endif Test_HassDiscovery_DHT11(); Test_HassDiscovery_digitalInput(); Test_HassDiscovery_digitalInputNoAVTY(); diff --git a/src/selftest/selftest_http.c b/src/selftest/selftest_http.c index a6c057e79..8fff6d2c7 100644 --- a/src/selftest/selftest_http.c +++ b/src/selftest/selftest_http.c @@ -342,6 +342,7 @@ void Test_Http_SingleRelayOnChannel1() { Test_FakeHTTPClientPacket_JSON("cm?cmnd=STATUS"); SELFTEST_ASSERT_JSON_VALUE_INTEGER("Status", "Power", 1); +#if ENABLE_MQTT // direct channel access - set to 0, is it 0? SIM_SendFakeMQTTRawChannelSet(1, "0"); // In STATUS register, power is encoded as integer... @@ -387,7 +388,7 @@ void Test_Http_SingleRelayOnChannel1() { // In STATUS register, power is encoded as integer... Test_FakeHTTPClientPacket_JSON("cm?cmnd=STATUS"); SELFTEST_ASSERT_JSON_VALUE_INTEGER("Status", "Power", 1); - +#endif } void Test_Http_TwoRelays() { diff --git a/src/selftest/selftest_if_inside_backlog.c b/src/selftest/selftest_if_inside_backlog.c index b54fa116f..d02151854 100644 --- a/src/selftest/selftest_if_inside_backlog.c +++ b/src/selftest/selftest_if_inside_backlog.c @@ -14,6 +14,9 @@ void Test_IF_Inside_Backlog() { PIN_SetPinRoleForPinIndex(26, IOR_PWM); PIN_SetPinChannelForPinIndex(26, 2); + +#if ENABLE_LED_BASIC + CMD_ExecuteCommand("led_enableAll 1", 0); CMD_ExecuteCommand("alias day_lights backlog led_temperature 200", 0); @@ -45,6 +48,9 @@ void Test_IF_Inside_Backlog() { CMD_ExecuteCommand("set_lights", 0); SELFTEST_ASSERT_EXPRESSION("$led_temperature", 500); +#endif + + } diff --git a/src/selftest/selftest_local.h b/src/selftest/selftest_local.h index c028f8286..7a8a4bf11 100644 --- a/src/selftest/selftest_local.h +++ b/src/selftest/selftest_local.h @@ -6,6 +6,7 @@ #include "../new_common.h" #include "../new_pins.h" #include "../new_cfg.h" +#include "../obk_config.h" #include "../cmnds/cmd_public.h" #include "../cmnds/cmd_local.h" #include "../sim/sim_import.h" diff --git a/src/selftest/selftest_mqtt.c b/src/selftest/selftest_mqtt.c index 782fdac8e..4a7f8e777 100644 --- a/src/selftest/selftest_mqtt.c +++ b/src/selftest/selftest_mqtt.c @@ -9,11 +9,13 @@ void SIM_ClearAndPrepareForMQTTTesting(const char *clientName, const char *group Main_OnWiFiStatusChange(WIFI_STA_CONNECTED); CFG_SetMQTTClientId(clientName); CFG_SetMQTTGroupTopic(groupName); +#if ENABLE_MQTT MQTT_init(); for (int i = 0; i < 20; i++) { MQTT_RunEverySecondUpdate(); } +#endif } void Test_MQTT_Get_And_Reply() { SIM_ClearOBK(0); @@ -733,9 +735,11 @@ void Test_MQTT(){ Test_MQTT_Misc(); Test_MQTT_Get_And_Reply(); Test_MQTT_Channels(); +#if ENABLE_LED_BASIC Test_MQTT_LED_CW(); Test_MQTT_LED_RGB(); Test_MQTT_LED_RGBCW(); +#endif Test_MQTT_Topic_With_Slash(); Test_MQTT_Topic_With_Slashes(); Test_MQTT_Average(); diff --git a/src/selftest/selftest_tasmota.c b/src/selftest/selftest_tasmota.c index 91c760dba..decdb4c53 100644 --- a/src/selftest/selftest_tasmota.c +++ b/src/selftest/selftest_tasmota.c @@ -638,6 +638,8 @@ void Test_Backlog() { void Test_Tasmota() { Test_Tasmota_MQTT_Switch(); Test_Tasmota_MQTT_Switch_Double(); +#if ENABLE_LED_BASIC Test_Tasmota_MQTT_RGBCW(); +#endif } #endif diff --git a/src/selftest/selftest_util_mqtt.c b/src/selftest/selftest_util_mqtt.c index e4f59c491..ca267ffb0 100644 --- a/src/selftest/selftest_util_mqtt.c +++ b/src/selftest/selftest_util_mqtt.c @@ -4,8 +4,10 @@ #include "../cJSON/cJSON.h" void SIM_SendFakeMQTT(const char *text, const char *arguments) { +#if ENABLE_MQTT MQTT_Post_Received_Str(text, arguments); Sim_RunFrames(1, false); +#endif } void SIM_SendFakeMQTTAndRunSimFrame_CMND_Generic(const char *myName , const char *command, const char *arguments) { diff --git a/src/selftest/selftest_ws2812b.c b/src/selftest/selftest_ws2812b.c index 82917d97e..f8b10d4ee 100644 --- a/src/selftest/selftest_ws2812b.c +++ b/src/selftest/selftest_ws2812b.c @@ -142,6 +142,9 @@ void Test_WS2812B() { SELFTEST_ASSERT_PIXEL(4, 0, 255, 0); SELFTEST_ASSERT_PIXEL(5, 0, 0, 255); + + +#if ENABLE_LED_BASIC CMD_ExecuteCommand("startDriver PixelAnim", 0); CMD_ExecuteCommand("led_enableAll 1", 0); CMD_ExecuteCommand("led_dimmer 100", 0); @@ -178,6 +181,7 @@ void Test_WS2812B() { for (int i = 0; i < 6; i++) { SELFTEST_ASSERT_PIXEL(i, 0, 0, 0); } +#endif } diff --git a/src/user_main.c b/src/user_main.c index 6fc7eed2f..c777f3bdb 100644 --- a/src/user_main.c +++ b/src/user_main.c @@ -11,6 +11,7 @@ //#include "driver/drv_ir.h" #include "driver/drv_public.h" +#include "driver/drv_bl_shared.h" //#include "ir/ir_local.h" // Commands register, execution API and cmd tokenizer @@ -511,9 +512,12 @@ void Main_LogPowerSave() { /// @brief Schedule HomeAssistant discovery. The caller should check OBK_FLAG_AUTOMAIC_HASS_DISCOVERY if necessary. /// @param seconds +#if ENABLE_HA_DISCOVERY void Main_ScheduleHomeAssistantDiscovery(int seconds) { g_doHomeAssistantDiscoveryIn = seconds; } +#endif + void Main_ConnectToWiFiNow() { const char* wifi_ssid, * wifi_pass; @@ -585,6 +589,8 @@ void Main_OnEverySecond() g_wifi_temperature = HAL_ADC_Temp(); #endif } + +#if ENABLE_MQTT // run_adc_test(); newMQTTState = MQTT_RunEverySecondUpdate(); if (newMQTTState != bMQTTconnected) { @@ -596,6 +602,7 @@ void Main_OnEverySecond() EventHandlers_FireEvent(CMD_EVENT_MQTT_STATE, 0); } } +#endif if (g_newWiFiStatus != g_prevWiFiStatus) { g_prevWiFiStatus = g_newWiFiStatus; // Argument type here is HALWifiStatus_t enumeration @@ -612,8 +619,13 @@ void Main_OnEverySecond() // save new value g_noMQTTTime = i; + +#if ENABLE_MQTT MQTT_Dedup_Tick(); +#endif +#if ENABLE_LED_BASIC LED_RunOnEverySecond(); +#endif #ifndef OBK_DISABLE_ALL_DRIVERS DRV_OnEverySecond(); #if defined(PLATFORM_BEKEN) || defined(WINDOWS) || defined(PLATFORM_BL602) || defined(PLATFORM_ESPIDF) \ @@ -650,15 +662,18 @@ void Main_OnEverySecond() const char* ip = HAL_GetMyIPString(); // this will return non-zero if there were any changes if (strcpy_safe_checkForChanges(g_currentIPString, ip, sizeof(g_currentIPString))) { +#if ENABLE_MQTT if (MQTT_IsReady()) { MQTT_DoItemPublish(PUBLISHITEM_SELF_IP); } +#endif EventHandlers_FireEvent(CMD_EVENT_IPCHANGE, 0); - +#if ENABLE_HA_DISCOVERY //Invoke Hass discovery if ipaddr changed if (CFG_HasFlag(OBK_FLAG_AUTOMAIC_HASS_DISCOVERY)) { Main_ScheduleHomeAssistantDiscovery(1); } +#endif } } @@ -731,10 +746,16 @@ void Main_OnEverySecond() //int mqtt_max, mqtt_cur, mqtt_mem; //MQTT_GetStats(&mqtt_cur, &mqtt_max, &mqtt_mem); //ADDLOGF_INFO("mqtt req %i/%i, free mem %i\n", mqtt_cur,mqtt_max,mqtt_mem); +#if ENABLE_MQTT ADDLOGF_INFO("%sTime %i, idle %i/s, free %d, MQTT %i(%i), bWifi %i, secondsWithNoPing %i, socks %i/%i %s\n", - safe, g_secondsElapsed, idleCount, xPortGetFreeHeapSize(), bMQTTconnected, MQTT_GetConnectEvents(), - g_bHasWiFiConnected, g_timeSinceLastPingReply, LWIP_GetActiveSockets(), LWIP_GetMaxSockets(), + safe, g_secondsElapsed, idleCount, xPortGetFreeHeapSize(), bMQTTconnected, + MQTT_GetConnectEvents(),g_bHasWiFiConnected, g_timeSinceLastPingReply, LWIP_GetActiveSockets(), LWIP_GetMaxSockets(), g_powersave ? "POWERSAVE" : ""); +#else + ADDLOGF_INFO("%sTime %i, idle %i/s, free %d, bWifi %i, secondsWithNoPing %i, socks %i/%i %s\n", + safe, g_secondsElapsed, idleCount, xPortGetFreeHeapSize(),g_bHasWiFiConnected, g_timeSinceLastPingReply, LWIP_GetActiveSockets(), LWIP_GetMaxSockets(), + g_powersave ? "POWERSAVE" : ""); +#endif // reset so it's a per-second counter. idleCount = 0; } @@ -770,6 +791,8 @@ void Main_OnEverySecond() } } + +#if ENABLE_HA_DISCOVERY if (g_doHomeAssistantDiscoveryIn) { if (MQTT_IsReady()) { g_doHomeAssistantDiscoveryIn--; @@ -785,6 +808,7 @@ void Main_OnEverySecond() ADDLOGF_INFO("HA discovery is scheduled, but MQTT connection is not present yet\n"); } } +#endif if (g_openAP) { if (g_bHasWiFiConnected) @@ -817,8 +841,9 @@ void Main_OnEverySecond() { // mark as enabled g_timeSinceLastPingReply = 0; - //Main_SetupPingWatchDog(pingTargetServer,pingInterval); +#if ENABLE_PING_WATCHDOG Main_SetupPingWatchDog(pingTargetServer); +#endif } else { // mark as disabled @@ -856,7 +881,7 @@ void Main_OnEverySecond() if (!g_reset) { // ensure any config changes are saved before reboot. CFG_Save_IfThereArePendingChanges(); -#ifdef ENABLE_DRIVER_BL0937 +#if ENABLE_BL_SHARED if (DRV_IsMeasuringPower()) { BL09XX_SaveEmeteringStatistics(); @@ -948,11 +973,15 @@ void QuickTick(void* param) CMD_RunUartCmndIfRequired(); // process recieved messages here.. +#if ENABLE_MQTT MQTT_RunQuickTick(); +#endif +#if ENABLE_LED_BASIC if (CFG_HasFlag(OBK_FLAG_LED_SMOOTH_TRANSITIONS) == true) { LED_RunQuickColorLerp(g_deltaTimeMS); } +#endif // WiFi LED // In Open Access point mode, fast blink @@ -1075,7 +1104,9 @@ void Main_Init_AfterDelay_Unsafe(bool bStartAutoRunScripts) { // initialise MQTT - just sets up variables. // all MQTT happens in timer thread? +#if ENABLE_MQTT MQTT_init(); +#endif CMD_Init_Delayed(); @@ -1133,8 +1164,10 @@ void Main_Init_BeforeDelay_Unsafe(bool bAutoRunScripts) { #if ENABLE_TEST_COMMANDS CMD_InitTestCommands(); #endif +#if ENABLE_LED_BASIC NewLED_InitCommands(); -#if defined(PLATFORM_BEKEN) || defined(WINDOWS) +#endif +#if ENABLE_SEND_POSTANDGET CMD_InitSendCommands(); #endif CMD_InitChannelCommands(); @@ -1155,98 +1188,70 @@ void Main_Init_BeforeDelay_Unsafe(bool bAutoRunScripts) { if (bAutoRunScripts) { CMD_ExecuteCommand("exec early.bat", COMMAND_FLAG_SOURCE_SCRIPT); +#ifndef OBK_DISABLE_ALL_DRIVERS if (!CFG_HasFlag(OBK_FLAG_DRV_DISABLE_AUTOSTART)) { // autostart drivers if (PIN_FindPinIndexForRole(IOR_SM2135_CLK, -1) != -1 && PIN_FindPinIndexForRole(IOR_SM2135_DAT, -1) != -1) { -#ifndef OBK_DISABLE_ALL_DRIVERS DRV_StartDriver("SM2135"); -#endif } if (PIN_FindPinIndexForRole(IOR_SM2235_CLK, -1) != -1 && PIN_FindPinIndexForRole(IOR_SM2235_DAT, -1) != -1) { -#ifndef OBK_DISABLE_ALL_DRIVERS DRV_StartDriver("SM2235"); -#endif } if (PIN_FindPinIndexForRole(IOR_BP5758D_CLK, -1) != -1 && PIN_FindPinIndexForRole(IOR_BP5758D_DAT, -1) != -1) { -#ifndef OBK_DISABLE_ALL_DRIVERS DRV_StartDriver("BP5758D"); -#endif } if (PIN_FindPinIndexForRole(IOR_BP1658CJ_CLK, -1) != -1 && PIN_FindPinIndexForRole(IOR_BP1658CJ_DAT, -1) != -1) { -#ifndef OBK_DISABLE_ALL_DRIVERS DRV_StartDriver("BP1658CJ"); -#endif } if (PIN_FindPinIndexForRole(IOR_KP18058_CLK, -1) != -1 && PIN_FindPinIndexForRole(IOR_KP18058_DAT, -1) != -1) { -#ifndef OBK_DISABLE_ALL_DRIVERS DRV_StartDriver("KP18058"); -#endif } if (PIN_FindPinIndexForRole(IOR_BL0937_CF, -1) != -1 && PIN_FindPinIndexForRole(IOR_BL0937_CF1, -1) != -1 && (PIN_FindPinIndexForRole(IOR_BL0937_SEL, -1) != -1 || PIN_FindPinIndexForRole(IOR_BL0937_SEL_n, -1) != -1)) { -#ifndef OBK_DISABLE_ALL_DRIVERS DRV_StartDriver("BL0937"); -#endif } if ((PIN_FindPinIndexForRole(IOR_BridgeForward, -1) != -1) && (PIN_FindPinIndexForRole(IOR_BridgeReverse, -1) != -1)) { -#ifndef OBK_DISABLE_ALL_DRIVERS DRV_StartDriver("Bridge"); -#endif } if ((PIN_FindPinIndexForRole(IOR_DoorSensorWithDeepSleep, -1) != -1) || (PIN_FindPinIndexForRole(IOR_DoorSensorWithDeepSleep_NoPup, -1) != -1) || (PIN_FindPinIndexForRole(IOR_DoorSensorWithDeepSleep_pd, -1) != -1)) { -#ifndef OBK_DISABLE_ALL_DRIVERS DRV_StartDriver("DoorSensor"); -#endif } if (PIN_FindPinIndexForRole(IOR_CHT83XX_CLK, -1) != -1 && PIN_FindPinIndexForRole(IOR_CHT83XX_DAT, -1) != -1) { -#ifndef OBK_DISABLE_ALL_DRIVERS DRV_StartDriver("CHT83XX"); -#endif } if (PIN_FindPinIndexForRole(IOR_SHT3X_CLK, -1) != -1 && PIN_FindPinIndexForRole(IOR_SHT3X_DAT, -1) != -1) { -#ifndef OBK_DISABLE_ALL_DRIVERS DRV_StartDriver("SHT3X"); -#endif } if (PIN_FindPinIndexForRole(IOR_SGP_CLK, -1) != -1 && PIN_FindPinIndexForRole(IOR_SGP_DAT, -1) != -1) { -#ifndef OBK_DISABLE_ALL_DRIVERS DRV_StartDriver("SGP"); -#endif } if (PIN_FindPinIndexForRole(IOR_BAT_ADC, -1) != -1) { -#ifndef OBK_DISABLE_ALL_DRIVERS DRV_StartDriver("Battery"); -#endif } if (PIN_FindPinIndexForRole(IOR_TM1637_CLK, -1) != -1 && PIN_FindPinIndexForRole(IOR_TM1637_DIO, -1) != -1) { -#ifndef OBK_DISABLE_ALL_DRIVERS DRV_StartDriver("TM1637"); -#endif } if ((PIN_FindPinIndexForRole(IOR_GN6932_CLK, -1) != -1) && (PIN_FindPinIndexForRole(IOR_GN6932_DAT, -1) != -1) && (PIN_FindPinIndexForRole(IOR_GN6932_STB, -1) != -1)) { -#ifndef OBK_DISABLE_ALL_DRIVERS DRV_StartDriver("GN6932"); -#endif } // if ((PIN_FindPinIndexForRole(IOR_TM1638_CLK, -1) != -1) && // (PIN_FindPinIndexForRole(IOR_TM1638_DAT, -1) != -1) && // (PIN_FindPinIndexForRole(IOR_TM1638_STB, -1) != -1)) // { -//#ifndef OBK_DISABLE_ALL_DRIVERS // DRV_StartDriver("TM1638"); -//#endif // } } +#endif } g_enable_pins = 1; @@ -1254,7 +1259,9 @@ void Main_Init_BeforeDelay_Unsafe(bool bAutoRunScripts) { PIN_SetupPins(); QuickTick_StartThread(); +#if ENABLE_LED_BASIC NewLED_RestoreSavedStateIfNeeded(); +#endif } void Main_ForceUnsafeInit() { if (g_unsafeInitDone) { @@ -1366,7 +1373,9 @@ void Main_Init_After_Delay() } else { if (Main_HasFastConnect()) { +#if ENABLE_MQTT mqtt_loopsWithDisconnected = 9999; +#endif Main_ConnectToWiFiNow(); } else { @@ -1387,11 +1396,12 @@ void Main_Init_After_Delay() // only initialise certain things if we are not in AP mode if (!bSafeMode) { +#if ENABLE_HA_DISCOVERY //Always invoke discovery on startup. This accounts for change in ipaddr before startup and firmware update. if (CFG_HasFlag(OBK_FLAG_AUTOMAIC_HASS_DISCOVERY)) { Main_ScheduleHomeAssistantDiscovery(1); } - +#endif Main_Init_AfterDelay_Unsafe(true); } @@ -1405,8 +1415,10 @@ void Main_Init() g_unsafeInitDone = false; #ifdef WINDOWS +#if ENABLE_LED_BASIC // on windows, Main_Init may happen multiple time so we need to reset variables LED_ResetGlobalVariablesToDefaults(); +#endif // on windows, we don't want to remember commands from previous session CMD_FreeAllCommands(); #endif diff --git a/src/win_main.c b/src/win_main.c index f5bca5df0..bbb7d82eb 100644 --- a/src/win_main.c +++ b/src/win_main.c @@ -129,7 +129,6 @@ void SIM_ClearOBK(const char *flashPath) { Main_Init(); } void Win_DoUnitTests() { - Test_EnergyMeter(); Test_TuyaMCU_Boolean(); Test_TuyaMCU_DP22(); @@ -144,6 +143,9 @@ void Win_DoUnitTests() { Test_Command_If_Else(); Test_MQTT(); Test_ChargeLimitDriver(); +#if ENABLE_BL_SHARED + Test_EnergyMeter(); +#endif // this is slowest Test_TuyaMCU_Basic(); Test_TuyaMCU_Mult(); @@ -151,16 +153,20 @@ void Win_DoUnitTests() { Test_Battery(); Test_TuyaMCU_BatteryPowered(); Test_JSON_Lib(); +#if ENABLE_LED_BASIC Test_MQTT_Get_LED_EnableAll(); +#endif Test_MQTT_Get_Relay(); Test_Commands_Startup(); Test_IF_Inside_Backlog(); Test_WaitFor(); Test_TwoPWMsOneChannel(); Test_ClockEvents(); +#if ENABLE_HA_DISCOVERY Test_HassDiscovery_Base(); Test_HassDiscovery(); Test_HassDiscovery_Ext(); +#endif Test_Role_ToggleAll_2(); Test_Demo_ButtonToggleGroup(); Test_Demo_ButtonScrollingChannelValues();