To curl or not to curl or “Using Insteon Hub Remotely”

 I have a Windows 10 machine an Arduino and my new addition is a Raspberry PI B+.  I have been using bath files to turn ON/OFF my X10 units that are hooked up to my Amateur Radio Station. The X10 is used to turn on/off different either power supply for the Radio’s or powered Wall-Wart units that power my hub’s on the Windows 7 machine.  In removing the CM-15A from the Windows 7 machine I needed a way to talk to the Insteon Hub Model 2242-222. The Hub will allow HTTP Posts to it for commands and trying to find something simple and cross platform, IE Raspberry PI and the Windows 7 box has been daunting. I had looked into several TCP/IP and UDP protocol sending platforms and sendip but nothing seemed to work well and easily between cross platforms.

I have been away from programming far to long and I do need to catch up on it. I am using here a HTTP POST type command and is very inefficient, but works and besides no one else is using my local network except hackers. To continue,  I came across the curl command, nothing like it under the stock hood of windows, but was easily supported under the Raspberry PI. I later found a curl for Windows X platforms and looked good for me and I was able to assemble a string to transmit the turn ON or Off commands of the X10 protocol using the Insteon Hub. Curl was found at: http://curl.haxx.se/latest.cgi?curl=win64-nossl  found a windows x64 version since I am using Windows 10 x64 and thought it would be best. I really do not think in this case the x64 version is necessary.

The first two commands to turn off device H16 OFF look something like this:

command 1: 3?0263DC00=I=3

command 2: 3?0263D280=I=3

First line is broken down like so: 3, the ?, then 02, then 63, the 1st half of byte is HouseCode in this case H = 13 which is D hexadecimal,  C is the UnitCode of 16 which transcribes to 12 which is C hexadecimal, 00 is a status filler, =I is for indirect command (I believe) and the =3 tells how many iterations to send of this command.

The Second line is similar, but the C of DC is replaced with 2  giving the OFF and the 00 is replaced with 80 which is issuing the Command. Of course I can be wrong in these assumptions, but works in my head for now and I welcome any corrections.

Now I believe the 3 is to get the attention of the HUB and let it know that a DIRECT command will follow the ?, 02 is for a type of command start and the 63 is for the direct command. DC is the HoiuseCode and UnitCode and the 00 is a flag, I guess technically should indicate the brightness of the controlled device 00-FF and since I’m using X10 ON/OFF I kind of ignore it for now and set to 00. The last 3 bytes are changed to 280 command is to turn an x10 item OFF and the 380 is to turn it ON.  Checkout the reference #1 for how HouseCodes and UnitCodes are combined and check #2 on how the commands are separated.

Now I have left out an important part of the information you will need such how to address the unit. the command line is such to turn OFF:

http://192.168.1.105:25105/3?0263DC00=I=3

http://192.168.1.105:25105/3?0263D2800=I=3 (OFF)

or to turn ON:

http://192.168.1.105:25105/3?0263DC00=I=3

http://192.168.1.105:25105/3?0263D380=I=3    (ON)

In reality only 2 numbers are changing, the 28 or the 38 in my examples. Now it is important to know about the 00 flags I am using since they can be used for brightness control, but here not necessary.

you may need a username and password to sent to your Hub such as for the OFF command:

http://username:userpassword@192.168.1.105:25105/3?0263DC00=I=3

http://username:userpassword@192.168.1.105:25105/3?0263D280=I=3

So in reality to use curl goes as follows:

curl http://username:userpassword@192.168.1.105:25105/3?0263DC00=I=3

sleep 1

curl http://username:userpassword@192.168.1.105:25105/3?0263D280=I=3

You may have noticed I added in a sleep 1 command to allow time for the Hub to process things and may not really be necessary, but I needed them. If you follow up with several commands you may also need another sleep x command just to give the Hub time to respond.

The really nice thing about this is I have a file of several commands that turn ON or OFF H 1-8 and H16 so there are 9 units getting the command and between the both systems, Windows 7 and Raspberry PI the only difference in the files is in Windows it is called turnOnRadio.bat and on the Raspberry PI it is called turnOnRadio.

So in conclusion it isn’t a very nice way to do things, but was effective. I plan on making use of either a Perl script or a C language file to do this in the future, or perhaps use another port on the Insteon Hub to be even more direct.

Revised portion:

  I have added some variables: $ipaddress, $user, $password. I chose not to define the port 25105 as I do not plan on this changing.

definitions in program are:

ipaddress=192.168.1.105;

user=username;

password=yourpassword;

Of course my Hub’s address is 192.168.1.105 and “username” is your username for your Hub and “password” is yourpassword for your Hub.

Example of L16.on:

ipaddress=192.168.1.105
user=username;
password=yourpassword;
echo L16 on
curl http://$user:$password@$ipaddress:25105/3?0263BC00=I=3
sleep 1
curl http://$user:$password@$ipaddress:25105/3?0263B280=I=3
echo done
# done

Example of L16.off:

ipaddress=192.168.1.105;
user=username;
password=yourpassword;
echo L16 off
curl http://$user:$password@$ipaddress:25105/3?0263BC00=I=3
sleep 1
curl http://$user:$password@$ipaddress:25105/3?0263B380=I=3
echo done
# done

Following is my turnRadios.on and have a similar turnRadios.off that are executed when I either turn on my system or turn off my system. I am only including the turnRadios.on file:

# turn on X10 units.
#echo off
#:Start

ipaddress=192.168.1.105
user=username;
password=yourpassword;

# for informatin on how to format message to send on/off to X10
# check http://www.madreporite.com/insteon/x10.html
# check http://www.madreporite.com/insteon/plm_basics.html
# 280 end bytes is ON and 380 is OFF. =I is imediate ad =3 is iterations

# H16 in my setup is a Master others will not run on if H16 is not on first
echo H16 on
curl http://$user:$password@$ipaddress:25105/3?0263DC00=I=3
sleep 1
curl http://$user:$password@$ipaddress:25105/3?0263D280=I=3
sleep 1
# H1
echo H1 on
curl http://$user:$password@$ipaddress:25105/3?0263D600=I=3
sleep 1
curl http://$user:$password@$ipaddress:25105/3?0263D280=I=3
sleep 1
# H2
echo H2 on
curl http://$user:$password@$ipaddress:25105/3?0263DE00=I=3
sleep 1
curl http://$user:$password@$ipaddress:25105/3?0263D280=I=3
sleep 1
# H3
echo H3 on
curl http://$user:$password@$ipaddress:25105/3?0263D200=I=3
sleep 1
curl http://$user:$password@$ipaddress:25105/3?0263D280=I=3
sleep 1
# H4
echo H4 on
curl http://$user:$password@$ipaddress:25105/3?0263DA00=I=3
sleep 1
curl http://$user:$password@$ipaddress:25105/3?0263D280=I=3
sleep 1
# H5
echo H5 on
curl http://$user:$password@$ipaddress:25105/3?0263D100=I=3
sleep 1
curl http://$user:$password@$ipaddress:25105/3?0263D280=I=3
sleep 1
# H6
echo H6 on
curl http://$user:$password@$ipaddress:25105/3?0263D900=I=3
sleep 1
curl http://$user:$password@$ipaddress:25105/3?0263D280=I=3
sleep 1
# H7
echo H7 on
curl http://$user:$password@$ipaddress:25105/3?0263D500=I=3
sleep 1
curl http://$user:$password@$ipaddress:25105/3?0263D280=I=3
sleep 1
# H8
echo H8 on
curl http://$user:$password@$ipaddress:25105/3?0263DD00=I=3
sleep 1
curl http://$user:$password@$ipaddress:25105/3?0263D280=I=3
sleep 1
# H9
echo H9 on
curl http://$user:$password@$ipaddress:25105/3?0263DD00=I=3
sleep 1
curl http://$user:$password@$ipaddress:25105/3?0263D280=I=3
sleep 1
# H10
echo H10 on
curl http://$user:$password@$ipaddress:25105/3?0263DF00=I=3
sleep 1
curl http://$user:$password@$ipaddress:25105/3?0263D280=I=3
sleep 1
# H11
# echo H11 on
# curl http://$user:$password@$ipaddress:25105/3?0263D300=I=3
# sleep 1
# curl http://$user:$password@$ipaddress:25105/3?0263D280=I=3
# sleep 1
# H12
# echo H12 on
# curl http://$user:$password@$ipaddress:25105/3?0263DB00=I=3
# sleep 1
# curl http://$user:$password@$ipaddress:25105/3?0263D280=I=3
# sleep 1
# H13
# echo H13 on
# curl http://$user:$password@$ipaddress:25105/3?0263D000=I=3
# sleep 1
# curl http://$user:$password@$ipaddress:25105/3?0263D280=I=3
# sleep 1
# H14
# echo H14 on
# curl http://$user:$password@$ipaddress:25105/3?0263D800=I=3
# sleep 1
# curl http://$user:$password@$ipaddress:25105/3?0263D280=I=3
# sleep 1
# H15
echo H15 on
curl http://$user:$password@$ipaddress:25105/3?0263D400=I=3
sleep 1
curl http://$user:$password@$ipaddress:25105/3?0263D280=I=3
sleep 1
# H16
echo H16 on
curl http://$user:$password@$ipaddress:25105/3?0263DC00=I=3
sleep 1
curl http://$user:$password@$ipaddress:25105/3?0263D280=I=3
#

