Skip to main content

Using CCI's MQTT endpoint

MQTT is a networking protocol that uses a 'publish-subscribe' model (where some machines 'publish' data to an endpoint, and others subscribe to that data stream) to share data. It's commonly used to share networked sensor data.

We run a MQTT server at the CCI, where we publish things like the air quality data, and also allow students to publish dedicated streams for physical computing projects.

In order to follow any of the below instructions, you will first need a username and password. Ask for this on the #technical channel in Slack! The MQTT server sits at mqtt.cci.arts.ac.uk on port 18331883.

Warning
Data published to the CCI's MQTT server is readable by anyone we have given access to! If you need the data you are publishing to be private, consider setting up your own server using a Raspberry Pi using the instructions linked below.

Accessing MQTT Data Through a GUI

To use MQTT on your computer, download an application like MQTT Explorer. The setup for accessing the CCI's topics is as follows.

Topics will appear in the interface as messages are published to them -- if you don't see everything at once, it's because it hasn't yet had a message in the time you've been subscribed. You can also use the interface to publish to a topic (see below).

MQTT from the Command Line

The best package for programatically interfacing to MQTT is mosquitto. On a mac, this can be installed using Homebrew. Once it is installed, use the following commands in separate terminal windows, substituting the corresponding values for the variables in triangle brackets:

To subscribe:

mosquitto_sub -h mqtt.cci.arts.ac.uk -p 1883 \
-u <your-username> -P <your-password> \
-t "sandbox/<your-topic>"

To publish:

mosquitto_pub -h mqtt.cci.arts.ac.uk -p 1883 \
-u <your-username> -P <your-password> \
-t "sandbox/<your-topic>" -m "hello everyone"

You could also use this method to connect to an MQTT endpoint via a Raspberry Pi -- you can use these instructions to get set up. (if you're interested in setting up your own MQTT endpoint, rather than using ours, you can also use a Pi to do this).

MQTT from ESP32 (for use with Arduino)

If you want to publish data using a microcontroller (the ESP32/ESP8266 are obvious candidates, as they're networked already!), the PubSubClient library provides support for microcontroller boards including the ESP32 and Arduino Ethernet.

There's a nice tutorial for doing this available here -- note that instead of needing to set up the Raspberry Pi mosquitto broker as they suggest, you can use the CCI's MQTT server as described above.

The last thing you will need to do, if you want to run this project on campus, is to register your devices with UAL-IoT, as they won't work over UAL's general wifi. (if it's just a one-off, phone hotspot wifi will also work for this!)