Skip to content

Commit

Permalink
Merge pull request #264 from xkevin190/wifi-subsys-modifications
Browse files Browse the repository at this point in the history
wifi-subsys: added cJSON and changed cbor to json in the https-request
  • Loading branch information
xkevin190 authored Jun 6, 2022
2 parents 3170c58 + fd5e6c6 commit 8a2e76f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion wifi-subsys/components/uart/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
file(GLOB_RECURSE SOURCES src/*.c)
idf_component_register(SRCS ${SOURCES} INCLUDE_DIRS src ../../main REQUIRES network tools protocols)
idf_component_register(SRCS ${SOURCES} INCLUDE_DIRS src ../../main REQUIRES network json tools protocols)
9 changes: 7 additions & 2 deletions wifi-subsys/components/uart/src/subsys_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* @author xkevin190 <[email protected]>
*/
#include <string.h>
#include <cJSON.h>

#include "subsys_uart.h"
#include "driver/gpio.h"
Expand Down Expand Up @@ -100,12 +101,16 @@ void received_sensor_data(uint8_t *values, size_t len) {
decode(values, "temp", &val_received, len);
ESP_LOGI(__func__, "%d ", val_received);

cJSON* root = cJSON_CreateObject();
cJSON_AddNumberToObject(root, "temp", val_received);
char* payload = cJSON_Print(root);

http_request_t request;
request.method = HTTP_METHOD_POST;
request.content_type = HTTPS_CONTENT_CBOR;
request.content_type = HTTPS_CONTENT_JSON;
memcpy(request.url, "https://cloud.mesh4all.org",
sizeof("https://cloud.mesh4all.org"));
memcpy(request.body, values, len);
memcpy(request.body, payload, strlen(payload) + 1);
request.callback = &callback;
http_client(&request);
}
Expand Down

0 comments on commit 8a2e76f

Please sign in to comment.