Is there a Data Source that I configure to send a command over TCP/IP to a LAN connected IP device
-
Perhaps you could write a system script (python, perl, bash, ruby etc.) that performs the action, and invoke it using the 'process' type point event detector.
From the manual:
This handler will execute a local process, or shell command, optionally when an event is raised or deactivated. The respective commands can be any shell command appropriate to the host. Commands should be specified as they would be from a terminal command prompt. For very complex commands, you may find it convenient to write a shell script, and then call the script from Mango
I don't know much python at all but I think it would be fairly trivial to write two small scripts that opens a TCP socket and writes the data to open/close the relay. This page should help you: http://www.binarytides.com/python-socket-programming-tutorial/
Hell, if you can put the device online, I'll even attempt it as a learning exercise for myself.
-
Actually it would appear that the manufacturer has implemented control via 'HTTP get':
From: http://www.robot-electronics.co.uk/htm/eth002tech.htm
HTML commands DOAx and DOIx (V4+ firmware needed)
Another customer requested feature, allowing the digital outputs to be switched by the http get function such as used in some voice over ip phones (VOIP). You can use the http get function to write to the io.cgi file with the following syntax:
192.168.0.200/io.cgi?DOA2=10
This would use the default address (192.168.0.200) and make output 2 active for 1 second.
Another example would be to set output 1 inactive for 10 seconds:
192.168.0.200/io.cgi?DOI1=10
You can test these functions by typing them directly into the address bar of most internet browsers. Also be aware that you may need to disable http authentication in the http configuration if your control device does not support it.In which case you may be able to use the Mango 'HTTP Retriever' module to do you what you want (not sure how exactly) or at least your Python etc. script will become a lot easier. See this page: http://stackoverflow.com/questions/645312/what-is-the-quickest-way-to-http-get-in-python
-
Thanks Jeremy!
The easiest in theory would be through javascript in source Metapoints.
I have a two javascript .js files that can send a TCP/IP message to the device and turn a relay on and off. See attached.
If I run them through the java -jar rhino.jar console it works. If I try to run in the script box of Source Meta Point the same command: load("c:/test1.js") . I get error message:
"Script error: sun.org.mozilla.javascript.EcmaError: ReferenceError: "load" is not defined. (#1) in at line number 1 in at line number 1"
Supposedly Mango Javascript uses Rhino.
Attachment: download link
-
Even though the Meta point scripting language is Javascript-like, I don't think you can do what you want with a Meta point. I think it is too 'sandboxed'.
Maybe, maybe you can do it through this way using the Scripting data source, but I doubt it.
I still think the best way to do it would be to write two python scripts that set the relay on/off, then invoke these through a point event detector that runs a system process.
If you want a hand with that I'm happy to help, I am not expert though so I would be learning too.
-
You are probably right that Mango Javascripting is sandboxed.
Event Handler may be the way to go. I will write something in phyton.
Not sure why Mango does not have a TCP/IP datasource module. They have modbus which is more or less the same.
Tons of devices are managed by TCP/IP.
I will make a test unit accessible through NAT soon, so you can play with it all you want to.
I actually bought a few 8 relay versions http://www.robot-electronics.co.uk/htm/eth008tech.htm Very useful devices at a fairly low cost.
-
This works.
Create Virtual Data Point
Add an Event Detector type Change and Alias XXX
Add in Event Handler/Point Event Detectors a Event Handler type Process
In the "Active Process Command" enter a command e.g. c:\python27\python c:\python27\relay1.pySee attached the relay1.py
Any time you set the the Virtual Data point to anything (does not matter what). The Python script is evoked and the relay turns on for 10 seconds.
... it is a start.
Thanks Jeremy for pointing me in the right direction.
Attachment: download link
-
Great!
I was thinking you would need two scripts; one for 'relay on', one for 'relay off'.
Then, you create a binary meta point, with two point event detectors, one for high and one for low.
Then finally, you set up a 'process' action point event detector (active process command only) for both events, so that when it is high, the 'relay open' script runs, and when it is low, the 'relay close' script runs.Or maybe you could do it all with one point event detector, using a binary meta point, and using an event detector that detects when it goes high, then using the active and inactive process commands.
Like this:Your 'change' event detector would look like this:
Would that work for your application?
-
I had to make 2 State Detectors. One for 1 (ON) and the other for 0 (OFF). Each their own Event Handler Python Script Process.
A Button (Virtual Data Source - Binary) Toggles very nicely.
Attachment: download link
-
Hey Guys,
Sorry for the delay on this. We do have a TCPIP data source but it's in Beta. I'm pretty sure it works but it hasn't been touched in a while. Here it is, will require core 2.5 to test. Please let me know if you get it to work.
Thanks,
Joel.Attachment: download link