Blog Image

Make it happen

Some code

ESP8266 Posted on Thu, March 03, 2016 10:09:31

Let’s write some code and see if this works out as planned. This blog does not allow me to paste the code here so I have created an attachment containing the code instead.

This sketch is compiled and uploaded to the ESP8266. Set the bord in the Ardino IDE to “Generic ESP8266 Module”. (I’m getting some warnings during compile but it works anyway) Remember to set GPIO00 to LOW before powering up the ESP and uploading the sketch.

The code might be a bit confusing since I’m “listening” for an incoming request for 60 seconds and then that just loops over and over again.. which of course makes no sence at all.

The reason is that I’m planning to add a schedule to my lighting. I don’t have a problem to to turn on and off lights manually when I’m at home but when I’m not at home I would like the lighting to turn on/off based on a predefined schedule. The ESP8266 will check if the schedule is active every 60 seconds ( but this is not developed yet) . But again how hard can it be 🙂
There is also a PHP file on my webpage with my floor plan, when clicking a lightbulb we send the HTTP request that the sketch is looking for. Attached you find a basic version of that file. (This basic PHP page does not have to be PHP since it only contains HTML.. but I’m expanding it with additional functionality as well)

I guess that’s it.. a webpage to control the power outlets. DONE!

The future plans for this is more functionallity such as;
– Update a mySQL database with the state of all outlets.
– Create schedule to control outlets when not at home
– When ESP updates state based on schedule it should also send a HTTP request back to the webserver to update the database
– Add on additional home automation functionality to the same dashboard.

Time to connect

ESP8266 Posted on Wed, March 02, 2016 18:59:05

Let’s connect the important stuff. I’m using an ESP8266-01 and I will program it using the Arduino IDE (google how to set up the IDE to work with the ESP module).
The ESP will be connected to the FTDI programmer (se picture)
Note that the ESP8266 only handles 3.3V so make sure to set the FTDI programmer to 3.3 or use a voltage regulator.

With the ESP connected let’s add the RF transmitter. I’m using a cheap one like this (around 1-2$ for the kit with both receiver and transmitter).The transmitter data connection is connected to GPIO02 on the ESP8266.
It’s easy to forget that GPIO00 needs to be connected to ground during startup when programming the ESP8266. When in “normal run mode” GPIO00 should be connected to VCC (or another sensor).
I had some issues with loosing wifi connection and have later learned that the ESP only can handle 2.4Ghz and not 5Ghz. (might be good to know).

Alright.. now are connected and should be able to start with some coding.

Getting some signals

ESP8266 Posted on Wed, March 02, 2016 15:47:01

Ok.. time to get some radio signals from the power outlets.
I’m using cheap 433 mhz power outlets from “Biltema”.
Now we need to figure out the signals for these outlets. For that I’m using a cheap RF signal receiver connected to my Arduino UNO.

To “sniff” the signal I use the rc-switch library and one of the “receive” examples. Pressing a button on the socket remote gives you a nummer of values in the serial monitor. I’m interested in the “tristate” values so I note them down to be used for later when I will transmit.

Since I’m incapable of figuring this kind of stuff out myself I got inspiration on