LoT thing - "smart" power strip and environment

This is somewhat of an admission of failure. You can't easily pigeon-hole everything, and most real projects use commercial software, homebrew, and hardware all at once. So, for you makers out there (including me) - this is where to put whole projects that don't fit well in the other forums.

LoT thing - "smart" power strip and environment

Postby Doug Coulter » Thu Apr 13, 2017 1:41 pm

This isn't the fanciest or most exotic thing, nor is it completely done, but it's a good base for stuff. This is a switched outlet power strip that also happens to monitor temperature and RH, since it kinda came along free. I had a well-used Ada ESP 8266 Feather Huzzah board, burned plenty of times that I used for development. At some point, it's the better part of valor to just put these into some project, before wearing out the flash...(yes, I know it's better these days, but). I like the USB support on this as a way to easily change the code in the field and kind of don't mind the extra cost, as I'm not product-izing this. If I were there are a couple things I'd do differently, but this one's just for me - and for you if you want to use this code and design.

One thing I would do differently if making this for public consumption is to use the wifi-manager library. This has the ESP 8266 default to being an access point if it can't find the hardcoded WAP in the connect parameters. It would be a great way for Joe Consumer to get it going on his LAN. It's also an attack vector if you think paranoid, as failure to connect makes it open to anyone to set up differently and spoof being you to the thing. Here, I just wanted it to work in one known spot, the shop, anyway, so I didn't mess with that yet. But it's out there if someone wants to do it - the link is to a Hackaday page describing the library.

The other thing I'd probably do differently is use 1 or two relays instead of a 4 relay board. If the whole point of wireless is fewer wires, having 4 switched power points co-located just means having a bunch of long power wires instead for most use-cases. Also, MPJA doesn't sell this cheap board anymore and only has the one or two holers. You may or may not want to put in the weather stuff, here an SHT-31 breakout, but I had it laying around and more data about the rooms in a remote building will help me decide whether to run fans or AC over there without having to hoof it over there to constantly check conditions. And now I have a way to turn these things on and off remotely. I will likely put the exhaust fan and the water collector booster pump on this, along with it's real use here - powering up and down the fusor data aq and cameras, again, remotely. Sometimes if things are really locked up, remote desktop won't get you a real robust reboot, and you might still want to turn things off for the night, and not have to hoof it over there to switch that power off and on just to do some dev work (which is always in progress with something like that).

I found a fairly nice "work box" the right size at Lowes. The main electronics fit easily in this, and lo and behold, there's even PCB retention/guide slots in this thing! However, when casting around for an AC adapter to run it all, well, even the small ones are on the large size. I pulled about the crummiest small one out of my junk box, and when I cut it open to just use the guts, I got a surprise on how they did this. It appears to be some kind of Royer oscillator running right off the line! The output (there is no feedback) is just half wave rectified off the secondary of the transformer (ferrite core) so to get any regulation at all - it's rated for either 120 or 240v - it must be doing something slightly tricky using core saturation for more than one thing.
There are just no parts there. The one diode marked zener is on the primary side of things. Here's a picture for your info. Whatever, the thing works for this just fine.
100_3142.JPG
Weird Scottish/Chinese design


On to the main show - it looks like this, when buttoned up it just looks like a sloppy hand made power strip:
100_3144.JPG
Kind of finished, thick as a brick but it won't dance and play flute

100_3143.JPG
Going together


As far as the UI is concerned, it looks like this:
ESPRlyEnv.png
root web page

And the relay control/status page looks like this:
ESP_Relay_Control.png
Relay control page CGI

The relay status is shown both on the main page and on this page when you navigate here - the CGI checks the boxes for the active relays.

The code is more or less standard for here. This implements my LANDNS stuff, using the "good luck changing this" ESP machine name which is ESP_(last 3 bytes of MAC as hex).
This broadcasts the machine name and IP on the subnet on UDP port 53831, and shouldn't bother your LAN if you're not using my code to listen for this, or at least, it doesn't bother mine.
It emits a web page at TCP/IP port 80, nothing special there. I have it showing the last 24 hours of temperature and humidity as plots via SVG graphics, which kind of makes your browser do the work. As mentioned in the code, this could be done better and faster if someone used the polyline commands instead of line...line...line, but this works.
The CGI page, /controls, creates the checkboxes and fills them in with current state. An improvement might be to make this persistent across boots with eeprom. Then again, coming up or failing in the off state seems fairly safe. So...less work, safer, I'm not fixing what I don't see as broken.

