Ethernet Relay Board -- Works Great!

Posted on
Wed Sep 27, 2017 5:10 am
jens offline
Posts: 191
Joined: May 03, 2015
Location: Sweden

Re: Ethernet Relay Board -- Works Great!

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

Posted on
Wed Sep 27, 2017 5:56 am
zaiks offline
Posts: 10
Joined: May 19, 2016

Re: Ethernet Relay Board -- Works Great!

jay (support) wrote:
How are you calling the script?


I'm callinng this as embedded script each call in separate Action Group

jens wrote:
Is it possible to get an easier instruction how to make it work?


Unfortunately this is all I have

Posted on
Wed Sep 27, 2017 9:27 am
jay (support) offline
Site Admin
User avatar
Posts: 13164
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Ethernet Relay Board -- Works Great!

zaiks wrote:
jay (support) wrote:
How are you calling the script?


I'm callinng this as embedded script each call in separate Action Group


And you just uncomment one of the lines at the top depending on what you want to do?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Sep 27, 2017 2:40 pm
zaiks offline
Posts: 10
Joined: May 19, 2016

Re: Ethernet Relay Board -- Works Great!

jay (support) wrote:
And you just uncomment one of the lines at the top depending on what you want to do?


Exactly

Posted on
Thu Sep 28, 2017 2:48 am
zaiks offline
Posts: 10
Joined: May 19, 2016

Re: Ethernet Relay Board -- Works Great!

jay (support) wrote:
From an Indigo standpoint, you don't need to convert it since the script doesn't target Indigo.


Ok. This script might be converted to external and it does what it is supposed to do as long as Apple keeps it's scripting envionment alive.
But for status requests I call for Indigo and write the states to variables - this part will be killed as I understand?

Posted on
Thu Sep 28, 2017 12:35 pm
jay (support) offline
Site Admin
User avatar
Posts: 13164
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Ethernet Relay Board -- Works Great!

zaiks wrote:
But for status requests I call for Indigo and write the states to variables - this part will be killed as I understand?


I don't know - the code you posted doesn't appear to communicate with Indigo. To reinforce what we've already posted, any AppleScript that has a "tell 'IndigoServer'" in it won't work.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Oct 01, 2017 12:53 pm
zaiks offline
Posts: 10
Joined: May 19, 2016

Re: Ethernet Relay Board -- Works Great!

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?

Posted on
Sun Oct 01, 2017 4:01 pm
FlyingDiver offline
Posts: 1657
Joined: Jun 07, 2014
Location: Cape Coral, FL

Re: Ethernet Relay Board -- Works Great!

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?


See this thread: viewtopic.php?f=107&t=19059

Something like:
Code: Select all
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))

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Oct 02, 2017 3:17 am
zaiks offline
Posts: 10
Joined: May 19, 2016

Re: Ethernet Relay Board -- Works Great!

Thank you Joe - this pointed me to the desired direction :D

My code is maybe a little robust, but i'll share the results with you as well. Now I'm able to control this card with some different python scripts and am futureproof.

For statuses and writing these to variables:
Code: Select all
 # 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))


For changing single relay state:
Code: Select all
# 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)


For changing relay states by list:
Code: Select all
# 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)

Who is online

Users browsing this forum: Bing [Bot] and 2 guests