Publishing INT's MQTT


#1

I am using the MQTT library for the Photon. It works amazingly! I have ran into issues when trying to publish an “int” to my Mosquitto broker. Currently I am converting my int’s to Strings and publishing them. I then have to convert them back to Int in Node Red.
Any clean ideas to accomplish this on the hardware rather than post?

I am also curious about using the MQTT library on the Electron?


#2

I take it you use the mqtt library from hirotakaster. That library has multiple publish methods, one of them lets you publish binary data. Something like:

int myint;
mqttclient.publish(“your topic”, &myint, sizeof(int) );

The question is do you really want to do that? I’d suggest that publishing one or more ints in a json message is much easier to handle later on and creates a bit more clear code. Now, if you need to shuffle say 1K of ints across, I certainly would use the publish binary method.