q.philippe Posté(e) le 10 février 2016 Signaler Partager Posté(e) le 10 février 2016 Bon voilà , je voudrai récupérer des infos d"état sur un fichier XML (ip/info.xml) d'un IPpower. J'ai deja créer mon module : http://www.domotique-fibaro.fr/index.php/topic/7511-module-ip-power-9258w/?hl=ippower Mais je voudrai faire un retour d'etat (si manipulation externe). j'ai les command : https://opengear.zendesk.com/entries/23240897-Aviosys-IP-Power-PDU-command-line-control j'ai l'explication de pascal(domo-info) sur le xml et http et zibase : http://www.domotique-info.fr/2014/02/utiliser-zibase-passerelle-enocean-pour-le-home-center-2/ j'ai ma page xml : ip/info.xml : 9258WIFI IPpower[192.168.0.xx] 00xxxxxxxxx7 Version:1.11 http://192.168.0.xx/info.xml IPpower Switch - OFF Switch PoE - ONReseauMedia - ON Prise - ON Quelqu'un a t-il développer un script dans le xml sur un module HC2 ?! Tout aide est sympa. Lien vers le commentaire Partager sur d’autres sites More sharing options...
JossAlf Posté(e) le 10 février 2016 Signaler Partager Posté(e) le 10 février 2016 Je te réponds ici aussi : Il y a un truc donné par Steven qui transforme un XML en json : -- This script will request sensors.xml file from a Zibase -- and use it to change global variables. -- Version = "1.0.0" -- Author = "Domotique-Info.fr (Steven Piccand)" -- Info = "Memory is preserved: Object are only load once in memory"-- This program is free software: you can redistribute it and/or modify -- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. -- This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -- You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ----- !!!!!remettre cette ligne si on repasse en main loop !!! --local maj = 30 -- Durée en secondes de la mise à jour -- -------------------------------------------------------------------------------------------------------------- -- Check that one and only one instance is in memory -- -------------------------------------------------------------------------------------------------------------- if ((not Zibase) or (Zibase.errors >= 5)) then Zibase = { errors = 0 } -- -------------------------------------------------------------------------------------------------------------- -- Miscellaneous -- -------------------------------------------------------------------------------------------------------------- Zibase.url = fibaro:get(fibaro:getSelfId(), 'IPAddress') Zibase.port = fibaro:get(fibaro:getSelfId(), 'TCPPort') -- -------------------------------------------------------------------------------------------------------------- -- Get the XML from the zibase and return it as a LUA table -- -------------------------------------------------------------------------------------------------------------- Zibase.getXml = function() --local zibaseURL = Net.FHttp("zibase.net"); --response, status, errorCode = zibaseURL:GET("/m/get_xml_sensors.php?device="..Zibase.id.."&token="..Zibase.token); local zibaseURL = Net.FHttp(Zibase.url) response, status, errorCode = zibaseURL:GET("/sensors.xml") return Zibase.iif(response ~= nil, Zibase.newParser().ParseXmlText(response), "") end -- -------------------------------------------------------------------------------------------------------------- -- Put all Sensors values in global variables -- -------------------------------------------------------------------------------------------------------------- Zibase.putSensorsInMemory = function(id) local xmlTable = Zibase.getXml() if (xmlTable) then if (not xmlTable.doc) then Zibase.errors = Zibase.errors+1 return nil end local evs = xmlTable.doc.evs for i in pairs(evs:children()) do local idtmp = evs.ev[i]["@id"] if (evs.ev[i]["@pro"]) then idtmp = evs.ev[i]["@pro"] .. idtmp else if (evs.ev[i]["@type"] == "2") then idtmp = "VS" .. idtmp elseif (evs.ev[i]["@type"] == "6") then idtmp = "CS" .. idtmp elseif (evs.ev[i]["@type"] == "7") then idtmp = "OS" .. idtmp elseif (evs.ev[i]["@type"] == "8") then idtmp = "VR" .. idtmp elseif (evs.ev[i]["@type"] == "10") then idtmp = "WS" .. idtmp end end if (not id) then fibaro:setGlobal(idtmp.."_V1", evs.ev[i]["@v1"]/10) fibaro:setGlobal(idtmp.."_V2", evs.ev[i]["@v2"]) elseif ((id ~= nil) and (idtmp == id)) then values = {} values[1] = evs.ev[i]["@v1"] values[2] = evs.ev[i]["@v2"] return values end end end return nil end -- -------------------------------------------------------------------------------------------------------------- -- Get the values (v1 and v2) of a sensor from the zibase -- -------------------------------------------------------------------------------------------------------------- Zibase.getSensorValues = function(id) if (id ~= nil) then return Zibase.putSensorsInMemory(id) else return nil end end -- -------------------------------------------------------------------------------------------------------------- -- Get the value from a variable from the zibase -- -------------------------------------------------------------------------------------------------------------- Zibase.getVariable = function(num) local xmlTable = Zibase.getXml() if (xmlTable) then if (not xmlTable.doc) then Zibase.errors = Zibase.errors+1 return "" end local vars = xmlTable.doc.vars for i in pairs(vars:children()) do if (vars.var[i]["@num"] == num) then return vars.var[i]["@val"] end end end return "" end -- ------------------------------------------------------------------------------------------------------------- -- Test the condition and return true or false param depending of the result -- param : condition (condition to test) -- iftrue (result to return of condition if true) -- iftfalse (result to return of condition if false) -- ------------------------------------------------------------------------------------------------------------- Zibase.iif = function(condition, iftrue, iffalse) if (condition) then return iftrue end return iffalse end -- ------------------------------------------------------------------------------------------------------------- -- Return a random number from 1 to 100 -- ------------------------------------------------------------------------------------------------------------- Zibase.random = function() return math.random(100) end -- ------------------------------------------------------------------------------------------------------------- -- This is a modified version of Corona-XML-Module by Jonathan Beebe which in turn -- is based on Alexander Makeev's Lua-only XML parser . -- see https://github.com/Cluain/Lua-Simple-XML-Parser -- ------------------------------------------------------------------------------------------------------------- Zibase.newParser = function() parseXml = {} parseXml.FromXmlString = function(value) value = string.gsub(value, "([%x]+)%;", function(h) return string.char(tonumber(h, 16)) end); value = string.gsub(value, "([0-9]+)%;", function(h) return string.char(tonumber(h, 10)) end); value = string.gsub(value, "\"", "\""); value = string.gsub(value, "'", "'"); value = string.gsub(value, ">", ">"); value = string.gsub(value, "<", "<"); value = string.gsub(value, "&", "&"); return value; end parseXml.ParseArgs = function(node, s) string.gsub(s, "(%w+)=([\"'])(.-)%2", function(w, _, a) node:addProperty(w, parseXml.FromXmlString(a)) end) end parseXml.ParseXmlText = function(xmlText) local stack = {} local top = parseXml.newNode() table.insert(stack, top) local ni, c, label, xarg, empty local i, j = 1, 1 while true do ni, j, c, label, xarg, empty = string.find(xmlText, "<(%/?)([%w_:]+)(.-)(%/?)>", i) if not ni then break end local text = string.sub(xmlText, i, ni - 1); if not string.find(text, "^%s*$") then local lVal = (top:value() or "") .. parseXml.FromXmlString(text) stack[#stack]:setValue(lVal) end if empty == "/" then -- empty element tag local lNode = parseXml.newNode(label) parseXml.ParseArgs(lNode, xarg) top:addChild(lNode) elseif c == "" then -- start tag local lNode = parseXml.newNode(label) parseXml.ParseArgs(lNode, xarg) table.insert(stack, lNode) top = lNode else -- end tag local toclose = table.remove(stack) -- remove top top = stack[#stack] if #stack < 1 then error("XmlParser: nothing to close with " .. label) end if toclose:name() ~= label then error("XmlParser: trying to close " .. toclose.name .. " with " .. label) end top:addChild(toclose) end i = j + 1 end local text = string.sub(xmlText, i); if #stack > 1 then error("XmlParser: unclosed " .. stack[#stack]:name()) end return top end parseXml.newNode = function(name) local node = {} node.___value = nil node.___name = name node.___children = {} node.___props = {} function node:value() return self.___value end function node:setValue(val) self.___value = val end function node:name() return self.___name end function node:setName(name) self.___name = name end function node:children() return self.___children end function node:numChildren() return #self.___children end function node:addChild(child) if self[child:name()] ~= nil then if type(self[child:name()].name) == "function" then local tempTable = {} table.insert(tempTable, self[child:name()]) self[child:name()] = tempTable end table.insert(self[child:name()], child) else self[child:name()] = child end table.insert(self.___children, child) end function node:properties() return self.___props end function node:numProperties() return #self.___props end function node:addProperty(name, value) local lName = "@" .. name if self[lName] ~= nil then if type(self[lName]) == "string" then local tempTable = {} table.insert(tempTable, self[lName]) self[lName] = tempTable end table.insert(self[lName], value) else self[lName] = value end table.insert(self.___props, { name = name, value = self[name] }) end return node end return parseXml; end end -- ------------------------------------------------------------------------------------------------------------- -- Send a message in the default chat frame if debug mode is activated -- param : sMessage (message to display) -- return : <none> -- ------------------------------------------------------------------------------------------------------------- Zibase.putSensorsInMemory() local time = os.date("le %d.%m.%Y à %H:%M:%S") if (Zibase.errors > 0) then time = "Erreur : " .. Zibase.errors end fibaro:call(fibaro:getSelfId(),"setProperty","ui.Label1.value",time) fibaro:call(fibaro:getSelfId(),"setProperty","ui.Label3.value","http://domotique-info.fr") ----- !!!!!remettre cette ligne si on repasse en main loop !!! --fibaro:sleep(maj*1000) Une autre piste : http://www.domotique-info.fr/2014/02/utiliser-zibase-passerelle-enocean-pour-le-home-center-2/ Lien vers le commentaire Partager sur d’autres sites More sharing options...
q.philippe Posté(e) le 4 mars 2016 Auteur Signaler Partager Posté(e) le 4 mars 2016 Merci Joss J'essaye de voir cela. Lien vers le commentaire Partager sur d’autres sites More sharing options...
Messages recommandés