synchronized io buffer on http and mqtt, fixed 'msgid' and 'applytype'

variables names in outgoing data
This commit is contained in:
Bogdan Pilyugin 2023-09-05 13:29:23 +02:00
parent 96ff27760e
commit aa448f3cbe
5 changed files with 18 additions and 9 deletions

View File

@ -41,7 +41,7 @@
#include "esp_netif.h" #include "esp_netif.h"
#include "esp_eth.h" #include "esp_eth.h"
#include "mbedtls/base64.h" #include "mbedtls/base64.h"
#include "SysConfiguration.h" #include "SystemApplication.h"
#define MAX_DYNVAR_NAME_LENGTH 32 #define MAX_DYNVAR_NAME_LENGTH 32
#define MAX_DYNVAR_LENGTH 256 #define MAX_DYNVAR_LENGTH 256
@ -53,7 +53,7 @@
#define MAX_FILE_SIZE_STR "200KB" #define MAX_FILE_SIZE_STR "200KB"
/* Scratch buffer size */ /* Scratch buffer size */
#define SCRATCH_BUFSIZE 4096 #define SCRATCH_BUFSIZE EXPECTED_MAX_DATA_SIZE
#define AUTH_DATA_MAX_LENGTH 16 #define AUTH_DATA_MAX_LENGTH 16
#define HTTP_SERVER_DEBUG_LEVEL 0 #define HTTP_SERVER_DEBUG_LEVEL 0

View File

@ -30,7 +30,10 @@
#define REAST_API_DEBUG_MODE 0 #define REAST_API_DEBUG_MODE 0
#define EXPECTED_MAX_DATA_RESPONSE_SIZE (4096 + 1024) #define EXPECTED_MAX_HEADER_SIZE 512
#define EXPECTED_MAX_PAYLOAD_SIZE 4096
#define EXPECTED_MAX_DATA_SIZE (EXPECTED_MAX_HEADER_SIZE + EXPECTED_MAX_PAYLOAD_SIZE)
#define VAR_MAX_NAME_LENGTH MAX_DYNVAR_NAME_LENGTH #define VAR_MAX_NAME_LENGTH MAX_DYNVAR_NAME_LENGTH
#define VAR_MAX_VALUE_LENGTH (2048) #define VAR_MAX_VALUE_LENGTH (2048)

View File

