Best way to control devices
Posted: Thursday 17 November 2016 10:45
Hi!
What's the best way to send http control command to devices in lua scripts?
I'm currently using "openurl"
My devices often are unreachable (bad wifi, chip crash etc)
I think this eventually is making domoticz unstable.
There must be a way for domoticz to control devices that doesn't lead it to eventually crash when those devices are unreachable surely?
(By crash I mean the web ui stops responding, the error log then starts showing domoticz folders as missing etc)
Example of scripts:
commandArray = {};
IP = '192.168.2.170';
Port = '80';
GPIO = 3; -- r=0,g=1,b=2,w=3
DomDevice = 'Bathroom Ceiling Lamp'
if devicechanged[DomDevice] then
if(devicechanged[DomDevice]=='Off') then
print("Turning OFF with openurl " .. DomDevice)
commandArray['OpenURL']="http://" .. IP .. ":" .. Port .. "/control?cmd=PWMFADE," .. tostring(GPIO) .. ",0,1"
elseif (devicechanged[DomDevice]=='On') then
print("Turning On with openurl value : " .. tostring(uservariables[DomDevice]))
otherdevices_svalues[DomDevice] = tostring(uservariables[DomDevice])
commandArray['OpenURL']="http://" .. IP .. ":" .. Port .. "/control?cmd=PWMFADE," .. tostring(GPIO) .. "," .. tostring(tostring(uservariables[DomDevice]*10+0)) .. ",1" -- new dimmers now do 0-100!
else
print("Value openurl sent from domoticz is : " .. otherdevices_svalues[DomDevice])
uservariables[DomDevice] = otherdevices_svalues[DomDevice]
commandArray['OpenURL']="http://" .. IP .. ":" .. Port .. "/control?cmd=PWMFADE," .. tostring(GPIO) .. "," .. tostring(tostring(uservariables[DomDevice]*10+0)) .. ",1" -- new dimmers now do 0-100!
commandArray['Variable:'..DomDevice] = uservariables[DomDevice]
end
end;
return commandArray
commandArray = {};
DomDevice = 'House Thermostat';
IP = '192.168.2.180'
Port = '80'
function send(msg)
runcommand = "echo "..string.char(34).."POST "..msg.. " HTTP/1.1"..string.char(13)..string.char(10)..string.char(13)..string.char(10)..string.char(34).."| telnet "..IP.." "..Port.." "
print (runcommand)
os.execute(runcommand)
end
if devicechanged[DomDevice] then
commandArray['OpenURL']="http://" .. IP .. ":" .. Port .. "/control?cmd=thermoset," .. tostring(otherdevices_svalues[DomDevice])
print("Thermoset Rads Set :" .. tostring(otherdevices_svalues[DomDevice]))
end
return commandArray
Cheers for any ideas!
What's the best way to send http control command to devices in lua scripts?
I'm currently using "openurl"
My devices often are unreachable (bad wifi, chip crash etc)
I think this eventually is making domoticz unstable.
There must be a way for domoticz to control devices that doesn't lead it to eventually crash when those devices are unreachable surely?
(By crash I mean the web ui stops responding, the error log then starts showing domoticz folders as missing etc)
Example of scripts:
commandArray = {};
IP = '192.168.2.170';
Port = '80';
GPIO = 3; -- r=0,g=1,b=2,w=3
DomDevice = 'Bathroom Ceiling Lamp'
if devicechanged[DomDevice] then
if(devicechanged[DomDevice]=='Off') then
print("Turning OFF with openurl " .. DomDevice)
commandArray['OpenURL']="http://" .. IP .. ":" .. Port .. "/control?cmd=PWMFADE," .. tostring(GPIO) .. ",0,1"
elseif (devicechanged[DomDevice]=='On') then
print("Turning On with openurl value : " .. tostring(uservariables[DomDevice]))
otherdevices_svalues[DomDevice] = tostring(uservariables[DomDevice])
commandArray['OpenURL']="http://" .. IP .. ":" .. Port .. "/control?cmd=PWMFADE," .. tostring(GPIO) .. "," .. tostring(tostring(uservariables[DomDevice]*10+0)) .. ",1" -- new dimmers now do 0-100!
else
print("Value openurl sent from domoticz is : " .. otherdevices_svalues[DomDevice])
uservariables[DomDevice] = otherdevices_svalues[DomDevice]
commandArray['OpenURL']="http://" .. IP .. ":" .. Port .. "/control?cmd=PWMFADE," .. tostring(GPIO) .. "," .. tostring(tostring(uservariables[DomDevice]*10+0)) .. ",1" -- new dimmers now do 0-100!
commandArray['Variable:'..DomDevice] = uservariables[DomDevice]
end
end;
return commandArray
commandArray = {};
DomDevice = 'House Thermostat';
IP = '192.168.2.180'
Port = '80'
function send(msg)
runcommand = "echo "..string.char(34).."POST "..msg.. " HTTP/1.1"..string.char(13)..string.char(10)..string.char(13)..string.char(10)..string.char(34).."| telnet "..IP.." "..Port.." "
print (runcommand)
os.execute(runcommand)
end
if devicechanged[DomDevice] then
commandArray['OpenURL']="http://" .. IP .. ":" .. Port .. "/control?cmd=thermoset," .. tostring(otherdevices_svalues[DomDevice])
print("Thermoset Rads Set :" .. tostring(otherdevices_svalues[DomDevice]))
end
return commandArray
Cheers for any ideas!