I'm using MQTT on an Arduino to send sensors data to a Javascript page.
Until now I've sent only simple data format: int or floats.
What format can I use to send more complex, structured data? for example:
{ "temperature": 32, "humidity": 67 }
I'd like to send it on a single MQTT message.
I could use Json, but I fear it's a bit heavy for an Arduino.
Update
Ok, seems to be a general consensus on JSON, however I'm a bit concerned about the memory requirement.
I've found two libraries for json encoding/decoding on an Arduino:
ArduinoJson claims to be less memory consuming, however doesn't support:
- reading from Stream (latest versions of the Arduino MQTT library supports receiving messages in streams)
- filtering of incoming json (to selectively parse only required Json fields)
The way I do it is just publish the temp in Celsius (or Faranheit) from the Arduino to the broker for example
/raw/sensorid temp
Then on the broker I transform it all into JSON including adding a timestamp and republish to another topic. I find it easier this way as I don't need to change the arduino code if I move the sensor or have replace it. Here is the code I use if you are interested, it's using Onewire sensors.
For example;
I do all my transformation in python using mqttwarn.