Sunday, April 29, 2018

Revogi Smart Power Strip SOW323 , howto

Here is a small howto on making the device usable without the cloud service. The result is a device controllable only via ethernet, with WiFi disabled, running custom simple remote control application. This howto probably voids the warranty, so use at your own risk.

First of all, replace the proprietary power controller with a simpler custom one. Sources for the controller and a convenience binary are at [LINK]. TFTP the binary to /bin/serial and chmod a+x it:

$ tftp -g -r /srv/tftp/serial -l /bin/serial 10.0.0.300
$ chmod a+x /bin/serial
# ls -la /bin/serial   
-rwxr-xr-x 1 root root 79481 Jan  1 01:23 /bin/serial
Next, replace the proprietary application with the open source one:
$ vi /etc/inittab
Locate the line
::respawn:/bin/switch
and replace it with 
::respawn:/bin/serial -l 6666
or whatever port you desire. The setting used above is 6666. To control the strip through this interface, use ie. netcat. The message format is "t:mmmmmm:vvvvvv", where "t" stands for "toggle", "m" is a mask of which sockets to toggle and "v" is the value to set on the sockets which had m=1. Both "m" and "v" values are either "0" or "1". Example:
$ echo "t:011000:101000" | nc 10.0.0.300 6666

Finally, albeit optional, disable the WiFi and start DHCP client on the wired ethernet port instead:
$ vi /etc/init.d/rcS
Locate the line
$ cfg init &
and replace it with 
mac=`grep -ri "^DEV_MAC" /etc/ | cut -d "=" -f 2`
mac1=`echo "$mac" | grep -o "............$" | grep -o "^.."`
mac2=`echo "$mac" | grep -o "..........$" | grep -o "^.."`
mac3=`echo "$mac" | grep -o "........$" | grep -o "^.."`
mac4=`echo "$mac" | grep -o "......$" | grep -o "^.."`
mac5=`echo "$mac" | grep -o "....$" | grep -o "^.."`
mac6=`echo "$mac" | grep -o "..$" | grep -o "^.."`
ifconfig eth0 hw ether ${mac1}:${mac2}:${mac3}:${mac4}:${mac5}:${mac6}
udhcpc -i eth0 -p /var/run/udhcpc.pid -s /etc/udhcpc.script

Indeed, the MAC address is stored in a configuration file within the filesystem and is configured into the ethernet interface by this "cfg" tool. This can be supplemented by
$ ifconfig eth0 hw ether MA:CA:DD:RR:EE:SS
The reason for the arcane MAC address parsing is because the system on the power strip doesn't have sed or any other useful tool to transform the MAC and the format of the MAC address entry in the configuration file is DEV_MAC=ABCDEF012345.

No comments: