Monday, April 20, 2015

First IoT device - Plug

Because was raining outside and I couldn't work in the backyard, I've made rapidly an IoT plug with ESP8266 .

Donor for the case was a timer plug that was in the house. After I've removed its content, I've added my stuff.

IoT plug
Inside the case I have:

  • power supply (220V-3v3 1A)
  • 5V relay ( is working fine on 3.3 V)
  • ESP-01 covered in blue tape 
And the final IoT plug:

IoT final plug

The ESP-01 is accepting JSON over MQTT from my mosquitto broker. 

To control the plug from my phone, I've created an android application that connects over
websockets to mosquitto broker and is sending commands. 

Plug is sending status every 15 seconds to its subscribers and a status after every command its receiving. I can turn on or off  my  lamp with my IoT device. 

For Android application I've used for rapid development a template, but I am planning to build a totally new application that will discover the IoT devices and add them automatically to the control screen.

IoT Plug application
EDIT: The Android application is different now. See this post.

And a video:


  1. This looks interesting!

    I am playing with a few esp03 modules, going in the same general direction: esp, lua, mqtt_client, mqtt_broker, home automation. I have some questions, you may have more experience in this. As a long term plan, where would you host the mqtt broker? How do you plan to reconfigure the clients firmware?

    Were you able to reuse anything from the programmable plug?


    1. Hi Marius,

      Right now the MQTT broker is on a PogoPlug NAS that was converted to a debian arm linux. I've have it also on my Raspberry Pi B/2 because later I want to test to connectivity between brokers. In the future I will use the ESP with 4M of flash since I am am on the edge right now. With 4Mb I will use OTA update for reconfigure (firmware updates). My code can address multiple sensors, so obtaining the firmware for one of them is just a matter of compiling it.



  2. I have yet to play with OTA update but it seems like a clean way of doing it if the updates are accepted only from an internal network server. So the device once installed would not need a serial input in case minor things happen (let's say the broker IP or AP password changed).

    It makes more and more sense to have a dedicated Raspberry PI as server to handle internal MQTT chatter and then interface that one with REST API with web pages or apps. I've seen some configurations using nodejs on top of the mqtt but the overhead doesn't seem necessary unless you need to handle tens or hundreds of devices.

    You were mentioning that you want to have it control the sprinkler system, did you run into range limitations so far with ESP01?


    1. My plan to configure the IoT devices is to start device in AP mode, connect to it and setup the MQTT IP address, port, user, password in a web page served by the ESP. After that the next reboot will put device into Station mode and will work normally. If the IP or password is changing then be reseting device with a button pressed will start again in AP mode and a new config will be set up. For this I need more memory on ESP.

      For sprinkler system I am using ESP201 with and external antenna because I need to control 4 valves. This week end I will put the system in place. Give me an email and I'll let you know about the range issues.

  3. Great job. Take a look at the Sonoff devices. They're cheap and already have an ESP8266 already built in. Already setup to reflash it with your own code. Many have changed the memory chip out to be able to do OTA updates and larger programs.

    1. Thanks Michael. I've made this on Monday, April 20, 2015 when Sonoff didn't exist :-) I have some Sonoff, I need to find some time o flash them. Mine are 1Mb.

  4. I saw this and it's very remarkable!
    My question is, your MQTT are you able to control lamp WAN or just LAN?

    Thanks and great job!

    1. Sure. It can control the lamp over the Internet also. Check the blog and I've also wrote a book on how to create any smart device, how to create your cloud and your mobile application. Check the latest articles on the blog.

  5. In the past 4 years, the ESP8266 is the most popular Wifi solution for Makers, the good spec and cheap price make the competitors, such as RTL8710, hard to grow up.
    But sometimes plan B is indeed needed. Recently the W600 Arm SoC Wifi solution, released by Winner Micro, we think would be an evenly matched competitor for ESP8266.