allow disabling Tasmota JSON API (#1236)

* allow disabling Tasmota JSON API

* test enable
This commit is contained in:
openshwprojects
2024-05-14 11:53:26 +02:00
committed by GitHub
parent 7a7ad1eba0
commit c11a8d1e55
6 changed files with 29 additions and 3 deletions

View File

@@ -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
}
}

View File

@@ -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

View File

@@ -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;