From 3bbe29a64e738f34fcb01cce2a53521d0b50838f Mon Sep 17 00:00:00 2001 From: iLyas Date: Thu, 24 Sep 2020 19:20:28 -0400 Subject: [PATCH] use Json instead of String to transmet data --- src/main.ino | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main.ino b/src/main.ino index 8044027..374c0fb 100644 --- a/src/main.ino +++ b/src/main.ino @@ -7,6 +7,7 @@ #include #include +#include //https://github.com/bblanchon/ArduinoJson (use v6.xx) #include #define DEBUG true @@ -87,13 +88,16 @@ void loop() { String prepareDataForWiFi(float humidity, float temperature) { - String dataAsJson = "{\"Humidity\":\""; - dataAsJson += (String)humidity; - dataAsJson += "\", \"Temperature\":\""; - dataAsJson += (String)temperature; - dataAsJson += "\"}"; - return dataAsJson; + StaticJsonDocument<200> doc; + + doc["humidity"] = (String)humidity; + doc["temperature"] = (String)temperature; + + char jsonBuffer[512]; + serializeJson(doc, jsonBuffer); + + return jsonBuffer; } String sendDataToWiFi(String command, const int timeout, boolean debug)