| Author |
Topic  |
|
snewman
Junior Member
 
USA
49 Posts |
Posted - 01/26/2011 : 07:50:49 AM
|
Has anyone done anything with the socket on port 9761? I tried MiCasa for the iPhone and saw that it uses it. I haven't put wireshark on it yet to see, but I've seen info indicating it's a TCP socket that sends/receives serial bytes.
I'd love to document this if anyone has any info or experience with it.
|
|
|
Kcspaceman
Starting Member
Canada
7 Posts |
Posted - 02/02/2011 : 08:31:07 AM
|
Another developer I know of has probed this issue a bit and has very recently written a blog post about it, you can see it online here: https://www.shion[ restricted ]/2011/01/smartlinc-2414n-undocumented-ports-ftw/
Basically yeah, it's a pass-through port of sorts that talks the same language as the serial PLMs. He has a link to his code implementation too in that link above. |
 |
|
|
jdale
Advanced Member
    
USA
1019 Posts |
Posted - 02/02/2011 : 08:47:36 AM
|
| That could open up quite a bit, if it essentially lets you treat it like a serial PLM. Nice find, thanks for sharing that link. |
Insteon FAQ: http://goo.gl/qNTNr |
 |
|
|
snewman
Junior Member
 
USA
49 Posts |
Posted - 02/02/2011 : 08:49:51 AM
|
I'm happy to give a go at writing a Python script to interface with the serial port if someone knows a sequence of serial bytes I can try. (I don't have experience with the serial bytes yet)
It will be quick-and-dirty, but I'll put it on Github once I have a proof-of-concept. |
 |
|
|
jdale
Advanced Member
    
USA
1019 Posts |
Posted - 02/02/2011 : 09:41:54 AM
|
Just use any of the custom commands, omitting the "http://172.30.1.101/3?" at the beginning and the "=I=3" at the end. And no pauses. The serial command starts with the 02. Every two digits represents a byte.
For example on your page you have an example to turn on the lights:
http://172.30.1.101/3?02620EA7220F11FF=I=3
The bytes to send are 02 62 0E A7 22 0F 11 FF
|
Insteon FAQ: http://goo.gl/qNTNr |
 |
|
|
mdrons@yahoo.com
Starting Member
10 Posts |
Posted - 02/02/2011 : 2:06:35 PM
|
I wrote a perl script that controls the devices in a 2412N controller.
I use this to get the status: http://$ip/buffstatus.xml
To turn a device off: url='3?0262' device='145BFF' command='0F13FF=I=3' echo "http://${smartlinc}/${url}${device}${command}"
${wget} -q -O - "http://${smartlinc}/${url}${device}${command}"
I am controlling 240V INSTEON relay switches for baseboard heaters. The script checks the status of the INSTEON devices and if on for more than 1 hour it shuts them off.
Mike |
 |
|
|
snewman
Junior Member
 
USA
49 Posts |
Posted - 02/02/2011 : 2:21:08 PM
|
I got it to successfully turn on a device with this rough little Python snippet:
import socket
import binascii
HOST = "172.30.1.101"
PORT = 9761
DEVICE = '0EA722'
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
commands = {}
commands['on'] = '02 62 %s 0F 11 FF' % DEVICE
commands['off'] = '02 62 %s 0F 13 FF' % DEVICE
# This turns the Ascii strings (above) into actual binary data
def ascii2bin(command):
bytes = command.replace(' ','')
binary = binascii.unhexlify(bytes)
return(binary)
print "Sending Command: %s" % commands['on']
command = ascii2bin(commands['on'])
s.send(command)
data = s.recv(1024)
s.close()
print 'Received', repr(data)
|
Edited by - snewman on 02/02/2011 2:21:32 PM |
 |
|
|
jdale
Advanced Member
    
USA
1019 Posts |
Posted - 02/02/2011 : 2:54:24 PM
|
| So then the next trick is to see if you can get responses back from the port instead of having to read it out of the buffer... |
Insteon FAQ: http://goo.gl/qNTNr |
 |
|
|
mdrons@yahoo.com
Starting Member
10 Posts |
Posted - 02/02/2011 : 5:13:33 PM
|
| Yes, It would be great to be able to get the status and not have to read buffstatus.xml, as it is not always reliable. |
 |
|
|
snewman
Junior Member
 
