I'm using eclipse paho client on ubuntu and trying to send latitude, longitude and timestamp information as JSON format to the MQTT broker. How do I do that?
I found this article, But its not complete.
IMPORTANT: The JSON data sent to each MQTT topic must be 75 bytes or less to be transferred over the wireless network to the sensor platform. and the quality limit. For a description of the values, see Quality Codes.
Short answer, yes that is the proper way to send the JSON. You should not be placing anything other than a string inside of quotes.
You just need to create your JSON object as a string then call getBytes() on that string to get the byte array to use as your payload in the message.
MqttMessage message = new MqttMessage();
message.setPayload("{foo: bar, lat: 0.23443, long: 12.3453245}".getBytes());
client.publish("foo", message);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With