Connect and control your LED Strip trough MQTT

Actually you already have a connection with your strip. The only thing you have to do is to write an "subscriber" who will parse commands and to something with the strip.

  • #1044
  • 31 Mar 2019

How to connect the LED Strip and the MQTT server ?

You have already connected the strip with your Raspberry. After that you have connected to your Raspberry trough MQTT server. So actually you have already connected your LED Strip with the MQTT server.

How to control it ?

You just have to create a "subscriber" that controls the LED Strip as you.

What is the correct topic and message ? 

It's all up to you! You can set the topic "A" and send message "B" and do something with this, light up the strip for example. The truth is that it's not OK to name it "A" and "B". The right way is to name it in something meaningful that you'll understand when you look at your code after a couple of time like an year or more. Some good topics are "Led Strip", "My Led Strip", "WS2801".
The other important thing is to send a "good message". The "good message" is a message that brings you some meaningful information. For example if you send "On", what will the strip do ?  Light up all diodes on the strip? Or light up only the first ? Or light up a random diode? In what color?  

Let's try it!

We have written a simple publisher for you. Which posts a JSON message, with three "Key:Value" pairs :

{
    'power':'on',
    'index':'2',
    'color':'blue'
}

This message is posted on topic called "ledStrip".

Your main task will be to create a Subscriber on your Raspberry, who must parse this message and light up a diode on your LED Strip on "index" in "color". Let's do this step by step.

Courses and lessons with this Tutorial

This Tutorial is used in the following courses and lessons

Image for Perfect STEM course. Module 2 - 1D Games with Led strip.
  • 19
  • 0:00
  • 37
Image for Controlling the LED Strip from the server
  • 1
  • 0
  • 5
  • 3d_rotation 0