USA
49 Posts |
Posted - 02/05/2011 : 12:20:16 PM
|
Hello everyone,
I've done some Python experiments with the serial port on the SmartLinc to see what happens when there is device activity. The results are encouraging!
I wrote a quick Python script to monitor the serial port:
import asyncore
import socket
import binascii
HOST = "172.30.1.101"
PORT = 9761
class SmartLincClient(asyncore.dispatcher):
def __init__(self, host, port):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect((host, port))
self.buffer = ''
def handle_connect(self):
pass
def handle_close(self):
self.close()
def handle_read(self):
received = self.recv(1024)
print "Received: %s" % binascii.hexlify(received).upper()
def writable(self):
return (len(self.buffer) > 0)
def handle_write(self):
sent = self.send(self.buffer)
self.buffer = self.buffer[sent:]
if __name__ == "__main__":
c = SmartLincClient(HOST, PORT)
asyncore.loop()
I ran this in one terminal window, then opened a second terminal window to send HTTP commands via curl to the SmartLinc. (Note: You can also see results if you use the SmartLinc web interface)
First, I sent a curl command to turn device on:
$ curl http://172.30.1.101/3?02620EA7220F11FF=I=3
Here's the last command broken into parts:
0262 0EA722 0F 11 FF + =I=3
Direct Command Flag + Device + SD Flag + Command (on) + Level + Trailing
This is what was returned by the socket program in the other terminal window:
>> Received: 02620EA7220F11FF06
>> Received: 02500EA72216A9442B11FF
Here's the received data broken into its parts:
0262 0EA722 0F 11 FF 06
Direct Command Flag + Device + SD Flag + Command (on) + Level + Unknown
0250 0EA722 16A944 2 B 11 FF
Return Flag + Target Device + SmartLinc + Ack + Hop Count + DB Delta + Level
You'll notice that the first received line is the command we just sent, except the "=I=3" from the URL is replaced with "06". (I have no idea what '06' represents) The second line received is the status of the device. This seems to be returned whenever there is activity.
Next, I sent a curl command to get device status:
$ curl http://172.30.1.101/3?02620EA7220F19FF=I=3
Here's the command broken into parts:
0262 0EA722 0F 19 FF =I=3
Direct Command Flag + Device + SD Flag + Command (status) + Padding + Trailing
This is what was returned form the socket program in the other terminal window:
>> Received: 02620EA7220F19FF06
>> Received: 02500EA72216A9442B00FF
Here's the received data broken down into parts:
0262 0EA722 0F 19 FF 06
Direct Command Flag + Device + SD Flag + Command (on) + Padding + Unknown
0250 0EA722 16A944 2 B 00 FF
Return Flag + Target Device + SmartLinc + Ack + Hop Count + DB Delta + Level
Finally, I sent the curl command to get the device buffer, which you need to do if you want to get device status from HTTP:
$ curl http://172.30.1.101/buffstatus.xml
<response><BS>02620EA7220F19FF0602500EA72216A9442B00FF</BS></response>
Here's the response broken down (with the tags removed):
02620EA7220F19FF 06 0250 0EA722 16A944 2 B 00 FF
Last Command + Response Flag + Return Flag + Target Device + SmartLinc + Ack + Hop Count + DB Delta + Level
Results:
If you compare the second line of received data from all three commands, you'll see they are the same: (with the exception of DB delta, which is some sort of way of keeping track of device activity - I haven't found a need/use for it yet)
Received Line 1 (from curl on) 02500EA72216A9442B11FF
Received Line 2 (from curl status) 02500EA72216A9442B00FF
Received Buffer (from curl buffer) 02500EA72216A9442B00FF (* This is the 2nd half of the response)
What's Next?
Where to go from here? Well, with my earlier experiment, I was able to send data to the serial socket. With this, I was able to receive data. The next thing I'll do is combine them together so I can send and receive data from the same program.
|
Edited by - snewman on 02/05/2011 12:25:01 PM |
 |
|
|
jdale
Advanced Member
    
