Is it possible to get an easier instruction how to make it work?
What code should you enter to activate a relay, eg nt 2 and how to turn it off again?
// Jens
jay (support) wrote:How are you calling the script?
jens wrote:Is it possible to get an easier instruction how to make it work?
zaiks wrote:jay (support) wrote:How are you calling the script?
I'm callinng this as embedded script each call in separate Action Group
jay (support) wrote:And you just uncomment one of the lines at the top depending on what you want to do?
jay (support) wrote:From an Indigo standpoint, you don't need to convert it since the script doesn't target Indigo.
zaiks wrote:But for status requests I call for Indigo and write the states to variables - this part will be killed as I understand?
curl --connect-timeout 2 --data saida1off=off http://admin:12345678@192.168.1.166/relay_en.cgi
zaiks wrote:Ok. Anyway as its always good idea to let something uncertain be the base for your crucial need I started to port this code over to python. I have all states read and written to variables, but for controlling I would like to get help with following shellscript:
- Code: Select all
curl --connect-timeout 2 --data saida1off=off http://admin:12345678@192.168.1.166/relay_en.cgi
How I can achieve the same with python?
import requests
url = "http://admin:12345678@192.168.1.166/relay_en.cgi?saida1off=off"
r = requests.get(url)
# Example of logging to Indigo the HTTP result status code and text:
indigo.server.log("result status: %d, text: %s" % (r.status_code, r.text))
# Script for getting statuses of ethernet Relay board
import urllib
# Input your data here:
BoardIP = '192.168.1.166'
User = 'admin'
Pass = '12345678'
RelayName = 'No1' # If you have more than 1 relay board
# Constants and global variables
SearchString2 = "img src"
Result = ''
variableOut = ''
Output = ''
a = 1
# Start extraction of data
urlReturned = urllib.urlopen('http://' + User + ':' + Pass + '@' + BoardIP + '/relay_en.cgi')
data_getStatuses = urlReturned.read()
for a in range(1, 9):
SearchString = 'saida' + str(a) + 'pluse'
ResultA = data_getStatuses[data_getStatuses.find(SearchString):data_getStatuses.find(SearchString)+150]
ResultB = ResultA[ResultA.find(SearchString2)+9:ResultA.find(SearchString2)+16]
if ResultB == "lighton":
Result = str(Result) + '1'
Output = "true"
else:
Result = str(Result) + '0'
Output = "false"
# Sending info to variables
variableOut = str(RelayName) + '_onStateRelay_' + str(a)
try:
var = indigo.variables[variableOut]
except:
indigo.variable.create(variableOut)
indigo.variable.updateValue(variableOut, Output)
# Relay states as list
# indigo.server.log(str(Result))
# Script for setting status of ethernet Relay board one relay at a time
import requests
# Input your data here:
BoardIP = '192.168.1.166'
User = 'admin'
Pass = '12345678'
RelayNo = '1'
RelayCommand = 'on' # accepts on/off
# Constants and global variables
key1 = ''
value1 = ''
# Start execution of change
url = ('http://' + BoardIP + '/relay_en.cgi')
key1 = 'saida' + RelayNo + RelayCommand
value1 = RelayCommand
payload = {key1: value1}
r = requests.post(url, auth=(User, Pass), data=payload)
# Script for setting status of ethernet Relay board relay's by list
import requests
# Input your data here:
BoardIP = '192.168.1.166'
User = 'admin'
Pass = '12345678'
RelayList = '00000000' # 1- true, 0 - false, any other character - ignore, 1st relay is 1st position in list
# Constants and global variables
key1 = ''
value1 = ''
a = 1
state = ''
RelayCommand = ''
# Start execution of change
url = ('http://' + BoardIP + '/relay_en.cgi')
for a in range(0,8):
state = RelayList[a]
if state == '1':
RelayCommand = 'on'
if state == '0':
RelayCommand = 'off'
if state <> '1' and state <> '0':
RelayCommand = ''
key1 = 'saida' + str(a+1) + RelayCommand
value1 = RelayCommand
payload = {key1: value1}
r = requests.post(url, auth=(User, Pass), data=payload)
DomoPat wrote:This relay board looks very interesting, what about the 8 inputs ? can you read their status or are they only able to command the relays ?
I have been looking for any sort of documentation about this board (and the inputs, as you seem to have the relay part well covered) and cannot find anything, do you have something ?
Thank you,
Patrick
Parameters of controller Default IP: 192.168.1.166 Default TCP port: 1234
(1) Open the relay
TCP Relay Protocol V1.0
L(n) ,n=1:8,Such as the need to open the relay 1, then send the string “L1”. The board will return “Relayon 1” after the relay in operation.
(2) Close the relay
D(n),n=1:8,Such as the need to close the relay 1, then send the string “D3”. The board will return “Relayoff 3” after the relay in operation.
(3) 800ms pluse,Open relay for 800ms,then close.
P(n),n=1:8,Such as the need to pluse the relay 1, then send the string “P1”. The board will return “Press 1” after the relay in operation.
(4) Read status of relays
R(n),n=1:8,Such as the need to read the status of relay 1, then send the string “R1”. The board will return “Relayon 1” or “Relayoff 1”.
(5) Read input status
I(n),n=1:8, Such as the need to read the status of input 1, then send the string “I1”. The board will return “IL 1” or “IH 1”.
(6) Burst mode read status
Send strings ”DUMP” or “dump”,the board will return all status of relays and inputs by end of “OK”.
(7) Examples
1. Connect to TCP port;
2. Send command,all commad by ends of “\r\n”;
3. If the PC within 30s no data is sent to the controller, the controller will disconnect to PC.
L1
Relayon 1
DUMP
Relayon 1
Relayoff 2
Relayoff 3
Relayoff 4
Relayoff 5
Relayoff 6
Relayoff 7
Relayoff 8
IL 1
IL 2
IL 3
IL 4
IL 5
IL 6
IL 7
IL 8
OK
Users browsing this forum: No registered users and 22 guests