Hello, I am new to arduino, and am trying to send a Json document to MQTT. It will send, but it doesn't display the message in the format I need/want. It just shows some random characters (which I'm guessing is something to do with the encoding) but not what I actually want to display. The print to serial output works fine and displays :
"{"Measurement":"Quench1","fields":{},"temperature":["22.25"],"tags":{"Machinename":"QuenchTank1","Machinetype":"Quench"},"Timestamp":{}}"
The Json document is meant to display in MQTT as above but I'm getting funny characters like "������".
Here's my code:
StaticJsonDocument<200> doc;
//Add "Location" to doc
doc["Measurement"] = "Quench1";
//Add "fields" to the Json document
JsonObject fields = doc.createNestedObject("fields");
//Add temperature underneath "fields"
JsonArray temperature = doc.createNestedArray("temperature");
// Add "tags" to the Json document
JsonObject tags = doc.createNestedObject("tags");
// This adds the readout from the thermocouple to the Json Doc
temperature.add(String(thermocouple.readCelsius()));
// Adding "machine name" and "machine type" to "tags"
tags["Machinename"] = "QuenchTank1";
tags["Machinetype"] = "Quench";
JsonObject Timestamp = doc.createNestedObject("exampleTimestamp");
// New line
Serial.println();
serializeJson(doc, Serial);
client.connect("TYZ040-777" );
client.publish("TYZ040-777", serializeJsonPretty(doc, Serial)));
Any help would be greatly appreciated!