Do I need a callback for MQTT?

I currently have a simple temperature monitor ( which sends data back to my local server via a crafted HTTP request. It works but I don’t find it particularly elegant - making deep sleep work took the better part of the day - and was already looking at using something like rabbitMQ to distribute data from my temperature sensor as well as from my home energy monitor to various sources (like a local DB, Weather Underground, etc.).

So MQTT seems like a natural fit as an all around better option. I found the MQTT library on the web IDE, but I’m curious about the callback:

MQTT client(“server_name”, 1883, callback);

I wasn’t planning on sending data to the Core. Instead I was going to have to just have it wake up, check temp, send temp data to the queue, and then go back into a deep sleep. As a result, do I need a callback here? I tried omitting it entirely and using a null value. It works if I provide an empty function, but that seems a little ugly?

Thoughts? Also I’m open to suggestions if folks have suggestions other than MQTT. I noticed there is a Redis library available as well so was pondering that.

Hey, did you figure this out? Looking to do something similar with GPS coordinates.

I think you need a callback to satisfy the MQTT constructor signature, so using the empty function is probably the way to go if you don’t plan on actually receiving messages. A little ugly, but not too bad.

And, from my limited knowledge, MQTT is definitely the right choice for your proposed workflow: wake, send MQTT message, sleep.

(I know this reply is 2 years late, but just in case others are wondering…)

Even if you’re not subscribing to a topic, you’ll still need to define a method with the required signature in your code. The method won’t be called. That’s all.

The signature looks like this:

void callback(char* topic, byte* payload, unsigned int length) {

the length argument is the length of the payload.

MQTT is a great fit for devices. I use it in all of my applications. Most of them are publish and subscribe, but a few only publish (like in your case). I use Mosquito. I’ve installed it on one of my servers for devices that are home bound and I also have it installed in the cloud. During development as well as demos, I also use the Eclipse instance that is free to use (

Since MQTT can be used from multiple devices (Netduino, Arduino Zero (and other Arduino WiFi enabled devices), ESP8266, Adafruit Feather M0, Feather Huzzah, various Embed devices, TI MSP432 etc. its a really great choice for inter-communication between devices as well as regular desktop applications, Web browser applications (using WebSockets) and web server applications. Oh, and let’s not forget, the Electron!

I even have applications built using the UNO and these application are connected to a PC via USB because I communicate with an application running on the PC. These application publish messages to MQTT on behalf of the application on the UNO.

It’s an extremely light-weight protocol and if you keep your data small as well, it’s super fast, even over the internet.