Using zmote with your own MQTT broker

A project log for zmote

Wi-Fi Universal Remote using the ESP8266

harikrishnaHarikrishna 10/12/2015 at 08:060 Comments

zmote is typically controlled via a REST API when you are on the same network as zmote. You can get more details about the REST API here.

zmote does support MQTT as well, but we intended this to be used when controlling the zmote from outside its network. There's usually no other way to get through your router's firewall when you are outside of your home network without having to do additional configuration. And it wouldn't be very safe anyhow.

MQTT makes the process safe and painless. The zmote connects to our MQTT broker and authenticates itself. It can then be controlled via the broker by sending messages as described here.

But perhaps that is not you want. Say you have your own MQTT broker and you want zmote to connect to it instead. Turns out you can do this easily enough without having to modify zmote's firmware.

Step 1: Determine your zmote's IP and MAC

There is a way to determine your zmote internal IP address by querying (again, ourAPI document has all the details). But I'll assume you know how to get it IP on your own (by checking your router's web interfac, say, or simply by guessing and pinging). First, check that you are right:

curl http://<zmote_ip>/api/wifi/mac
This should return something like this:
{"ap_mac": "1a-fe-34-f3-b4-6e", "sta_mac":"18-fe-34-f3-b4-6e"}

Step 2: Save the default MQTT Broker IP and Port

Next query the zmote for the default MQTT broker it is connecting to:

$ curl

$ curl $
Keep these written down somewhere for when you need to go back.

Step 3: Change it to your MQTT Broker IP and Port

You can change this via corresponding `POST` commands

$ curl -X POST -H 'Content-type: application/json' -d '{"mqtt_server":"xxx.yyy.zzz.nnn"}'
$ curl -X POST -H 'Content-type: application/json' -d '{"mqtt_port":"nnn"}'

Step 4: Reboot

Reboot your zmote using

When the zmote come back up, it should connect to your broker instead of its default. You can then issue it your commands via your own broker.

Hold On

Changing the MQTT broker will break your ability to control your zmote via, our web app.

I'd still recommend the REST API over MQTT for several reasons.

  1. The REST API is easier to use -- you post to a particular URL a JSON object as command and you get a JSON response back telling you if all went well.
  2. It is faster -- there is no round tripping through an intermediary. You client speaks one-to-one with the zmote
  3. It works from any client that can do simple HTTP (a browser or even another network-connected IoT device)

But if you are comfortable with MQTT and have your own infratructure that makes that simple for you, you can use it by all means. If you think we have gotten our MQTT API all wrong and, in fact, it is better than the REST API, we'd like to hear from you.