Use the New MQTT Service from ThingSpeak for Real-time CheerLights Updates

It’s that time again. That time when people all across the world synchronize their lights together with CheerLights! People have built amazing CheerLights displays. I have seen everything from color-changing shoes to snowmen… and trees.

 

CheerLights Introduction

Here’s a quick introduction to the CheerLights project for those who are new to the project. Imagine 1000’s of multicolored lights all around the world synchronized to one color. When one of the lights turns red, they all turn red. To control CheerLights, send a tweet to @cheerlights or include “cheerlights” somewhere in your message with the name of a color. This will cause a chain reaction and all of the CheerLights displays and apps will change their color to red.

 

ThingSpeak MQTT Service

CheersLights is powered by ThingSpeak IoT. And, this year, I am happy to introduce real-time CheerLights updates using ThingSpeak’s new MQTT service. Using the MQTT service by ThingSpeak, your CheerLights change instantly. ThingSpeak has posted an example that gets a Particle Photon connected to CheerLights using MQTT. The Subscribe to Channel Updates Using Particle Photon Client example shows you how to use a Particle Photon Wi-Fi board to subscribe to channel updates from the CheerLights channel. The program displays the color read from the channel on the built-in LED on the Photon board. You can subscribe to the channel feed or directly to the color field on the CheerLights channel.

Once you learn how to use the MQTT service from ThingSpeak, you can easily adapt it to your IoT project. This is a great way to have real-time control of a device or real-time monitoring of sensors.

If you want to follow the project and see what others are building, visit CheerLights.com or follow on Twitter.

Learn How to Use MQTT.fx with ThingSpeak

ThingSpeak just announced that they added MQTT as a way to send data to a ThingSpeak channel. This is great news since a lot of devices support MQTT. If you don’t have a device, but want to try out the MQTT protocol with ThingSpeak, you can use a desktop application called MQTT.fx. In this example, I am going to explain how to use MQTT.fx to send data to a ThingSpeak channel.

ThingSpeak MQTT Broker

Setup ThingSpeak

  • Sign up for ThingSpeak (or log in if you have an account)
  • Create a new channel
  • Note the Channel ID and Write API Key

Setup MQTT.fx

  • Download and install MQTT.fx.
  • Configure the connection profile for the desktop MQTT client.
    • Broker Address: mqtt.thingspeak.com
    • Broker Port: 1883

MQTT.fx Screenshot

  • Click Connect to connect to the ThingSpeak MQTT broker.

mqttdesktop02

  • Enter the topic channels/<channelID>/publish/<apikey> to publish data to a channel feed. Replace <channelID> with the channel ID and <apikey> with the write API key of the channel. Enter the message to publish to the channel feed. This PUBLISH message publishes a value of 45 to field 1 and 60 to field 2 of the specified channel, along with a status message MQTTPUBLISH.

mqttdesktop03

  • Alternatively, you can enter the topic channels/<channelID>/publish/fields/field<fieldnumber>/<apikey> to publish to a channel field. Replace <channelID> with the channel ID, <fieldnumber> with field number that want to update, and <apikey> with the write API key of the channel. Enter the message to publish to the channel field. This PUBLISH message publishes a value of 45 to field 1 of the specified channel.

mqttdesktop04

Additional Resources

  • MQTT Basics – Learn about the publish/subscribe architecture for connecting bandwidth and power-constrained devices over wireless networks
  • MQTT Client Configuration – Learn how to set up an MQTT client to communicate with the ThingSpeak MQTT broker
  • Choose Between REST and MQTT – Learn when to use REST and MQTT to update a channel