Looking for help to make a UI7 Plug-in for NETIO PDU

I’m new to Vera and to Programming. If anyone out there is kind enough to help me with the coding of a new plug-in I would be grateful.

Basically i would like to control my PDU (Power Distribution Unit http://www.koukaam.se/kkmd/showproduct.php?article_id=1502) though Vera Edge.

NETIO-230B is a 4 port PDU that supports control though cgi comands of the following type:

http://IP:port/cgi/control.cgi?login=p:username:password&p=i10u

p=XYZK
X-port 1
Y-port 2
Z-port 3
K-port 4

1 means set port on
0 means set port is off
u don’t change port status
i means if the port is on turn it of and on again (reset after 5 seconds)

After inserting the command on the browser and if PDU executes the command successful it replays on the browser = 250 OK

At any time i can request the status of the ports with the fowling command:
http://IP:port/cgi/control.cgi?login=p:username:password&p=list

PDU Reports the port status on the following format - 1001 (means only port 1 and 4 are on)

1 means port is on
0 means port is off

In the Develop Apps i started to mess with the Test Luup code (Lua) and was able to control de PDU with a command like:
luup.inet.wget(“http://192.168.100.23:2323/cgi/control.cgi?login=p:teste:test&p=0101”)
it executes the task and reply is “Failed to test code, please try again”

The objective is to get a 4 way switch on the dashboard that controls the ports on the PDU and checks the status of the ports from time to time for locally made changes (set by a timer in seconds).
I was looking on similar pulg-ing link the WOL with ping. But the problem is that i don’t have the thinness clue how to make a plug-in with luup for UI7.

All help is welcome.

You could actually use the Multiswitch plugin to set/show status of the ports as it has 8 virtual switches. Use scenes for regular checks and when a button changes status. You are on the right way with the LUA but did you put in the delay loop to give the PDU a chance to respond?

Example code (source Vera wiki) using GET

[code]require(‘ltn12’)
local http = require(‘socket.http’)

– 5 Second timeout (change if more time for PDU to respond us needed)
socket.http.TIMEOUT = 5

local response_body = {}
local request_body = ‘’

local r, c, h = socket.http.request{
url = ‘http://website/page?parameter1=value&parameter2=value’,
method = “GET”,
port = 80,
headers = {
[“Content-Length”] = string.len(request_body),
[“Content-Type”] = “application/x-www-form-urlencoded”
},
source = ltn12.source.string(request_body),
sink = ltn12.sink.table(response_body)
}[/code]

Example code using POST

[code]local http = require(“socket.http”)

– 5 Second timeout
http.TIMEOUT = 5

– The return parameters are in a different order from luup.inet.wget(…)
result, status = http.request(“http://192.168.0.113/runprocess.htm”, “run=run”)
[/code]

Have a look at the web power switch plugin to help you get started.

  • Garrett

Thanks for the quick feedback Guys, ;D

@BOFH sorry for the ignorance but form the code you provided changing “http://website/page?parameter1=value&parameter2=value” to the right string should be enough to make the code roll correctly on Test Luup code (Lua)? because I get “Failed to test code, please try again” what else am i not seeing right?

@garrettwp Allredy installed the app what is the best way to analyse and edit it’s code?

@garrettwp LOL just found out you are the developer of the web power switch plug-in. Kudos! If you have the time and the will i would like to have your help to make it compatible with Netio PDU.

I tried to look trough the XML on your pulg-in code but i confess i’m totally lost… :-[

Still trying withou any sucess! :-[

I suck at programing! :stuck_out_tongue: