diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index 3a4ba19d6..a752888a4 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -2291,13 +2291,17 @@ int http_fn_cm(http_request_t* request) { http_getRawArg(request->bodystart, "cmnd", long_str_alloced, commandLen); } CMD_ExecuteCommand(long_str_alloced, COMMAND_FLAG_SOURCE_HTTP); +#if ENABLE_TASMOTA_JSON JSON_ProcessCommandReply(long_str_alloced, skipToNextWord(long_str_alloced), request, (jsonCb_t)hprintf255, COMMAND_FLAG_SOURCE_HTTP); +#endif free(long_str_alloced); } } else { CMD_ExecuteCommand(tmpA, COMMAND_FLAG_SOURCE_HTTP); +#if ENABLE_TASMOTA_JSON JSON_ProcessCommandReply(tmpA, skipToNextWord(tmpA), request, (jsonCb_t)hprintf255, COMMAND_FLAG_SOURCE_HTTP); +#endif } } diff --git a/src/httpserver/json_interface.c b/src/httpserver/json_interface.c index 2f04b7e31..685d0fc0a 100644 --- a/src/httpserver/json_interface.c +++ b/src/httpserver/json_interface.c @@ -21,6 +21,8 @@ #include "../driver/drv_local.h" #include "../driver/drv_bl_shared.h" +#if ENABLE_TASMOTA_JSON + void JSON_PrintKeyValue_String(void* request, jsonCb_t printer, const char* key, const char* value, bool bComma) { printer(request, "\"%s\":\"%s\"", key, value); if (bComma) { @@ -1049,6 +1051,8 @@ int JSON_ProcessCommandReply(const char* cmd, const char* arg, void* request, js return 0; } +// close for ENABLE_TASMOTA_JSON +#endif diff --git a/src/httpserver/rest_interface.c b/src/httpserver/rest_interface.c index 27005900d..978362521 100644 --- a/src/httpserver/rest_interface.c +++ b/src/httpserver/rest_interface.c @@ -2062,7 +2062,9 @@ static int http_rest_post_cmd(http_request_t* request) { request->responseCode = code; http_setup(request, httpMimeTypeJson); hprintf255(request, "{\"%s\":%d, \"msg\":\"%s\", \"res\":", type, code, reply); +#if ENABLE_TASMOTA_JSON JSON_ProcessCommandReply(cmd, skipToNextWord(cmd), request, (jsonCb_t)hprintf255, COMMAND_FLAG_SOURCE_HTTP); +#endif hprintf255(request, "}", code, reply); poststr(request, NULL); return 0; diff --git a/src/mqtt/new_mqtt.c b/src/mqtt/new_mqtt.c index 07ba03787..fd6b07b73 100644 --- a/src/mqtt/new_mqtt.c +++ b/src/mqtt/new_mqtt.c @@ -708,6 +708,7 @@ int mqtt_printf255(obk_mqtt_publishReplyPrinter_t* request, const char* fmt, ... request->curLen += myLen; return 0; } +#if ENABLE_TASMOTA_JSON void MQTT_ProcessCommandReplyJSON(const char *cmd, const char *args, int flags) { obk_mqtt_publishReplyPrinter_t replyBuilder; memset(&replyBuilder, 0, sizeof(obk_mqtt_publishReplyPrinter_t)); @@ -716,6 +717,7 @@ void MQTT_ProcessCommandReplyJSON(const char *cmd, const char *args, int flags) free(replyBuilder.allocated); } } +#endif int tasCmnd(obk_mqtt_request_t* request) { const char *p, *args; //const char *p2; @@ -739,7 +741,9 @@ int tasCmnd(obk_mqtt_request_t* request) { // there is a NULL terminating character after payload of MQTT // So we can feed it directly as command CMD_ExecuteCommandArgs(p, args, COMMAND_FLAG_SOURCE_MQTT); +#if ENABLE_TASMOTA_JSON MQTT_ProcessCommandReplyJSON(p, args, COMMAND_FLAG_SOURCE_MQTT); +#endif #else int len = request->receivedLen; char copy[64]; @@ -1894,6 +1898,7 @@ int MQTT_RunQuickTick(){ int g_wantTasmotaTeleSend = 0; void MQTT_BroadcastTasmotaTeleSENSOR() { +#if ENABLE_TASMOTA_JSON if (CFG_HasFlag(OBK_FLAG_DO_TASMOTA_TELE_PUBLISHES) == false) { return; } @@ -1906,12 +1911,15 @@ void MQTT_BroadcastTasmotaTeleSENSOR() { if (bHasAnySensor) { MQTT_ProcessCommandReplyJSON("SENSOR", "", COMMAND_FLAG_SOURCE_TELESENDER); } +#endif } void MQTT_BroadcastTasmotaTeleSTATE() { +#if ENABLE_TASMOTA_JSON if (CFG_HasFlag(OBK_FLAG_DO_TASMOTA_TELE_PUBLISHES) == false) { return; } MQTT_ProcessCommandReplyJSON("STATE", "", COMMAND_FLAG_SOURCE_TELESENDER); +#endif } // called from user timer. int MQTT_RunEverySecondUpdate() diff --git a/src/new_common.h b/src/new_common.h index 4d91578a0..3f9ae17e1 100644 --- a/src/new_common.h +++ b/src/new_common.h @@ -484,7 +484,9 @@ extern int g_rebootReason; extern float g_wifi_temperature; typedef int(*jsonCb_t)(void *userData, const char *fmt, ...); +#if ENABLE_TASMOTA_JSON int JSON_ProcessCommandReply(const char *cmd, const char *args, void *request, jsonCb_t printer, int flags); +#endif void ScheduleDriverStart(const char *name, int delay); bool isWhiteSpace(char ch); void convert_IP_to_string(char *o, unsigned char *ip); diff --git a/src/obk_config.h b/src/obk_config.h index ab64f7278..5dbfb3aa4 100644 --- a/src/obk_config.h +++ b/src/obk_config.h @@ -26,10 +26,12 @@ #define ENABLE_NTP 1 #define ENABLE_DRIVER_BL0937 1 #define ENABLE_DRIVER_DHT 1 +#define ENABLE_TASMOTA_JSON 1 #elif PLATFORM_W800 #define OBK_DISABLE_ALL_DRIVERS 1 +#define ENABLE_TASMOTA_JSON 1 #elif WINDOWS @@ -62,9 +64,10 @@ #define ENABLE_EXPAND_CONSTANT 1 #define ENABLE_DRIVER_DHT 1 #define ENABLE_DRIVER_SM16703P 1 -//#define ENABLE_DRIVER_PIXELANIM 1 -//#define ENABLE_DRIVER_TMGN 1 -//#define ENABLE_DRIVER_DRAWERS 1 +#define ENABLE_DRIVER_PIXELANIM 1 +#define ENABLE_DRIVER_TMGN 1 +#define ENABLE_DRIVER_DRAWERS 1 +//#define ENABLE_TASMOTA_JSON 1 #elif PLATFORM_BL602 @@ -82,6 +85,7 @@ #define ENABLE_DRIVER_DHT 1 // parse things like $CH1 or $hour etc #define ENABLE_EXPAND_CONSTANT 1 +#define ENABLE_TASMOTA_JSON 1 #elif PLATFORM_BEKEN @@ -121,6 +125,7 @@ #define ENABLE_DRIVER_DHT 1 //#define ENABLE_DRIVER_AHT2X 1 #define ENABLE_DRIVER_DRAWERS 1 +#define ENABLE_TASMOTA_JSON 1 #elif PLATFORM_LN882H @@ -136,6 +141,7 @@ #define ENABLE_TEST_COMMANDS 0 #define ENABLE_EXPAND_CONSTANT 1 //#define ENABLE_DRIVER_TMGN 1 +#define ENABLE_TASMOTA_JSON 1 #else