Hi all,
I'm still a beginner with the new QA stuff, and wrote some piece of code to achieve the following:
Interface with my Bayrol Poolmanagers XML interface and retrieve some data to show (and in future)process them.
The code itself is working , getting data and writing them to some global variables, however I simply cannot manage to get the data shown in to labels in the QA.
can someone more experienced than me have a look?
here is the code:
-- URL of the XML interface
local xmlURL = "http://xxx.xxx.xxx.xxx/cgi-bin/webgui.fcgi?xmlitem=34.4022"
-- Function to retrieve XML data and update variables
local function updateData()
local http = net.HTTPClient()
http:request(xmlURL, {
options = {
method = 'GET',
headers = {},
timeout = 5000
},
success = function(response)
local data = response.data
fibaro.trace("XML data received: " .. data)
local label, value = string.match(data, '<item%s+type=%"34%"%s+id=%"4022%"%s+label=%"(.-)%".-value=%"(.-)%"')
if label and value then
fibaro.trace("Label: " .. label)
fibaro.trace("Value: " .. value)
-- Update the global variables with the new values
hub.setGlobalVariable("XMLlabel", label)
hub.setGlobalVariable("XMLValue", value)
else
fibaro.trace("Failed to extract label and value from XML response.")
end
end,
error = function(error)
fibaro.trace("Failed to retrieve XML data: " .. error)
end
})
end
-- Function to update the interface values
local function updateInterfaceValues()
-- Retrieve the values from the global variables
local label = hub.getGlobalVariable("XMLlabel")
local value = hub.getGlobalVariable("XMLValue")
print(value,label)
-- Update the Quick App interface with the new values
self:updateView ("Unit", "text", hub.getGlobalVariable("XMLlabel"))-- write in Label "Unit"
self:updateView ("Value", "text", hub.getGlobalVariable("XMLVabel"))--writein Label "Value"
end
-- Main execution
function QuickApp:onInit()
-- Trigger the initial data update
updateData()
-- Create a timer to update the interface values periodically
fibaro.setTimeout(5000, function()
updateInterfaceValues()
fibaro.setTimeout(5000, function()
updateInterfaceValues()
end)
end)
end