Hi,
I installed the WPSswitch plugin as a base of a plugin im trying to build.
And i have a question about the following part: (partial question are mention as comments in the code)
-- get outlet status
-- hier wat aanpassen voor xmp parse relays.cgi?relay=7 = relay1 relays.cgi?relay=0 = relay8
local function getStatus()
local command = "status.xml" --original this is index.htm but i need status.xml
local data = ""
data = httpRequest(command)
if (data ~= nil) then
for state in string.gmatch(data, "state=(%w.)") do --
-- local stateBinary = Hex2Bin(state)
debug(string.format("getStatus: state: %s", stateBinary))
-- output of status.xml is like:
-- <response>
-- <relay0>0</relay0>
-- <relay1>1</relay1>
-- <volts>13</volts>
-- </response>
-- part below is letting my eye role over here
local o = OUTLETS_MAX
for status in string.gmatch(stateBinary, "(%d)") do
debug(string.format("getStatus: Outlet-%d=%s", o, status))
local device = findChild(PARENT_DEVICE, string.format("Outlet-%d", o))
if (device ~= nil) then
local lastStatus = luup.variable_get(SWITCH_SERVICEID, "Status", device)
-- below i understand
-- check if new status is different from last status
if (lastStatus ~= status) then
local time = os.time(os.date('*t'))
luup.variable_set(SWITCH_SERVICEID, "Status", status, device)
-- no need for HADevice luup.variable_set(HADEVICE_SID, "LastUpdate", time, device)
end
end
o = o - 1
end
end
end
end
--
-- below i put some questions behind the code line
--
local function outletControl(outlet, state)
debug(string.format("outletControl: %d state: %s", outlet, state))
-- url to switch status = "http://ip/relays.cgi?relay=7" for relais 1 and relays.cgi?relay=0 switches relais 8 so some convertion is needed here
local command = "relay?" .. outlet .. "=" .. state -- think i need to do some text format to get the word relayX here
httpRequest(command)
getStatus()
end
Hopefully somebody can help me with this.