Skip to main content

Building a Web-Controlled WiFi-Enabled Power Plug

Testing the ESP8266 with an Arduino UNO.
[Update (May 1, 2016): The box itself has since seen a version upgrade, which can be found here.]

My last project sought to create a light show by using an Arduino board and a few relays to coordinate a light show. Fun stuff, but not really useful year-round. With the holiday season behind us, and having recently taken delivery of an ESP8266 WiFi module, I therefore decided to repurpose the parts to build something new. The thought was to combine my #WittyLights project with the new hardware to enable new methods of interaction.

The first thing I had to do was figure out how to work with the WiFi module. It being relatively new to the market, there wasn't a lot of documentation available for it- at least, not much written in English. My initial attempts at getting the ESP to communicate with Wit's API were fruitless and, as a direct result of the lack of documentation, I quickly decided that there were simply too many potential reasons for why my efforts were not successful. I therefore decided to change focus and instead configure the Arduino to respond to incoming requests as opposed to initiating requests itself. A separate computer, cloud-based or local, would be responsible for all of the data processing and then forward along a simplified command to the Arduino over the internet or local network.


Testing the ESP8266 using the Arduino's USB to UART bridge.

After a bit of trial and error I eventually figured out which commands should be sent to the ESP in order to prep it for incoming requests, as well as how to handle said requests once they were passed to the Arduino. Once I managed to sort all of that out, it was a rather straightforward process to figure out how to return some sort of a command-received-successfully message back to whoever made the original request. This I eventually decided to format as a JSON object and return the current command being performed by the board.


This sketch allows you to control pins 2-10 by making a simple HTTP request from another device, such as the browser on a computer. It then returns a message which can be used to determine whether or not the sent command was properly executed. My own setup involves the same 4-channel relay board and 2-plug receptacles that were employed in my previous project, allowing for complete control of the circuits' power states from anywhere in the world. Now I have an easy means of communicating with the board, facilitating implementation into a Twitterbot, website, mobile application or even something else entirely. Cool, huh?

Comments