Skip to content

Instantly share code, notes, and snippets.

@isaacgr
Created June 8, 2019 03:32
Show Gist options
  • Save isaacgr/6621cdee1e58e88d2072bdd5a0fdaae4 to your computer and use it in GitHub Desktop.
Save isaacgr/6621cdee1e58e88d2072bdd5a0fdaae4 to your computer and use it in GitHub Desktop.
Setup a json message buffer with ArduinoJson
#include <Arduino.h>
#include <ArduinoJson.h>
void setup()
{
Serial.begin(115200);
}
void loop(){
const size_t bufferSize = JSON_OBJECT_SIZE(5);
DynamicJsonBuffer jsonBuffer(bufferSize);
JsonObject &root = jsonBuffer.createObject();
root["temp"] = 23;
root["humid"] = 44;
root["temp_f"] = 78;
root["loc"] = "bedroom;
root["key"] = "key";
char JSONmessageBuffer[300];
root.prettyPrintTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
Serial.println(JSONmessageBuffer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment