I am learning the ArduinoJson.h
library and creating jsonOject:
JsonObject& prepareResponse(JsonBuffer& jsonBuffer) {
JsonObject& root = jsonBuffer.createObject();
JsonArray& tempValues = root.createNestedArray("temperature");
tempValues.add(t);
JsonArray& humiValues = root.createNestedArray("humidity");
humiValues.add(h);
JsonArray& dewpValues = root.createNestedArray("dewpoint");
dewpValues.add(pfDew);
JsonArray& EsPvValues = root.createNestedArray("systemv");
EsPvValues.add(pfVcc / 1000, 3);
return root;
}
As per the example given here. However since I am using an ESP8266WebServer
to create a server object from ESP8266WebServer.h
, I cannot pass a JsonObject to server.send(.....)
.
no matching function for call to 'ESP8266WebServer::send(int, const char [10], ArduinoJson::JsonObject&)'
void outputJson() {
StaticJsonBuffer<500> jsonBuffer;
JsonObject& json = prepareResponse(jsonBuffer);
writeResponse(client, json);
server.send ( 200, "text/json", json );
}
void writeResponse(WiFiClient& clnt, JsonObject& json) {
clnt.println("HTTP/1.1 200 OK");
clnt.println("Content-Type: application/json");
clnt.println("Access-Control-Allow-Origin: *");
clnt.println("Connection: close");
clnt.println();
json.prettyPrintTo(clnt);
}