So, this is a reasonable codebase for ESP-8266 "things" for my Lan of Things projects around here. Other "things" are often Raspberry Pies, but sometimes that's total overkill, and these are both cheaper in bucks and in power use.

And of course, the real purpose of this post is to share and also have offsite backup (someday I'll get serious about github, but till then..).
ESPRly.ino.zip
Source code for arduino IDE
(6.24 KiB) Downloaded 367 times


Down the road a little (and things like this are why I made sure this would be easy to shove new code into) it might seem good to put another interface on this, say UDP at some other odd port (42042 comes to mind as the answer). Right now the only way to command this is via the web page or by pretending to submit to the existing page. It'd be easier to do programmatically, at least for me, to just have a port I could send messages to.
Posting as just me, not as the forum owner. Everything I say is "in my opinion" and YMMV -- which should go for everyone without saying.
User avatar
Doug Coulter
 
Posts: 3515
Joined: Wed Jul 14, 2010 7:05 pm
Location: Floyd county, VA, USA

Re: LoT thing - "smart" power strip and environment

Postby Doug Coulter » Fri Jun 28, 2019 11:03 am

And now there are two! We have a winner! Like all useful things, the original wound up in service in a way that I don't want to lose - it controls a block heater for the backup generator, a maintenance light, a starting battery maintainer, and a battery booster for that lashup. It's lived (and continues) a good long life outdoors stuffed under the Listeroid diesel generator pallet jack...so I built another.
Sometimes you just need a rainy day project while you think about new fusor data and decide what to try and measure next, and so on. I had the parts, the thing is super nice to have, so...
The main selling point I suppose, now that the IoT is pretty ubiquitous and inexpensive is that -

1. No external server is used (who might cut you off)
2. No external server is used that might listen in. It's amazing what can be deduced from the data most of these things emit. A different LoT device showed spikes in basement temperature when
I flushed the toilet (plumbing got cold...) or opened a door or window (the barometer). To heck with that crap.
3. No external server (Am I being repetitious here?) that might be hacked. They'd have to get into my LAN if they wanted this. It could be difficult.
4. I can fix it if it breaks...
5. your idea goes here - these kinds of things can be re-purposed or functionality added later. Easier with source code and other info you have since you built it.

While I hate wiring electrics with that fat wire (Dammit, Jim, I'm an engineer, not a butt-crack showing electrician jamming things into boxes with the force of jackscrews) - I found a workaround for that one. I used speaker wire for the "crush it into the box" parts that is a fatter gauge than the line cord, so no worries. I just tinned the ends that got into the terminal strip or under outlet screws.

I didn't need to change the software much at all - and yes, this gives away my wifi access point creds. All you have to do to compromise me is to get inside easy rifle range and try your cantenna, which won't work from the other side of the mountain. Let's have some fun! (just kidding for those easily triggered...um....). All I changed was the fixed IP I have these using for network management simplicity and troubleshooting, and the name...
I used a different power supply, this one's a bit marginal, but seems OK at least in one all-night test. I may go in and use a better one at some point. Made the build a lot cleaner looking anyway.
The power supply is here: https://www.amazon.com/DAOKI-Power-Supp ... 00XAGSKMG/
I note there are other similar ones on Amazon, I just happened to have bought a bunch of these when they were the only...most of the others look better but also cost more, your call.
Here's a link to a page of those 4 relay boards. https://www.amazon.com/s?k=relay+board+ ... _sb_noss_2
Any with the optoisolators work fine with 3.3v drive. If you get one with 12v relay coils, you'll need 12v from somewhere.
I used an old Adafruit ESP9266 "Huzzah" board as those are cheap and I had a handful - I didn't need usb programmability. But any ESP8266 will work - even a bare module if you want to do your own 3.3v LDO regulator and rig the programming interface stuff. I haven't had to go into this code and do anything....
The box is from Lowes, as are the outlets and the wall plates I had to cut to fit this. The line cord was taken from some old piece of computer junk and I cut the IEC connector end off.
The sht31 weather sensor is a generic module, available from many sources. This time I used this one: https://www.amazon.com/gp/product/B07MGL176C
I usually get such things from Adafruit, since they did spend the time to write drivers. Well, at least the first few. At some point the fact they charge double gets to me and I get the generic ones.
That plus prime...might as well also not pay as much for shipping as you do for the thing (I abuse prime - about 100 orders/year).


So, some pix of the new build, and the new code. Put it through a diff with the old stuff and instantly find out what to change for your own LAN, assuming its a type c with a base of 192.168.1.xxx.

20190627-1308-ESPRelays-2.jpg
Top view, getting started.

20190627-1309-ESPRelays-3.jpg
Wiring other than relay drives (which are just wires to the relay board header). Note sht-31 runs from 3.3v from Huzzah board. No extra pullups needed on the I2C bus here.

IMG5.png
Power supply at bottom center, relays at top, all energized and allowed to equalize temperatures. And yes, it's hot here in the summer.
IMG5.png (8.78 KiB) Viewed 4896 times


Yes, the power supply gets hot at under 1/2 it's ratings. I might someday put in a better one, Amazon is now full of better looking ones.

20190627-1327-ESPRelays-5.jpg
All but the big power wired...the rest is an exercise for the student. (yes, I hate it too when people say that)


I soldered a fat solid wire jumper between the commons of all the relays and wired that to the "hot" line of the power cord, along with the "hot" wire to the switcher power supply.
I used 16 ga speaker wire to do the individual wires to the relay and outlet hot sides, tinning the ends. The cheap computer line cord was 18 ga (!) and in this case, is the line fuse...(yep).

In the code package I added a couple useful pix of pinouts...I didn't happen to have one for the Huzzah, but the silkscreen numbers for the IO pins are the same. Here at the shop, I've printed these out and laminated them to make them stand out on the shelf from all the other junk I've printed and then lost in the pile of paper.

This uses a bit of code I call tellem. What that does is broadcast a hostname and IP address on a UDP port on the lan, for anyone listening to use to update their hosts file (using a companion program called tellme, which is perl and only used in PC's here). This makes name resolution independent of bad default setups and changes in local network ID schemes, as well as differences between various OS and hardware types - for me it works better than the official stuff. You can comment out calls to it if you like, but it generally doesn't mess up anything, as it uses an obscure high number UDP port and just once a minute or so for a short packet. More info on LANDNS (which is what I call this) elsewhere here. At some point I may even put up the .service files for the new disease called systemd we are forced to live with in the linux world (or use an obscure poorly supported distro...is there one for raspberry pies too?).

You could also just change the code to use your DHCP (which is the normal way in most examples) and trust to fate. It's not a hard change, it was much harder to get it to use a fixed one.
So far, this has worked fine in all versions of the Arduino IDE tools. I didn't put in OTA updates, as there's just no need - if I needed to change this often, I'd have used a NodeMCU full module with USB etc anyway. But this is pretty straightforward code, at least for a thing using a non standard web server and C (And printf!) for CGIs....
Turns out I did have a pinout for the Huzzah - not that it matters much. The one I also included for the NodeMCU is the one I used and have helpfully labeled which pins are used for I2C on...
ESPRly2Env.tar.gz
The bits you need.
(1.15 MiB) Downloaded 303 times


This is pretty straightforward stuff, it's just handy. If you wanted, you could run it on a bare module, or even an ESP8266-07 that has external wifi antenna connectors so you could do this inside a metal box and use a big antenna for range. Here on my campus that's not an issue - it hears the relatively weak machine shop wap from 50 yards away in my living quarters fine (which has its own WAP but I decided not to get fancy with that).

The green perfboard was cut to fit the board retention slots in the power box - yes, it has those! There was little hope of doing that on the relay board, but it fits in there diagonally in a helpful space provided and is a nearly perfect fit. I thought of adding a little glue to hold things down, but the tight fit serves fine for that...
Posting as just me, not as the forum owner. Everything I say is "in my opinion" and YMMV -- which should go for everyone without saying.
User avatar
Doug Coulter
 
Posts: 3515
Joined: Wed Jul 14, 2010 7:05 pm
Location: Floyd county, VA, USA

Re: LoT thing - "smart" power strip and environment

Postby Doug Coulter » Fri Jun 28, 2019 3:22 pm

Oh, forgot to post screenshots of the rather lame web pages this emits. I wasn't going for commercial use, just enough to make it useful to me.
Writing fancy web pages with pure html and SVG in C...well, there are better uses of my time. The fancy frameworks used by others won't fit on this hardware.
R;y2Home.png
The home page. The graphics are svg, and yes, there's internal heating here. Still useful once you know.

Rly2Controls.png
The actual controls page. The logic lets you change more than one at a time, and not false-trigger just because you checked a box - you have to say you mean it.
Posting as just me, not as the forum owner. Everything I say is "in my opinion" and YMMV -- which should go for everyone without saying.
User avatar
Doug Coulter
 
Posts: 3515
Joined: Wed Jul 14, 2010 7:05 pm
Location: Floyd county, VA, USA


Return to Combined projects

Who is online

Users browsing this forum: No registered users and 3 guests

cron