Hi, I’m using a Photon with a BME280 sensor to send weather readings to an Azure IoT Hub using the particle integration, but I’m struggling to figure out this ‘slash’ issue.
I have this code:
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define BME_SCK D4
#define BME_MISO D3
#define BME_MOSI D2
#define BME_CS D5
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK);
unsigned long delayTime;
float temperature = 0;
float pressure = 0;
float humidity = 0;
char buf[256];
void setup()
{
Serial.begin(9600); //initiate serial monitor and set data transfer rate
bme.begin(); //initiate the sensor
delayTime = 10000; //set delay to 10 seconds
}
void loop()
{
//take sensor readings
temperature = bme.readTemperature();
pressure = bme.readPressure() / 100.0F;
humidity = bme.readHumidity();
//clear JSON buffer
memset(buf, 0, sizeof(buf));
JSONBufferWriter writer(buf, sizeof(buf) - 1);
//write readings as JSON
writer.beginObject();
writer.name("Temperature C").value(temperature);
writer.name("Pressure hPa").value(pressure);
writer.name("Humidity %").value(humidity);
writer.endObject();
//print JSON buffer to serial monitor
Serial.println(buf);
Serial.println();
//publish readings to Azure
Particle.publish("SendToAzure", buf, PRIVATE);
//wait some time
delay(delayTime);
}
which is successfully creating valid JSON:
but when I check the events arriving in the IoT Hub the key string has gained a slash before each double quote:
I’m a bit new to this so not entirely sure how to resolve my code to generate valid JSON in Azure (i.e. without the slashes). Any pointers will be much appreciated!
Thanks,
db