Probably now I should show the definitions for HouseCodes and UnitCodes.

HouseCodes:

A  = 6

B  = E
C  = 2
D  = A
E  = 1
F  = 9
G  = 5
H  = D
I  = 7
J  = F
K  = 3
L  = B
M  = 0
N  = 8
O  = 4
P  = C

UnitCodes:

1   = 600

 2   = E00
 3   = 200
 4   = A00
 5   = 100
 6   = 900
 7   = 500
 8   = D00
 9   = 700
10  = F00
11  = 300
12  = B00
13  = 000
14  = 800
15  = 400
16  = C00

Then there are the command codes:

On          = 280
Off         = 380
All On   = 180
All Off  = 680
Bright  = 500
Dim      = 480

Just to add I do a DoStartup.bat file in Windows 10 x64 that is basically my turnRadios.on file from my Ubuntu RPi 16.04 insteon\ directory with a minor changes to run in Win 10 x64. My shutdown is just a another link to a turnRadios.off which is just the 280 changed to 380 in the command section from above. Believe it or not I still use this page for my references to get things done on curl for Insteon and X10.

I hope this better explains on how I use curl to control my Radios at startup and shutdown of my computer. I also use it from my Android Phone with an app called SSH button by: David Grootendorst and I am using Version 1.33. If you have any questions on this article please do not be afraid to ask. After all it was written to help someone maybe even more than one.

The following is a collection of information I got from Insteon and other websites that helped me setup to send the TWO line command string to the Hub.

#1: the format of the HouseCode and UnitCode and is much better explained here: http://www.leftovercode.info/smartlinc_x10.html (defunct)

#2: This link gives a good breakdown of the command line: http://blog.automategreen.com/post/insteon-hub-switch-control

#3: The SmartHome Forum was helpful in understanding also: http://forum.smarthome.com/topic.asp?TOPIC_ID=13762

#4: http://www.richstevenson.com/2014/01/06/insteon-direct-commands/ for setting up for dim/bright

# 5 http://www.prodigyproductionsllc.com/articles/automation/home-automation-with-x10-insteon-python-part-5/ for h=HouseCodes, UnitCodes and CommandCodes, by LuCus

 

 

 

Advertisements