source code migrating from gitlab
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
#include "json/json_convert.h"
|
||||
#include <cJSON.h>
|
||||
#include <esp_log.h>
|
||||
|
||||
char *createJSON(float fahr, float cel, float hum) {
|
||||
char *json = NULL;
|
||||
|
||||
cJSON *fahrenheit = NULL;
|
||||
cJSON *celsius = NULL;
|
||||
cJSON *humidity = NULL;
|
||||
|
||||
cJSON *data = cJSON_CreateObject();
|
||||
if (!data) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fahrenheit = cJSON_CreateNumber(fahr);
|
||||
if (!fahrenheit) {
|
||||
cJSON_Delete(data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(data, "fahrenheit", fahrenheit);
|
||||
|
||||
celsius = cJSON_CreateNumber(cel);
|
||||
if (!celsius) {
|
||||
ESP_LOGE("JSON", "Failed to create celsius JSON");
|
||||
cJSON_Delete(data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(data, "celsius", celsius);
|
||||
|
||||
humidity = cJSON_CreateNumber(hum);
|
||||
if (!humidity) {
|
||||
cJSON_Delete(data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(data, "humidity", humidity);
|
||||
|
||||
json = cJSON_Print(data);
|
||||
|
||||
return json;
|
||||
}
|
||||
Reference in New Issue
Block a user