USA
1019 Posts |
Posted - 02/05/2011 : 2:06:08 PM
|
>> Received: 02620EA7220F11FF06 >> Received: 02500EA72216A9442B11FF
The first line is the command you sent, echoed by the PLM chip (in the Smartlinc). The 06 at the end is an ACKnowledgment that the command was successfully sent (but not necessarily received). If something went wrong with the command, there would be a 15 there instead.
The second line is an incoming message from the other device (0E.A7.22) responding, telling you that it received the command and has done what you asked (turned on). It looks to me like you don't have to look at the buffer at all, these two messages contain the same information.
In the case of the status command, you have the link delta as you say. But in the response to the ON command, that byte of data is actually just echoing the command you sent. The response to a status request is unusual because it puts the link delta in the command1 position instead of the command. (Which is kind of annoying, as the response to a status request isn't necessarily labeled as such, unlike basically every other command.) But for everything else the byte in that position tells you what the message is about.
Depending on how you set up your links, and if you keep track of the responses from devices, you don't necessarily have to always use the status request command. You may already know the status.
This is great stuff, by the way. It looks like you should really be able to do everything this way. |
Insteon FAQ: http://goo.gl/qNTNr |
 |
|
|
jdale
Advanced Member
    
USA
1019 Posts |
Posted - 02/05/2011 : 2:08:55 PM
|
| Oh, also, it seems like this is actually easier than working with a PLM directly. The Smartlinc is at least parsing the different messages apart for you. With a PLM you get them all in a row. |
Insteon FAQ: http://goo.gl/qNTNr |
 |
|
|
stevespaw
Starting Member
2 Posts |
Posted - 02/18/2011 : 1:31:27 PM
|
| Hey folks I have stumbled on this. I want to control an Insteon system with socket commands but cannot find a solution. I just tried this with Telnet and Putty. I get responses but they are garbled. (binary?). Any thoughts on a method to send Ascii command via telnet type of client? |
 |
|
|
jdale
Advanced Member
    
USA
1019 Posts |
Posted - 02/18/2011 : 2:32:37 PM
|
Can you give an example of what you are seeing? It's going to look like a mess of hexadecimal stuff until you interpret it.
I can't provide much input on the telnet/putty side of things, only in interpreting PLM-ese. |
Insteon FAQ: http://goo.gl/qNTNr |
 |
|
|
dt1000
Starting Member
Canada
14 Posts |
Posted - 02/22/2011 : 08:14:41 AM
|
Hi, Chaps, Thanks for all the fantastic info. I've incorporated it into an Event Ghost plug-in for the SmartLinc which works pretty well...
Apart from one problem that I need a little help on:
If I use the plug-in to just send commands it works great. As soon as I incorporate the listening code, it won't send.
You can download the plug-in here: http://www.mediafire.com/?uscuozyjcdp7t And EventGhost can be found here: http://www.eventghost.org/downloads/
Would someone be able to take a look at my Python and let me know what I'm doing wrong?
The plug-in currently has the listener enabled, so if you want to test the commands you'll have to go in and comment out line 359.
(Also, I cobbled this together very quickly, and I've never used Python before, so apologies if the plug-in is a little rough - I will neaten it up and refactor it before release!)
Many thanks, Dan
|
 |
|
|
snewman
Junior Member
 
USA
49 Posts |
Posted - 02/22/2011 : 08:27:45 AM
|
Hi Dan,
Sorry I can't be of any help, I don't use Windows and I'm not familiar with EventGhost. Does it throw any specific errors or does it just silently fail?
If possible, I'd try breaking it down into simple parts - make a simple GUI that just listens for events and make sure it's holding the socket open first. (since that's likely the most fragile part of the code)
-- Scott
|
 |
|
|
dt1000
Starting Member
Canada
14 Posts |
Posted - 02/22/2011 : 09:02:05 AM
|
Hey, SNewman, Thanks for the swift reply. I've basically copied both bits of your code - the send and receive. It looks like the asyncore stuff jams up the port somehow. When I send a command, nothing happens and after a while I get the following error:
[Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
If I comment out the following line, commands work fine... #c = SmartLincClient(Address, Port)
|
 |
|
|
snewman
Junior Member
 
USA
49 Posts |
Posted - 02/22/2011 : 09:18:56 AM
|
quote: Originally posted by dt1000
Hey, SNewman, Thanks for the swift reply. I've basically copied both bits of your code - the send and receive. It looks like the asyncore stuff jams up the port somehow. When I send a command, nothing happens and after a while I get the following error:
[Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
If I comment out the following line, commands work fine... #c = SmartLincClient(Address, Port)
In my SmartLincClient object, the constructor (init) method starts an asyncore socket session that is meant to stay open for the duration of the program's event loop.
It looks like in your scene objects, you are opening and closing sockets manually. This would explain why it gets jammed - the SmartLinc only allows a single socket connection.
Your approach might work, but you won't be able to respond to events that happen on the SmartLinc such as a motion sensor event or a device status change that you didn't initiate. By keeping the socket open with asyncore, you will be notified of these events.
I'm not familiar with EventGhost, but if looks like there is a plugin object constructor on line 311. If you want to keep the socket open, I'd probably try opening it here and assigning it as an instance variable on the object. (like mypluginobject.socket) You'll want to make sure you close it in the __close__ method.
Hope this helps. |
 |
|
|
dt1000
Starting Member
Canada
14 Posts |
Posted - 02/22/2011 : 10:43:44 PM
|
Ah-hah!!!!! Thanks for the help, Scott - I now have my Event Ghost plug-in totally working. :D
All I did was modify the event sending functions to use the asyncore socket.
I have one more question...
My plug-in detects when a network command is used to change the status of an Insteon device (e.g. from my iphone, or another computer). With a little work I can turn this into proper Event Ghost events.
What it DOES NOT do, is detect when a switch on my Insteon network is pressed. Is there any way I can do this using the SmartLinc and Python?
I would really like to be able to set this up with a TriggerLinc or Motion Sensor... http://www.smarthome.com/2421/TriggerLinc-INSTEON-Wireless-Open-Close-Sensor/p.aspx http://www.smarthome.com/2420M/Wireless-INSTEON-Motion-Occupancy-Sensor/p.aspx ...to fire off events on my computer so I can have a JARVIS style welcome when I come home (kinda sad, yes, but also kinda awesome!) |
 |
|
|
snewman
Junior Member
 
USA
49 Posts |
Posted - 02/23/2011 : 07:33:25 AM
|
quote: Originally posted by dt1000 My plug-in detects when a network command is used to change the status of an Insteon device (e.g. from my iphone, or another computer). With a little work I can turn this into proper Event Ghost events.
What it DOES NOT do, is detect when a switch on my Insteon network is pressed. Is there any way I can do this using the SmartLinc and Python?
That's a great question - I don't know the answer, this stuff is still new to me, too. I hope the answer is yes! |
 |
|
|
jdale
Advanced Member
    
USA
1019 Posts |
Posted - 02/23/2011 : 8:38:24 PM
|
You need to link the device (motion sensor, triggerlinc, switchlinc, whatever) as the controller, and the SmartLinc as the responder.
The SmartLinc is not designed to be linked as a responder, so you probably can't do it with button pressing or through the SmartLinc's interface. Instead, put the other device into linking mode and then send a custom command on the SmartLinc, the bytes will be:
02 64 00 00
The fourth byte is the group number. I'm not sure offhand if the value matters when it is going to be the responder.
Once the Smartlinc is linked as a responder you should see the incoming events.
|
Insteon FAQ: http://goo.gl/qNTNr |
 |
|
|
dt1000
Starting Member
Canada
14 Posts |
Posted - 02/24/2011 : 08:46:32 AM
|
Thanks, jdale.
I had a play with things this morning and I can report that if you link the switch to the SmartLinc using the button on the switch and the button on the side of the SmartLinc then you can indeed capture button presses over the network. No direct commands are necessary.
My EventGhost plug-in is now sporting some pretty cool functionality. I just need to neaten it up a bit and then I can release v0.1 ! :)
I'll probably be back at the weekend with some questions about message codes. I've noticed that the ACK and the HOP vary depending on the type of activity that generates them.
Thanks once again to everyone for their help - teamed with Event Ghost the SmartLinc can do some pretty advanced stuff! |
 |
|
|
dt1000
Starting Member
Canada
14 Posts |
Posted - 02/24/2011 : 09:12:09 AM
|
Here is a quick preview of the Event Ghost plug-in...

http://img690.imageshack.us/f/smartlincplugin.jpg/
You can see it catching Insteon activity in the Log window (on the left) and converting them to Event Ghost events.
The top dialog box let you store your scenes and devices. The lower dialog box is an example of how you would set up an Event Ghost Insteon command.
On the right, you can see a list of the supported commands...
:)
Dan |
 |
|
|
jdale
Advanced Member
    
USA
1019 Posts |
Posted - 02/24/2011 : 6:41:10 PM
|
I love that you guys are pushing the SmartLinc this way. I was getting lonely programming Insteon stuff outside of the SDK with hardly any company. ;) I do hope you'll put everything you've found in one place for the future benefit of whoever follows along next, like snewman already started.
|
Insteon FAQ: http://goo.gl/qNTNr |
 |
|
|
dt1000
Starting Member
Canada
14 Posts |
Posted - 02/24/2011 : 11:10:53 PM
|
For sure, jdale. My plan is to post the plug-in on the Event Ghost forums and open it up for other people to improve.
I just set up Event Ghost so that it speaks the weather forecast to me when I press a light switch! :D Looks like I'll be ordering some motion sensors...
In the meantime, I have a question about direct commands.
I would like to set the brightness level and ramp rate of a scene. One would think that there is a direct command that I can send to the SmartLinc that would do this.
I read through the Insteon documentation and I must confess that it was all Greek to me. Do you guys have any idea what such a command might look like?
If you give me some pointers, I will test it out right away.
Cheers, Dan |
 |
|
|
Tfitzpatri8
Administrator
    
USA
6962 Posts |
Posted - 02/25/2011 : 05:55:41 AM
|
You can send an On, Off, Bright, Dim, Fast On or Fast Off signal to an Insteon scene.
When you create a scene you program each device with its own dim level and ramp rate as part of the scene. After turning a scene on, you can send Bright and Dim signals to adjust all scene members up or down. If you want to send a single signal to have all devices in a scene go to a different level, you create a different scene. Most devices support membership in several hundred scenes to allow for this design.
|
Volunteer Moderator & Home Automation Enthusiast |
 |
|
|
dt1000
Starting Member
Canada
14 Posts |
Posted - 02/25/2011 : 08:43:29 AM
|
Thanks for the info, Tfitzpatri8.
quote: When you create a scene you program each device with its own dim level and ramp rate as part of the scene.
How would I do this? Is there a series of direct commands I can use? As it stands, the SmartLinc does not support this level of detail for scene creation.
Sorry if that is a noob question, by the way!
:)
Dan |
 |
|
|
Tfitzpatri8
Administrator
    
USA
6962 Posts |
Posted - 02/25/2011 : 08:57:38 AM
|
Full Owner's Manual is here: http://wiki.smarthome.com/index.php?title=SmartLinc_-_INSTEON_Central_Controller_Owner's_Manual_(v2.0%2B)
To add devices to a scene, see the section entitled "Linking SmartLinc to an INSTEON Device". You use the Add button on the SmartLinc interface and the Set button on the responding device. You can link as many devices as you want to the same scene by repeating the directions for each device you want to add to the same scene. |
Volunteer Moderator & Home Automation Enthusiast |
 |
|
|
jdale
Advanced Member
    
USA
1019 Posts |
Posted - 02/26/2011 : 07:06:35 AM
|
Here's a much more complete list of commands: http://www.madreporite.com/insteon/commands.htm The standard direct commands are the ones relevant. Not all of them will be suitable to send to scenes.
In addition to on, off, dim (by one step), bright (by one step), fast on, and fast off, there's also Start Manual Change which I know will work to a group/scene. |
Insteon FAQ: http://goo.gl/qNTNr |
 |
|
|
dt1000
Starting Member
Canada
14 Posts |
Posted - 02/26/2011 : 11:22:18 PM
|
Thanks again for the info. I read through the instructions, and the technical papers for Insteon commands, but I can't work out the correct one...
Looking at the web page from jdale's post, it looks like command 0x2E - 46 - Extended Set/Get might do what I need... But when I try sending it to a switch, or the Smart Linc, I get the following response:
026216F9172E00070100000000000800000000000015
Which, from the 15 at the end, looks like nothing was received.
Any suggestions? Just to remind everyone: I am trying to set the brightness level that a scene turns on at, using a direct command.
Thanks, Dan |
 |
|
|
jdale
Advanced Member
    
USA
1019 Posts |
Posted - 02/27/2011 : 3:57:23 PM
|
The 15 at the end (NAK) indicates that for some reason the message was not correctly sent by the Smartlinc. The problem is before/during transmission, it's not the device telling you it wasn't received. Typically if you get that it is telling you that you have the command wrong. Doublecheck the number of bytes, etc.
In this case I think you have omitted the flags byte.
02 62 - send an insteon command 16 F9 17 - to device 16.F9.17 - next byte should be the flags byte, typically 0F for a standard message and 1F for extended 2E - command 1 00 - command 2 and then 14 data bytes for an extended message, looks like you have this part right
|
Insteon FAQ: http://goo.gl/qNTNr |
 |
|
Topic  |
|