I try to pass JSON to my Azure IoTHub. The initial setup is quite easy. But that sends a string and I want to pass plain JSON.
I tried to use SparkJson
// Construct object
StaticJsonBuffer<200> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root["tempF"] = tempf;
root["humidity"] = humidity;
root["baroTempF"] = baroTemp;
root["pascals"] = pascals;
root["altf"] = altf;
// Deserialize to JSON
char buffer[256];
root.printTo(buffer, sizeof(buffer));
// Trigger the integration
Particle.publish("temperature", buffer);
But all I got for was this escaped JSON:
{"data":"{"tempF":69.14,"humidity":49.51,"baroTempF":70.36,"pascals":102221.75,"altf":83843.30}","device_id":"3e0025000447343138333038","event":"temperature","published_at":"2016-12-26T00:38:23.9830000Z","EventProcessedUtcTime":"2016-12-26T00:38:22.8995203Z","PartitionId":1,"EventEnqueuedUtcTime":"2016-12-26T00:38:23.3160000Z","IoTHub":{"MessageId":null,"CorrelationId":null,"ConnectionDeviceId":"3e0025000447343138333038","ConnectionDeviceGenerationId":"636181129351436517","EnqueuedTime":"0001-01-01T00:00:00.0000000","StreamId":null}}
(this is JSON output from StreamAnalytics (select * into blobsink from hubinput) which should contain unescaped json).
I also tried it using a simple string
Particle.publish("temperature", "{"value" : 42}",);
I have to escape the double quotes in order to have the code verified successfully. So It seems that the publish method is messing up my json? How can I pass unescaped JSON?