Code for an ESP8266 to control some relays in a power strip and as usual, sense weather
Just used this again today. It turns out to be real useful to have a few remote controlled outlets on my homestead, and this is how I do that. I'm using an ESP8266 module, a 4 place relay module, a tiny cheapo switcher, an 8 gang deep plastic outlet box, and the usual wires and bypass capacitors and surge protectors. This is very straightforward wiring, such that I didn't make a schematic. The pinouts used are in the code of course.
This controls 4 outlets via the relays, and senses weather, not super accurate as the sensor is inside the outlet box, but it's close enough for my needs. Do I need a coat to go out there? Does the block heater or battery charger for the big diesel backup generator need to run awhile before I go out to start it?
This kicks around the place being useful - I may build more, in which case I suppose I'd better update the web page title so as to tell them apart! Right now, it's in my mostly-unheated kitchen and used to control an electric teapot, so my water will be ready to go when I broach the morning chill to make tea. And again, notice how cold it is in the kitchen, which can be important in winter here when you're still in sleeping garb.
This demonstrates my little scheduler, and controls the relays via a CGI (in C) using the ESP web server library. The weather data is from the usual SHT31, and is displayed over the last 24 hours in a rolling buffer using SVG graphics. This was a tight fit in the resources available, so I had to break up the web content generation and do it in pieces to stay inside the available memory.
Amazingly, this rather kludgy hardware has already lived a couple of years outdoors by a generator - kind of almost protected from rain but not really, and no protection from the bugs and weeds. Since I'm no longer using that diesel, I pulled it indoors to use for other things.
In fact, this is the first time I've noticed it might have been a good idea to use that library that emits an access point and webpage to configure it if it can't find the WAP - as I just moved it out of range of one, and I had to actually get in there and program it to find the other one - that's left as an excercise for the reader, I did the hard part for ya.
It looks like the page on the right in this screen capture - I've just re-booted it, so it doesn't have 24 hours of history yet, and taken it from next to a woodstove to the cool kitchen, so it shows that. The controls link gets you to a page that lets you set the state of the relays. Nothing fancy, doing CGI in C in a limited uP, well, the bear can dance, if not amazingly ornate. The window on the left is another one, sans relays, upstairs in my machine shop, showing it warming up in there today as I put a fire in the woodstove in that building. (Vivaldi tiles are cool)
Happy morning cup!