Feature #1080
closedSensors: 1 port power switch
100%
Description
This is effectively the same as the light switch but is generalized to enable power on an outlet.
The ESP board should be powered via the mains, so I need a buck converter of some kind, probably like this simple circuit that takes 110v down to 12v and then to 5v or lower.
- https://makeradvisor.com/tools/rf-remote-controlled-sockets-433mhz/
- https://github.com/xkonni/raspberry-remote
- https://github.com/sui77/rc-switch - library to control 433MHz switches.
- https://tutorials-raspberrypi.com/control-raspberry-pi-wireless-sockets-433mhz-tutorial/
- https://hristoborisov.com/index.php/projects/switcher-a-wifi-open-source-power-switch/
- https://randomnerdtutorials.com/esp8266-remote-controlled-sockets/
- ESP8266 ESP-01S Relay Module Relay WIFI Smart Socket Control Switch
- https://newbiely.com/tutorials/esp8266/esp8266-relay
It would seem that the easy way to do this is to use a 433MHz socket along with the Pi and the rc-switch library. rc-switch provides some sample projects that might provide templates for creating Ironman interfaces.
Files
Related issues
Updated by Hammel 12 months ago
Ordered 433Mhz xmit/receive units from Amazon, along with BN-Link RF outlets.
I already have Arduino's I can use, including ESP8266-01's.
- Debian pkg: 1.8.13 - apt get arduino
- Upstream: 2.3.2
ESP8266 Guide (from Ironman lightsw project, only valid for 1.x releases).
This should be tested first with the Arduino boards, then ported to the esp8266 if possible. A bank of esp8266 boards for a collection of RF outlets would be preferrable to a bank of Arduino's, although some of them are pretty small too.
Updated by Hammel 12 days ago
- % Done changed from 0 to 10
- Severity changed from 03 - Medium to 01 - Critical
- pwrctrl (the old imlightsw). This will require custom hardware and enclosure. This will be tracked in this issue.
- pwremote - a new project based on using off-the-shelf 433MHz controlled plugs. pwremote will be tracked separately, in RM #1191.
Both projects will live in the "ard lightsw" repo (re: xarduino/imlightsw, which will eventually be renamed to something more generic like ABox or similar).
Both projects will need- Mains power to 3.3V for the ESP01
- an enclosure
pwrctrl will need the additional components defined in the Users Guide
Updated by Hammel 9 days ago
Step 1: Get the runtime protoboard back up and running. This is not the programmer, it's the other board.
It's got a ton of wires hanging on it and it doesn't quite look like the picture on the Wiki. I need to design it with an HLK-PM03 step down power supply (110v to 3.3v) to use mains power. And then mains have to pass through to the socket. I should update the Fritzing diagram for that.
Updated by Hammel 9 days ago
Runtime protoboard is running. I can step through WiFi setup.
Tip: Enable Reset first (left side is on, right side is off). The enable config (left on, right off).
With Config enabled (watch minicom), connect with phone and configure connection to AP. Wait for ESP to connect to AP, then power off and disable both Config and Reset buttons.
At this point I need to setup Ironman with it's gpio button for pairing. This will switch to an app that can put the Ironman monitor into pairing mode with display updates when pairing is waiting and connected, etc. But for now I just need to see the protoboard connect to Ironman and make sure the LED on the protoboard goes on and off.
Updated by Hammel 7 days ago
The sensor attempts to pair correctly but to the wrong device. It's trying to connect to the Media System (on .60) instead of the Ironman Systsem (on .67).
.........imiot setup: Connected to: MuseN IP address : 192.168.101.199 Password : 6953af02c3 Resetting GPIO0. HTTP server started Device registration not found. Scheduling timer events. ...............................Sent multicast announcement: 0 .........Registering with url = http://192.168.101.60:8165/pair/iot/1df53702-0f21-11f0-b4a6-b827eba2c19a Return code from http.POST: -1I see three things here.
- Media System should not have registration enabled.
- Ironman may not have registration enabled and running in piboxd.
- Media System doesn't have the web server running to respond to the POST from the sensor.
I'll shutdown Media System and retry just to see if Ironman responds at all. Then I need to check piboxd builds to make sure Ironman gets registration while Media System does not.
Once I get Ironman responding to the multicast request I can check on the web server that should be responding to the POST from the sensor.
Updated by Hammel 7 days ago
Ironman is not responding to multicast.
.........imiot setup: Connected to: MuseN IP address : 192.168.101.199 Password : 6953af02c3 Resetting GPIO0. HTTP server started Device registration not found. Scheduling timer events. ...............................Sent multicast announcement: 0 ................................Sent multicast announcement: 1 ................................Sent multicast announcement: 2 ................................Sent multicast announcement: 3 ................................Sent multicast announcement: 4
Updated by Hammel 7 days ago
Verified that sensor and Ironman are attempting registration - ironman gets multicast request and sends back uuid. sensor attempts to connect to ironman with the POST to complete registration. But this fails because the imrest server isn't running because I can no longer compile nodejs with Buildroot.
I've already ported imrest to mongoose (see RM #1006). But I think I missed porting imrest to an initscript. The old startup script, runserver.sh, just starts nodejs, not the new imrest.
Also, when I run imrest manually, the registration fails with 401 on the sensor:
Connected to: MuseN
IP address : 192.168.101.199
Password : 6953af02c3
Resetting GPIO0.
HTTP server started
Device registration not found.
Scheduling timer events.
....................Sent multicast announcement: 0
................................Sent multicast announcement: 1
................................Sent multicast announcement: 2
................................Sent multicast announcement: 3
................................Sent multicast announcement: 4
................................Sent multicast announcement: 5
................................Sent multicast announcement: 6
.............Registering with url = http://192.168.101.67:8165/pair/iot/3b0577f2-0f40-11f0-a89a-b827eb3c7aaf
Return code from http.POST: 401
This is likely because imrest's API was updated so pwrctrl (re: imlightsw) must be updated to match.
The runserver.sh shouldn't be needed. It's actually quite messy. There should be an init script for the php server (imwww) and one for the IoT server (imrest). Both should start at boot time. Both should be running mongoose. And both should be able to test for state files within the C code wrapping mongoose. Doing this will simplify Ironman startup and reduce clutter in the /home/httpd/* directories by removing the useless nodejs stuff (which still needs to be removed) and extra php files (but might leave the templates).
I need to add some new issues to track this work.- imlightsw repo
- imrest
- metabuild
- Remove imgpio package from ironman since mongoose can check gpio itself (so shell scripts don't need to do it anymore). (RM #1203)
- imwww
1203, 1204 and 1205 can be worked on after this issue is complete.
Updated by Hammel 7 days ago
- Related to Feature #1195: Port pwrctrl to use new API added
Updated by Hammel 7 days ago
- Related to Maintenance #1197: Remove src/old from imrest repo. added
Updated by Hammel 7 days ago
- Related to Maintenance #1196: Remove imrest directory from imwww repo added
Updated by Hammel 7 days ago
- Related to Feature #1199: Add init script for imrest added
Updated by Hammel 7 days ago
- Related to Feature #1200: Have imrest check for gpio state to allow registrations added
Updated by Hammel 7 days ago
- Related to Action Item #1203: Remove imgpio package from ironman since mongoose can check gpio itself added
Updated by Hammel 7 days ago
- Related to Feature #1204: Port imwww web server to mongoose added
Updated by Hammel 7 days ago
- Related to Feature #1205: Make init script run mongoose-ported imwww added
Updated by Hammel 4 days ago
- Status changed from New to In Progress
- % Done changed from 10 to 50
pwrctrl talks to imrest and attempts to register.
imrest gets the registration
$ imrest -v3 Verbosity level: 3 main[imrest.c:317] INFO No log file configured. validateConfig[cli.c:192] INFO Webroot: /home/httpd/imrest initSetup[init.c:56] INFO init.setup has been called. initSetup[init.c:75] INFO Webroot directory : /home/httpd/imrest initSetup[init.c:76] INFO Ironman directory : /home/httpd/imrest/ironman initSetup[init.c:77] INFO Monitor directory : /home/httpd/imrest/monitor initSetup[init.c:78] INFO Stamp directory : /home/httpd/imrest/ironman/jarvis/ initSetup[init.c:79] INFO IoT directory : /home/httpd/imrest/ironman/iot/ initSetup[init.c:80] INFO Descriptor file : /home/httpd/imrest/monitor/descriptor initSetup[init.c:82] INFO Monitor UUID : 9ac68709-da72-4b3f-91b3-a7cadcae4801 main[imrest.c:337] INFO Running from /home/httpd/imrest. frontEnd[imrest.c:265] INFO Inbound method: POST handlePost[imrest.c:157] INFO uri: /pair/iot/6d49a5fe-11a6-11f0-98cf-b827eb3c7aaf handlePost[imrest.c:161] INFO body: {"type":"light_switch","description":"Toggle_light_switch","state":0}
But the response on pwrctrl looks like a failure.
...........................Sent multicast announcement: 0 .............Registering with url = http://192.168.101.62:8165/pair/iot/6d382fae-11a6-11f0-a59d-b827eb0e76fa Return code from http.POST: -1 ........Registering with url = http://192.168.101.67:8165/pair/iot/6d49a5fe-11a6-11f0-98cf-b827eb3c7aaf Return code from http.POST: 401
Updated by Hammel 3 days ago
Registration appears to complete now.
frontEnd[imrest.c:266] INFO Inbound method: POST
handlePost[imrest.c:157] INFO uri: */pair/iot/547c1774-1236-11f0-84e6-b827eb3c7aaf*
handlePost[imrest.c:158] INFO PAIR_IOT: */pair/iot*
handlePost[imrest.c:162] INFO body: {"type":"light_switch","description":"Toggle_light_switch","state":0}
handlePost[imrest.c:180] INFO Match PAIR_IOT: /pair/iot
devicePairIot[pair.c:123] INFO Entered.
gpioRead[utils.c:583] INFO GPIO value for pin 4: 1
Ev/sys/class/gpio/gpio4/value
devicePairIot[pair.c:136] INFO Registration mode enabled. Handing pair request from 192.168.101.199
handle_uuid[pair.c:55] INFO handle_uuid has been called: stampDir: /home/httpd/imrest/ironman/iot/, json = {"type":"light_swi
tch","description":"Toggle_light_switch","state":0}
handle_uuid[pair.c:66] INFO Registration file: /home/httpd/imrest/ironman/iot//192.168.101.199
handle_uuid[pair.c:89] INFO Wrote registration stamp file: /home/httpd/imrest/ironman/iot//192.168.101.199
But using that registration fails on imrest.
frontEnd[imrest.c:266] INFO Inbound method: GET
handleGet[imrest.c:122] INFO Requesting IP: 127.0.0.1
deviceGetDevices[device.c:307] INFO Entered.
deviceGetDevices[device.c:316] INFO GetDevices request from local system.
deviceGetDevices[device.c:328] INFO iotDir: /home/httpd/imrest/ironman/iot/
deviceGetDevices[device.c:340] INFO Requesting check of 192.168.101.199
utilsLoadUUID[utils.c:130] INFO iotDir: /home/httpd/imrest/ironman/iot/
utilsLoadUUID[utils.c:133] INFO iot file: /home/httpd/imrest/ironman/iot/192.168.101.199
utilsLoadUUID[utils.c:144] INFO File data: {"type":"light_switch","description":"Toggle_light_switch","state":0}
deviceGetDevices[device.c:344] ERROR Failed check of 192.168.101.199
Updated by Hammel 3 days ago
pwrctrl is not adding the UUID to the registration JSON packet because it's in the URL. However, when imrest checks the packet later when pwrctrl tries to reconnect it doesn't find the uuid (in deviceGetDevices()) in the saved JSON data so it rejects the attempt to reconnect.
I can either remove the check imrest (because the filename IS the UUID) or I can add the UUID to the JSON packet during pwrctrl's registration.
Updated by Hammel 1 day ago
- Status changed from In Progress to Closed
- % Done changed from 50 to 100
Okay, it's working again!!
.........imiot setup: Connected to: MuseN IP address : 192.168.101.199 Password : 6953af02c3 Resetting GPIO0. HTTP server started Reading from SPIFFS Read from /registration.txt: d22b0246-1409-11f0-8569-b827eb3c7aaf:d22b0246-1409-11:192.168.101.67 UUID: d22b0246-1409-11f0-8569-b827eb3c7aaf Key: d22b0246-1409-11 Monitor Address: 192.168.101.67 Encoding message: ping iv: /rQnNkwD54P+tCc2TAPngw== message: 9eWOnJ4AJTJZET10y6qlXA== Ping JSON: {"iv":"/rQnNkwD54P+tCc2TAPngw==","message":"9eWOnJ4AJTJZET10y6qlXA=="} Checking registering with url = http://192.168.101.67:8165/ping Return code from http.POST: 200 We're still paired. Scheduling timer events. ......................................................................................................................Entere. Monitor Address: 192.168.101.67 Request Address: 192.168.101.67 Decoding message: {"iv":"ZjQwM2I5YTYtNWJjZC00Zg==","message":"PKDcFxMrmcH4JAALImoTng=="} iv: *ZjQwM2I5YTYtNWJjZC00Zg==* IV len: 24 message: PKDcFxMrmcH4JAALImoTng== message len: 24 1. decode message len: 16 2. decode message len: 16 paddedlen: 32 key: d22b0246-1409-11 Decrypted message: getdevices Message: {"uuid":"d22b0246-1409-11f0-8569-b827eb3c7aaf","type":"light_switch","description":"Toggle_light_switch","state":0} Encoding message: {"uuid":"d22b0246-1409-11f0-8569-b827eb3c7aaf","type":"light_switch","description":"Toggle_light_switch","} iv: Jz4/1TknPConPj/VOSc8Kg== message: BRaPTk15zEIc+5SHE6fguPJbE7tmRLEQ71oAyXKTZiy5kDIx/AKZbdSfUH8JqdwSUBJpPtsoEsUNPLGN04gVibQzWZ8nEKi7Ik/Ecue5BsUXnRIK6Mf=
(That's without wrap enabled in minicom)
That's what it looks like AFTER registration has completed. This required switching pwrctrl and piboxd to the 239 multicast address and fixing the registration JSON from pwrcrtl to include the UUID so imrest could validate it properly on reconnects.
This is good enough for this issue. I now need to test the same code with the pwremote implementation which is identical except it uses the RFSwitch library to send 433MHz signals instead of directly controlling the relay switch.
And yes, there is now an issue (RM #1208) for converting registration and pairing in a library so the code can be shared with ALL IoT sensors for Ironman.
All code tested on hardware.
All code committed and pushed.
Closing issue.