commandArray = {} time = os.date("*t") --funzione tempo aggiornamento script if ((time.min % 1)==0)then --espresso in minuti
function XML_Capture(cmd,flatten) local f = assert(io.popen(cmd, 'r')) local s = assert(f:read('*a')) f:close() if flatten then s = string.gsub(s, '^%s+', '') s = string.gsub(s, '%s+$', '') s = string.gsub(s, '[\n\r]+', ' ') end return send
--set to true to print to log file.debug = false
--definizione IDX(numero identificativo dispositivo domoticz)
sensore1 = 20sensore2 = 9sensore3 = 12sensore4 = 11
--definizione id sensori papouch
sensorID_1 = "id=\"1\""sensorID_2 = "id=\"2\""sensorID_3 = "id=\"3\""sensorID_4 = "id=\"4\""
-- Define your device IP@
Device_IP = "192.168.3.5" --indirizzo ip papouch
if debug == true then print("Reading values from: 'http://"..Device_IP.."/fresh.xml'")end
-- Read the XML data from the device
XML_string=XML_Capture("curl -u username:password -s 'http://"..Device_IP.."/fresh.xml'",1) --accesso compreso di username e password
valid = string.find(XML_string, "<root") -- check we are looking in the right place
if debug == true then print(XML_string) end if valid == nil then print ("Bad XML status read - sensor not updated") else --Find the first sensor based on its UID i = string.find(XML_string,sensorID_1) p = string.find(XML_string,"val=\" ",i) valsensore1=string.sub(XML_string,p+6,p+14) commandArray[1] = {['UpdateDevice'] = sensore1.."|0|"..valsensore1} --aggiornamento valore dispositivo Domoticz if debug == true then print("temp returned = ".."'"..valsensore1.."'") end --Find the second sensor based on its UID i = string.find(XML_string,sensorID_2) p = string.find(XML_string,"val=\" " ,i) valsensore2=string.sub(XML_string,p+6,p+14) commandArray[2] = {['UpdateDevice'] = sensore2.."|0|"..valsensore2} --aggiornamento valore dispositivo Domoticz if debug == true then print("temp returned = ".."'"..valsensore2.."'") end --Find the third sensor based on its UID i = string.find(XML_string,sensorID_3) p = string.find(XML_string,"val=\" ",i) valsensore3=string.sub(XML_string,p+6,p+14) commandArray[3] = {['UpdateDevice'] = sensore3.."|0|"..valsensore3} --aggiornamento valore dispositivo Domoticz if debug == true then print("temp returned = ".."'"..valsensore3.."'") end --Find the fourth sensor based on its UID i = string.find(XML_string,sensorID_4) p = string.find(XML_string,"val=\" ",i) valsensore4=string.sub(XML_string,p+6,p+14) commandArray[4] = {['UpdateDevice'] = sensore4.."|0|"..valsensore4} --aggiornamento valore dispositivo Domoticz if debug == true then print("temp returned = ".."'"..valsensore4.."'") end end endreturn commandArray