@ -31,7 +31,7 @@ HTTP_IO_RESULT HTTPPostSysAPI(httpd_req_t *req, char *PostData)
httpd_req_get_hdr_value_str(req, "Content-Type", (char*) data, 31); httpd_req_get_hdr_value_str(req, "Content-Type", (char*) data, 31);
if (!memcmp(data, "application/json", sizeof("application/json"))) if (!memcmp(data, "application/json", sizeof("application/json")))
{ {
char *respbuf = malloc(EXPECTED_MAX_DATA_RESPONSE_SIZE); char *respbuf = malloc(EXPECTED_MAX_DATA_SIZE);
if (respbuf) if (respbuf)
{ {
data_message_t M = { 0 }; data_message_t M = { 0 };
@ -39,7 +39,7 @@ HTTP_IO_RESULT HTTPPostSysAPI(httpd_req_t *req, char *PostData)
M.inputDataLength = strlen(PostData); M.inputDataLength = strlen(PostData);
M.chlidx = 100; M.chlidx = 100;
M.outputDataBuffer = respbuf; M.outputDataBuffer = respbuf;
M.outputDataLength = EXPECTED_MAX_DATA_RESPONSE_SIZE; M.outputDataLength = EXPECTED_MAX_DATA_SIZE;
ServiceDataHandler(&M); ServiceDataHandler(&M);
httpd_resp_set_type(req, "application/json"); httpd_resp_set_type(req, "application/json");
httpd_resp_sendstr(req, respbuf); httpd_resp_sendstr(req, respbuf);

View File

@ -235,7 +235,7 @@ static void mqtt_system_event_handler(int idx, void *handler_args, esp_event_bas
if (!memcmp(topic, event->topic, event->topic_len)) if (!memcmp(topic, event->topic, event->topic_len))
{ {
//SystemDataHandler(event->data, event->data_len, idx); //Old API //SystemDataHandler(event->data, event->data_len, idx); //Old API
char *respbuf = malloc(EXPECTED_MAX_DATA_RESPONSE_SIZE); char *respbuf = malloc(EXPECTED_MAX_DATA_SIZE);
if (respbuf != NULL) if (respbuf != NULL)
{ {
data_message_t M = { 0 }; data_message_t M = { 0 };
@ -243,7 +243,7 @@ static void mqtt_system_event_handler(int idx, void *handler_args, esp_event_bas
M.inputDataLength = event->data_len; M.inputDataLength = event->data_len;
M.chlidx = idx; M.chlidx = idx;
M.outputDataBuffer = respbuf; M.outputDataBuffer = respbuf;
M.outputDataLength = EXPECTED_MAX_DATA_RESPONSE_SIZE; M.outputDataLength = EXPECTED_MAX_DATA_SIZE;
ServiceDataHandler(&M); ServiceDataHandler(&M);
SysServiceMQTTSend(M.outputDataBuffer, strlen(M.outputDataBuffer), idx); SysServiceMQTTSend(M.outputDataBuffer, strlen(M.outputDataBuffer), idx);
free(respbuf); free(respbuf);
@ -371,6 +371,8 @@ static void start_mqtt()
strcat(url, ":"); strcat(url, ":");
strcat(url, tmp); strcat(url, tmp);
#if ESP_IDF_VERSION_MAJOR >= 5 #if ESP_IDF_VERSION_MAJOR >= 5
mqtt_cfg.buffer.out_size = EXPECTED_MAX_DATA_SIZE;
mqtt_cfg.buffer.size = EXPECTED_MAX_DATA_SIZE;
mqtt_cfg.broker.address.uri = url; mqtt_cfg.broker.address.uri = url;
mqtt_cfg.credentials.username = GetSysConf()->mqttStation[i].UserName; mqtt_cfg.credentials.username = GetSysConf()->mqttStation[i].UserName;
mqtt_cfg.credentials.authentication.password = GetSysConf()->mqttStation[i].UserPass; mqtt_cfg.credentials.authentication.password = GetSysConf()->mqttStation[i].UserPass;

View File

@ -74,9 +74,10 @@ static sys_error_code PayloadType_1_Handler(data_message_t *MSG)
char time[RFC3339_TIMESTAMP_LENGTH]; char time[RFC3339_TIMESTAMP_LENGTH];
GetRFC3339Time(time); GetRFC3339Time(time);
jwObj_string(&jwc, "time", time); jwObj_string(&jwc, "time", time);
jwObj_int(&jwc, "messtype", DATA_MESSAGE_TYPE_RESPONSE); jwObj_int(&jwc, "msgtype", DATA_MESSAGE_TYPE_RESPONSE);
jwObj_int(&jwc, "payloadtype", 1); jwObj_int(&jwc, "payloadtype", 1);
jwObj_object(&jwc, "payload"); jwObj_object(&jwc, "payload");
jwObj_int(&jwc, "applytype", 0);
jwObj_object(&jwc, "variables"); jwObj_object(&jwc, "variables");
jRead(MSG->inputDataBuffer, "{'data'{'payload'{'variables'", &result); jRead(MSG->inputDataBuffer, "{'data'{'payload'{'variables'", &result);
@ -222,7 +223,10 @@ static sys_error_code DataHeaderParser(data_message_t *MSG)
jRead(MSG->inputDataBuffer, "{'signature'", &result); jRead(MSG->inputDataBuffer, "{'signature'", &result);
if (result.elements == 1) if (result.elements == 1)
{ {
//ESP_LOGI(TAG, "Signature is %.*s", 64, (char* )result.pValue); #if REAST_API_DEBUG_MODE
ESP_LOGI(TAG, "Signature is %.*s", 64, (char* )result.pValue);
#endif
//Here compare calculated and received signature; //Here compare calculated and received signature;
} }
else else