Skip to content

Commit b682e75

Browse files
driver/power: Add power backend for RPM1521
Add power backend for the Minuteman RPM1521 series of power switches(2,4,8 ports). Signed-off-by: Caleb Ethridge <caleb.ethridge@analog.com>
1 parent 64723a5 commit b682e75

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

labgrid/driver/power/rpm1521.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""Power backend for the Minuteman RPM1521 networked power controller.
2+
3+
The RPM1521 is controlled via an HTTP CGI endpoint using HTTP basic auth::
4+
5+
curl --user user:pwd \\
6+
"http://192.168.1.100/nagios_powerctrl.csp?slave_id=1&port=<PORT>&ctrl_kind=<KIND>"
7+
8+
where ``ctrl_kind=1`` turns the outlet on and ``ctrl_kind=2`` turns it off.
9+
10+
The outlet state is read back from a separate status CGI::
11+
12+
curl --user user:pwd "http://192.168.1.100/nagios_power_status.csp"
13+
14+
which returns a list whose second to last element holds the on/off state of each
15+
outlet (0 = off, 1 = on).
16+
17+
NetworkPowerPort:
18+
model: rpm1521
19+
host: 'http://admin:secret@192.168.1.10'
20+
index: 1
21+
"""
22+
23+
import json
24+
25+
import requests
26+
27+
SLAVE_ID = 1
28+
CTRL_KIND_ON = 1
29+
CTRL_KIND_OFF = 2
30+
31+
32+
def power_set(host, port, index, value):
33+
index = int(index)
34+
ctrl_kind = CTRL_KIND_ON if value else CTRL_KIND_OFF
35+
params = {
36+
"slave_id": SLAVE_ID,
37+
"port": index,
38+
"ctrl_kind": ctrl_kind,
39+
}
40+
r = requests.get(f"{host}/nagios_powerctrl.csp", params=params)
41+
r.raise_for_status()
42+
43+
44+
def power_get(host, port, index):
45+
index = int(index)
46+
params = {
47+
"slave_id": SLAVE_ID,
48+
}
49+
r = requests.get(f"{host}/nagios_power_status.csp", params=params)
50+
r.raise_for_status()
51+
52+
# The status CGI returns a list literal, e.g.
53+
# ['RPM1521E','0.0','NULL','1','1','109.9',['1','0'],['0','1'],['0.0','0.0']]
54+
# It contains several bracketed sub-lists; the second to last one holds the
55+
# on/off status of each outlet.
56+
data = json.loads(r.text.replace("'", '"'))
57+
socket_states = data[-2]
58+
return int(socket_states[index - 1]) == 1

tests/test_powerdriver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ def test_import_backends(self):
295295
import labgrid.driver.power.pe6216
296296
import labgrid.driver.power.poe_netgear_plus
297297
import labgrid.driver.power.rest
298+
import labgrid.driver.power.rpm1521
298299
import labgrid.driver.power.sentry
299300
import labgrid.driver.power.eg_pms2_network
300301
import labgrid.driver.power.shelly_gen1

0 commit comments

Comments
 (0)