Author Topic: Insteon 2412N Addition?  (Read 2319 times)

trippleg

  • Regular Poster
  • **
  • Posts: 25
    • View Profile
Insteon 2412N Addition?
« on: November 08, 2011, 05:06:07 pm »
I am new to Linuxmce, and the home automation scene, but I have an Smartlinc 2412N.  I have learned that is has a raw port open 9761 that allows for PLM much like the USB or serial versions.  I am wondering if anyone can point me in the right direction on getting this to work.  I noticed that LinuxMCE uses Python, I am not much of a developer, but I am sure I can learn.  I found some code that allows for communication at  github(dot)com/zonyl/pyinsteon.  I have also written some perl code that works with the raw plm as well posted below.  Any advise or help is greatly appreciated.


#smartlinc.pl

use IO::Socket;

$socket = new IO::Socket::INET (
                                PeerAddr  => '192.168.0.112', #SetAddress of Smartlinc
                                PeerPort  =>  9761,       #Defaultport number of smartlinc
                                Proto => 'tcp',
                             )
or die "Couldn't connect to Server\n";

while (1)
{

#used to test input to smartlinc User friendly loop
      print "Type Command for Smartlinc( Type x to Exit):";

      $input_data = <STDIN>;
      chop($input_data);
      $send_data_hex = pack("H*", $input_data), "\n";


      if ($input_data ne 'x' and $input_data ne 'X')
      {
              $socket->send($send_data_hex);
      }
      else
      {
          close $socket;
          last;
      }
#receives and Prints smart linc return response in ASCII
  $socket->recv($recv_data,1024);
  print "Smartlinc Replied:", unpack("H*", $recv_data), "\n" ;


Thanks.

-Gregg

trippleg

  • Regular Poster
  • **
  • Posts: 25
    • View Profile
Re: Insteon 2412N Addition?
« Reply #1 on: November 08, 2011, 05:40:34 pm »
I have  found some ruby code as well that will communicate with the Smartlinc.  I am posting it for reference as well. It is not my code and I do not remember where I found it. Maybe this will help, or maybe someone can tell me how to get it to work.

#!/usr/bin/ruby

require 'socket'
require 'fcntl'
require 'pp'

def hexlify(msg)
    msg.split("").collect { |c| c[0].to_s(16) }.join
end

def unhexlify(msg)
    msg.scan(/../).collect { |c| c.to_i(16).chr }.join
end

class ChatClient

    def initialize
        @client = nil
    end

    def start(hostname=HOST, port=PORT)

        puts "client connecting to server #{hostname} @ #{port}"
        @client = TCPSocket.new(hostname, port)
        reading = Array.new
        reading.push(@client)
        STDIN.fcntl(Fcntl::F_SETFL,Fcntl::O_NONBLOCK)
        reading.push(STDIN)

        while true
            ready = IO.select(reading)
            readable = ready[0]

            readable.each do |socket|
                if socket == @client
                    buf = socket.recv_nonblock(1024)
                    if buf.length == 0
                        puts "omg, the server is dead, bye!"
                        exit
                    else
                        puts "Received Response: #{hexlify(buf)}"
                    end
                else
                    buf = socket.read
                    if buf.length > 1
                        @client.send(unhexlify(buf), 0)
                    end
                end
            end
        end
    end

end

HOST = '192.168.0.112'
PORT = 9761

client = ChatClient.new
client.start


tschak909

  • LinuxMCE God
  • ****
  • Posts: 5501
  • DOES work for LinuxMCE.
    • View Profile
Re: Insteon 2412N Addition?
« Reply #2 on: November 08, 2011, 09:43:00 pm »
a couple of things:

* You should read the page on "Developing a DCE device" on the wiki, this is the approach to writing a C++ device.

* you should read any pages in the wiki which have GSD, or Generic Serial Device in them. This is the Ruby interpreter to write a DCE device in Ruby, should you decide to go this route.

Basically, you need to create a new device template as a start in the Web Admin, for your PLM device. You can use the Insteon PLM device as a reference.. (190x something, I forget the exact #), If the device is TCP, you can do the device in GSD, at which point the conn_. object becomes a connection to the device, and you can send and receive data and do the appropriate thing.

-Thom

trippleg

  • Regular Poster
  • **
  • Posts: 25
    • View Profile
Re: Insteon 2412N Addition?
« Reply #3 on: November 08, 2011, 10:00:24 pm »
Thanks.  I will take a look at the wiki.  I am hoping I can use the existing PLM template.  The only difference is my device uses TCP/IP instead of a serial or usb connection.  The PLM commands are the same.

-Gregg

Aviator

  • Veteran
  • ***
  • Posts: 79
    • View Profile
Re: Insteon 2412N Addition?
« Reply #4 on: November 08, 2011, 10:29:20 pm »
The template is 1932 for the Insteon PLM GSD device. As tschak909 suggests, reading up on DCE will help.  For examples of IP based GSD devices, run this query in the pluto_main database:

select PK_DeviceTemplate, Description from DeviceTemplate Where IsIPBased=1 and CommandLine = 'Generic_Serial_Device';

If the commands are the same, it shouldn't be hard to get them working.

trippleg

  • Regular Poster
  • **
  • Posts: 25
    • View Profile
Re: Insteon 2412N Addition?
« Reply #5 on: November 09, 2011, 09:30:03 pm »
Ok I did some reading on GSD, created a template, but I have some questions.  According to the wiki If I am adding an Ethernet connection I need to add " TCP Port (#69) to the device data."  My device requires a port number as well.  So my questions are: 
1. Does the TCP Port #69 represent a port number, or the IP address? 
2.If it is the Port# do I need to add the IP address separately or use the default field from when the device is created? 

My current config Shows TCP port #69 as the port number 9761, and IP address is populated in the default IP field that was created with the device.  Am I missing something?  I have run a wire shark and the data does not hit the network. 

Is there a way to look at the commands as they are being sent by LinuxMCE through the command line?

Thanks.

-Gregg

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5501
  • DOES work for LinuxMCE.
    • View Profile
Re: Insteon 2412N Addition?
« Reply #6 on: November 09, 2011, 10:14:32 pm »
Great work so far, Gregg!

To answer your questions:

* the TCP Port is literally the port # to connect to. the IP address is not specified in the device template, but rather, is provided when the device is created (either manually, or via the plug and play mechanism). It is worth noting that with IP devices, the plug and play system provides a way to match network devices via MAC address ranges. If this isn't possible, there are other options (the system in the end doesn't care, it just wants to receive a device detected event if something is found)
* Each device entry in the device tree has an entry for IP address and MAC address, if wanted. These can be used by your device appropriately.

You can look at various log files. The most useful for you is to watch the interaction between the router and other devices, the DCE router log. You can either view this by selecting the DCERouter device in the device tree of  advanced > configure > devices section of the web admin, OR, you can tail -f /var/log/pluto/DCERouter.log on the core.

In addition, each device # created, has its own log file, under  /var/log/pluto. If your new device # is 62, then your device is 62_Generic_Serial_Device.log, this is because the Command Line specified in the device template is indeed Generic_Serial_Device for ruby devices.

-Thom

trippleg

  • Regular Poster
  • **
  • Posts: 25
    • View Profile
Re: Insteon 2412N Addition?
« Reply #7 on: November 10, 2011, 12:31:31 am »
Ok.  A bit more progress.  I am able to get it to send a command, and I can see it in wireshark. I have some more questions.
Wireshark shows a SYN, but no ACK. Is there a way to change the timeout on the SYN?

Here is a bit of my log...

01   11/09/11 14:42:18.001      Ruby was unable to handle the command in reasonable amount of time <0xb5814b90>
05   11/09/11 14:42:20.206      Socket::ReceiveData 0x9b2f658 failed, bytes left 0 start: 42940000 1: 0 1b: 0 2: 0 2b: 0 m_Socket: 8 Command_Impl1 Dev #52 <0xb5814b90>
05   11/09/11 14:42:20.207      Socket::ReceiveString2 ReceiveData failed m_Socket: -1 Command_Impl1 Dev #52 <0xb5814b90>
01   11/09/11 14:42:20.207      Receive string failed in HandleRequestSocket 18:ReceiveData failed Command_Impl1 Dev #52 <0xb5814b90>
05   11/09/11 14:42:20.207      Dumping 1 locks <0xb5814b90>
05   11/09/11 14:42:20.207      finished check for exceptions <0xb5814b90>
05   11/09/11 14:42:20.207      OL: (0x9b2f7a4) (>75) MessageQueue Command_Impl.cpp l:822 time: 4:00:00p (1320878540 s) thread: 3053542

Thanks.

-Gregg
« Last Edit: November 10, 2011, 12:39:55 am by 3gem »

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5501
  • DOES work for LinuxMCE.
    • View Profile
Re: Insteon 2412N Addition?
« Reply #8 on: November 10, 2011, 12:56:09 am »
May I see snippets of the relevant code?

-Thom

trippleg

  • Regular Poster
  • **
  • Posts: 25
    • View Profile
Re: Insteon 2412N Addition?
« Reply #9 on: November 10, 2011, 05:25:01 pm »
I am using the code from template 1932.  It was setup originally for a serial device, but I do not see anything in the code that marries it to serial.  I was able to get an ACK from the Smartlinc last night, LinuxMCE is issueing keep allives. Now I just have to figure out the problem I fear it may be in the code.  I get the following error when I issue a command from the command line.


 /usr/pluto/bin/MessageSend localhost -r 0 53 1 193 97 ""
RESP: Delivery failed



Thanks.

-Gregg
« Last Edit: November 10, 2011, 07:22:32 pm by 3gem »

trippleg

  • Regular Poster
  • **
  • Posts: 25
    • View Profile
Re: Insteon 2412N Addition?
« Reply #10 on: November 14, 2011, 07:22:35 pm »
Ok I think I have made a bit more headway.  I added #163 assign to parents room to my template and now it can automatically see children in the Insteon database and displays them in the log for that device.  My problem now is creating children and keeping them.  I create a child for the thermostat and give it the appropriate address, but when I reload the router the child disappears. 

Am I missing a step.

Thanks.

-gregg

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5501
  • DOES work for LinuxMCE.
    • View Profile
Re: Insteon 2412N Addition?
« Reply #11 on: November 14, 2011, 07:28:02 pm »
the driver itself currently only supports lighting and a few other small class of devices, that are automatically introspected by querying the device database of each insteon device in the network.

you would need to add support for interfacing with the climate and security features of the system.

The reason the devices are disappearing is because the GSD device in question uses the Report Child Devices DCE command to return a list of devices found, and their equivalent device data for port mappings, device templates to use etc.. If the system already sees that these devices exist, they are left alone. If a device doesn't appear on that list, it is deleted from the children.

-Thom

trippleg

  • Regular Poster
  • **
  • Posts: 25
    • View Profile
Re: Insteon 2412N Addition?
« Reply #12 on: November 14, 2011, 10:37:50 pm »
the driver itself currently only supports lighting and a few other small class of devices, that are automatically introspected by querying the device database of each insteon device in the network.

you would need to add support for interfacing with the climate and security features of the system.

The reason the devices are disappearing is because the GSD device in question uses the Report Child Devices DCE command to return a list of devices found, and their equivalent device data for port mappings, device templates to use etc.. If the system already sees that these devices exist, they are left alone. If a device doesn't appear on that list, it is deleted from the children.

-Thom

My log shows it detects the device in question.
Code: [Select]
(***):InsteonID:14.26.57seems to exist in child databases
(***):CDB:{"0F.63.82"=>["****************"], "14.26.57"=>["****************"], "13.7B.60"=>["000B1801********", "E201142657050391"]}
(***):^[[36m
From Device:13.7B.60
Flags:
Not the last record
Record In Use
I am a Controller of 14.26.57 Group:1^[[37m

Within the code #756 Child Devices there is a device defined for the Venstar Thermostat I have.

Code: [Select]
when 0x05 # Climate Control
case $childdatabases[insteonID][0][2..3].hex
when 0x00; @work += 'Broan SMSC080 Exhaust Fan'
when 0x01; @work += 'Simplehomenet EZTherm'
when 0x02; @work += 'Broan SMSC110 Exhaust Fan'
when 0x03; @work += 'Venstar RF Thermostat Module'
when 0x04; @work += 'Simplehomenet EZStat Thermostat'
end

Is there another place I need to add the code?  Do I need to add a Template specifically named Venstar RF Thermostat Module?


Thanks.

-Gregg

« Last Edit: November 14, 2011, 10:39:44 pm by 3gem »

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5501
  • DOES work for LinuxMCE.
    • View Profile
Re: Insteon 2412N Addition?
« Reply #13 on: November 14, 2011, 11:05:07 pm »
I am not sure, honestly. I did not write the code. ddamron did.

-Thom

trippleg

  • Regular Poster
  • **
  • Posts: 25
    • View Profile
Re: Insteon 2412N Addition?
« Reply #14 on: November 15, 2011, 12:14:18 am »
Well at least you gave it a shot Thom :)

Do you know of a way I can get a hold of ddamron?  In the mean time I will plug away at it and see if I can figure it out.  As far as I can tell the template I created for the 2412N should work for other Insteon add ons.  How do I submit it for others to test??

-Gregg