2

iTach python example

I thought I'd contribute this to the community since it took me a little while to figure out how to get this right. It shows how to send a command to an iTach CC and how to handle the return values using sockets in python. It can get tighter/cleaner, but I left it very basic so it's easier for people to play with.

#!/usr/bin/python

import socket

HOST2 = '192.168.1.201'

PORT2 = 4998

s = socket.socket( socket.AF_INET, socket.SOCK_STREAM)

s.connect((HOST2, PORT2))

s.sendall("setstate,1:2,0\r")

response = s.recv(24) #This is the echo back from iTach

print "Response from send():", response

s.sendall("getstate,1:2\r")

state = s.recv(24)

if ( int(state[10:11]) == 1 ):

  print "Current state is ON"

elif ( int(state[10:11]) == 0 ):

  print "Current state is OFF"

else:

  print "Unknown. Got:", state

7 comments

Please sign in to leave a comment.