Hi, Since the automated webserver that was advertised with the device isn't ready yet. I was wondering if its possible to send a command using json http. I read there is an API for it however its above me. I am trying to close my infrared curtains at sunset. I thought I'd be able to write a script if I could get the flex to receive the commands via http. Cheers
25 comments
-
Simon Rb Or maybe write a script? Has anybody got a template so all the has to be added would be the flex's details (ip address etc..) and infra red codes? Cheers -
Josh Sherman Attached is a script necessary to learn and retransmit IR codes via a browser. This logic should allow you to get your desired setup working.
IR Learn and Retransmit.zip -
Simon Rb Thank you Josh, after looking at the files I have no idea how to implement this? I was hoping to get a program I'm using to control my house called domoticz and I was hoping that could run the scripts at sunset and sunrise unfortunately it's a bit above my technical know how.. -
Scottin Pollock Simon,
If the computer you're running has an implementation of python on it, the following script should work for you...
#!/usr/bin/python
import socket
HOST2 = '<addressOfGCUnit>'
PORT2 = <portOfGCUnit>
s = socket.socket( socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST2, PORT2))
s.sendall("<commandCode>\r")
response = s.recv(24) #This is the echo back from iTach
print "Response from send(<whateverStringYouWantToGetBack-OPTIONAL>):", response -
Simon Rb Hit Scottin, Thank you for your post. My current setup is a Raspberry PI runninng Wheezy, this little box runs SiriProxy, Domoticz and a basic squeeze server for when the main server is off. Would I be able to run the script from that? What I need to do for the flex/script to learn my codes to close my curtrains. There is 3 codes per curtain and 3 curtains - so 9 codes. I currently have them saved in a txt document if this helps. I was hoping for some way to get Domoticz to run the script at sunset which shouldn't be a problem - first off I'll need a working script. This is all very new to me and i'm trying to learn.. Thank you very much. -
Simon Rb I was a bit tired when I first read your script, was 4am and getting ready for work.
Looking at your script if I fill in the flex details and under the sendall is that where I paste my codes - all 9 of them. I may need a pause between sending each code as I have noticed sending them too close together some of the codes are not picked up.
Cheers. -
Scottin Pollock Haven't played with that device or "Wheezy", but what I know of it, its running a flavor of linux. If that is indeed the case there is probably a Python binary available for it (if not already there).
You'll need a separate s.sendall line for each code you want to send. If you need to insert delays use...
import time
time.sleep(<numberOfSeconds>)Floating point numbers are supported. When replacing syntax template items, be sure to remove the angle brackets.
-
Simon Rb Hi, Lovely, thank you Scottin. Once I receive my Flex back i'll give this a go. Cheers bud -
Simon Rb Hi, So using the new protocol can I just type this into a browser address bar and hit enter? base url/ir ports/irportnumber/sendir Obviously replacing the fields with the relevent data. Or is there more to it -
Scottin Pollock It is not a protocol, it is a python script. I am not familiar with the web server on a flex but I would guess the simplest way to call this from a browser would be from a CGI request.
-
Simon Rb Thanks for your reply. There is a new http API out which is what I thought I could communicate with.. I have not tried your script yet. To be honest I have never used a script and just researching how to run it. Assume I just copy it to a folder and then run it... -
Scottin Pollock Not sure why you want to do this over http... seems more complicated to me if all you want to do is run a script at a certain time of day. Why not just use cron to run it?
-
Simon Rb If I could get it to work over http then I could also get siriproxy to send the same codes easily. Sorry to be completely stupid however what is Cron? I can setup domoticz to run the script at sunset, I've never used a script before. Once written I assume I point domoticz to this script and it should run. Fingers crossed eh.. -
Scottin Pollock Don't know what siriproxy or domoticz is, or whether they can execute shell commands like 'python myScript.py'... but that is what you need to run a script.
Cron is a linux/unix binary designed to execute commands based on day/time statements in a table (crontab).
-
Simon Rb I'll look into Cron, see if it can grab sunset times. This is my script. does it look correct? #!/usr/bin/python import socket HOST2 = '' PORT2 = s = socket.socket( socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST2, PORT2)) s.sendall("sendir1:1.14000.1.34 .34.53.63.76.86.4.02\r") response = s.recv(24) #This is the echo back from iTach print "Response from send():", response Cheers bud -
Simon Rb #!/usr/bin/python import socket HOST2 = '' PORT2 = s = socket.socket( socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST2, PORT2)) s.sendall("sendir1:1.14000.1.34 .34.53.63.76.86.4.02\r") response = s.recv(24) #This is the echo back from iTach print "Response from send():", response Sorry I reposted your example by mistake. Also, Domoticz uses Lua for its events and scripting if thats help. I did post your example script and it was said it may not work however they are unsure. I'll try it however I think I may have to go down the http api route if I get no joy - appreciate your help and how something so simple is so difficult for a simple mind like mine lol -
Simon Rb Ok, every time I post the script on here some of it disappears.. strange.. -
Simon Rb Hi, I'm going to try the HTTP stuff however I have no idea how to use it. I have tried to google it however iam more confused now then what I was 2 ads ago.. How do I implement this stuff? For example how do I use this command just to get version number... HTTP/1.1 GET /version where: is "http:///api/v1" Where is this typed? In the address bar? In a file? I have no idea!!! Please help.. -
Scottin Pollock I don't know what to tell you. You can't learn html and JS in an online forum. The version command is a simply 'get' request, and can be typed in the browser's address bar:
http://xxx.xxx.xxx.xxx/api/v1/version
However, according to the flex documentation, IR commands must use the 'post' method. You can not construct a 'post' request in the address bar.
You're not stupid. Nor is this designed to be simple for the layperson. You're simply trying to avail yourself of a web programming interface, with no prior knowledge or experience in programming for the web, so there is little wonder as to why you are stuck here. I don't have a flex, so I don't know if there are any 'sample' html files on the unit other than the standard config files. But even if there are, you'll need some modicum of web development experience to understand them and create the functionality you are looking for.
-
Simon Rb Cheers Scottin,
There is some documentation about sending ir commands via the post method. Something like:-
When sending IR commands to a Flex unit via HTTP, an HTTP POST is used to send the JSON packet as shown below. HTTP/1.1 POST
/irports//sendir
Header Values:
"crossDomain" must be true if issuing this command from the web page of a different Flex unit
“frequency”:“”, “preamble”:“”, “irCode”:“”, “repeat”:“”
} where:
is the frequency of the command in hertz (Hz)
is a comma separated list of numeric values signifying the first portion of the IR command that is only fired once. This portion is not repeated when using a repeat count. is a comma separated list of numeric values signifying the full IR command when not using a preamble. This portion of the code is repeated when using a repeat count.
is the number of times that the is to be repeated after sending the preamble of the command in the case that it is used.
Is that all that is required for a post command? If so where would it go? In the mean time I will try and get your script to run, however I have never even done that before. Would I save it as a .py file and the. Try running it from the command terminal first to make sure it works? -
Simon Rb Right, I have installed python for windows and copy and pasted your script and save it as test.py. I doesn't seem to work so I have done something wrong.
The flex ip address is 192.168.1.70 Port is 4998 the test command to send is
sendir,1:1,1,40000,2,1,96,23,49,23,24,23,49,23,24,23,49,23,24,23,24,23,49,23,24,23,24,23,24,23,24,1033
How would this look in your script? Sorry for being a pain. Once I have a working script I can usually see how it all works and modify it to operate the curtains and adding your import time
time.sleep(<numberOfSeconds>) command.Cheers bud
-
Liran the python script works very well - thanks.
pay attention that the port for TCP connection is 4998.
-
Cesar Simon, did you have any luck with this set up? I've also got Siriproxy running on my Pi and would also like to send commands to trigger events that I have pre-programmed using Roomie Remote.
Cheers,
CJ
-
Deep Batra Hi All,
I am completely new to GlobalCache and iTach products. I have a iTach IP2IR and have managed to use the iLearn and iTest without any problems to control my HDMI Switcher via iR. Now I would like to program the IP2IR device to do what is sent over http. I tried learning on the API-Flex_HTTP.pdf file but could not go through the first section even. I tried to type http://172.18.103.6/api/v1/version and it does not show anything. Just a blank page. May I know where I can learn how to program the IP2IR?
Thank you.
Regards
Deep Batra, Tung Wah College,
Hong Kong -
Garrett Gustafson Hi Deep Batra,
The IP2IR does not have an HTTP API. The Flex HTTP document you referenced is for the iTach Flex family of products which is currently the only family that supports a HTTP API. If you would like to learn more about controlling the IP2IR through its TCP API please feel free to take a look at the iTach API here, start a new topic in the iTach user forum, or send a ticket into support@globalcache.com.