From Flashlight to MQTT with ESP8266

Prepare a Publisher

For this one, I make a simple dashboard to push the message to MQTT server. In the stand-mode, the LCD shows the Clock.

  1. SSD1306 OLED Screen display, $2.41 each
  2. EPS8266 WEMOS D1 Mini, $2.53 each
  3. A potentiometer
  4. One 4-pin-slide switch.
  5. Two 3mm LEDs
  6. Small resistors

Here is the schematics of this terminal:

schematics of Publisher
A simple terminal to push message to MQTT server.
Upload the Code

The branded WEMOS ESP8266 is pleasant to work with. You only need a micro USB, press the upload button on Arduino IDE flash the chip. The code is here (GitHub). Change the topic to match the subscriber's one.:

Take a look at the highlight on the code (screenshot). That is the topic the dashboard pushes the message to, and our LEDs is waiting to see any news from the JSON message.

match topic
Match the topic to the subscriber's.
Adjust channel
In standy mode, this terminal shows the time, and when the switch is pushed, we can enter the value to each channel, and push the values to the MQTT server.

To publish a message, push the switch to turn the green led on (and red off), then slide up the pin and adjust, and finally push the button again to push the message onto MQTT server. The dashboard could publish a JSON message to 4 channels.

An IoT flashlight
Finally, we can control the flashlight powered by a power bank via wireless and another ESP8266. Sweet!

That is about it. I hope the tutorial is helpful.

▣ ▣ ▣