Skip to content

Commit

Permalink
driver/power: add support for Robot Electronics ETH008
Browse files Browse the repository at this point in the history
use HTTP-GET API defined at
https://www.robot-electronics.co.uk/htm/eth008tech.htm

Signed-off-by: Jens Kleintje <[email protected]>
  • Loading branch information
JensKle committed Sep 28, 2023
1 parent 342dc90 commit 7720884
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ Currently available are:
interface, this module deliberately uses the standard password '1' and is
not compatible with a different password.

``eth008``
Controls a Robot-Electronics eth008 via a simple HTTP API.

``gude``
Controls a Gude PDU via a simple HTTP API.

Expand Down
42 changes: 42 additions & 0 deletions labgrid/driver/power/eth008.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
This driver implements a power port for the robot electronics 8 relay
outputs board.
Driver has been tested with:
* ETH008 - 8 relay outputs
"""

import requests
from ..exception import ExecutionError

PORT = 80

def power_set(host, port, index, value):
index = int(index)
assert 1 <= index <= 8
# access the web interface...
value_str = "A" if value else "I"
response = requests.get(
f"http://{host}:{port}/io.cgi?DO{value_str}{index}"
)
response.raise_for_status()

# Check, that the port is in the desired state
state = get_state(response, index)
if state != value:
raise ExecutionError(f"failed to set port {index} to status {value}")

def power_get(host, port, index):
index = int(index)
assert 1 <= index <= 8
# get the contents of the main page
response = requests.get(f"http://{host}:{port}/io.cgi?relay")

response.raise_for_status()
state = get_state(response, index)
return state

def get_state(request, index):
value = request.text.split()[1][index-1]
states = {"0": False, "1": True}
return states[value]

0 comments on commit 7720884

Please sign in to comment.