I am using ArduinoJson in a project to be able to send process data of a test bench compactly to a MQTT broker. In the reverse direction, data (setpoints) is sent to the Arduino via an HMI. Thereby I have the following problem:
When changing individual parameters on the HMI, I always have to send the complete package of parameters. Example:
I have the parameters pressure, temperature and time. The JSON looks like that:
If I change only the time at the HMI and send only the time value in a JSON file:
the library overwrites the other missing values with 0 in the following code segment:
pressure = docIn["pressure"];
temperature = docIn["temperature"];
time = docIn["time"];
So I am forced to send always the complete package of data, which leads to problems with some of my parameters.
Does anyone here know about the library and can tell me if there is a possibility to send only single parameters?
Thanks a lot for the help
In Arduinojson , an array is an ordered collection of values. THis value only includes the size of the data structures that represent the array; My Lowes Life if you have nested objects or strings , you need to add their sizes as well.
I found a way to solve my problem in the briliant documentation of the Library in chapter 3.3.3:
We saw how to extract values from an object, but we didn’t do error checking. Let’s see what happens when a value is missing.
When you try to extract a value that is not present in the document, ArduinoJson returns a default value. This value depends on the requested type.
The default value is zero. To change the default value it is possible to use the or operator. In my case the solution looked like that:
pressure = docIn["pressure"] | pressure;
temperature = docIn["temperature"] | temperature;
time = docIn["time"] | time;
Thanks for helping me. Next time I maybe first look to the documentation instead of steeling your time.
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.