Hello all,
i have very heavy problem with ArduinoJson library.
I am trying to send request with json body to server. This body contains json with some informations and with an array of measures collected from sensors.
here is the code:
void writeMeasureArray(const char* keyName, JsonObject& root)
{
JsonArray& array = root.createNestedArray(keyName);
for (int i = 0; i < this->sensorCount; i++) {
JsonObject& _obj = (this->sensorArray[i])->toMeasureJson();
_obj.printTo(Debug);
array.add(_obj);
}
};
this function should produce output like this:
{"deviceIp":{"value":"192.168.1.8"},"sensorMeasures":[{"sensorType":"GAS","digitalResult":1,"analogResult":-99999.00},
{"sensorType":"PIR","digitalResult":0,"analogResult":-99999.00},
{"sensorType":"TEMP","digitalResult":0,"analogResult":-99999.00}]}
but produces this:
{"deviceIp":{"value":"192.168.1.8"},"sensorMeasures":[{"sensorType":"TEMP","digitalResult":0,"analogResult":-99999.00},
{"sensorType":"TEMP","digitalResult":0,"analogResult":-99999.00},
{"sensorType":"TEMP","digitalResult":0,"analogResult":-99999.00}]}
sensorArray is a fixed size array of pointers to Sensor class which have toMeasureJson() method.
toMeasureJson() returns current measures of current sensor.
printing every single _obj to Serial (Debug is just a define to easily switch between Serial1 or Serial or whatever) gives
expected results. Adding _obj reference gives three same references in array.
Can some tell what am I doing wrong?