Skip to content

Commit

Permalink
use Json instead of String to transmet data
Browse files Browse the repository at this point in the history
  • Loading branch information
isbkch committed Sep 24, 2020
1 parent ca65e70 commit 3bbe29a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <dht11.h>
#include <LiquidCrystal.h>
#include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson (use v6.xx)
#include <SoftwareSerial.h>

#define DEBUG true
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3bbe29a

Please sign in to comment.