Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


Recommended Posts

Posted (edited)

Guys, I have written the code below and The label alarmStatus label is never updated when the message arrives.

See below the logs. Any thoughts?

 

[14.05.2023] [22:43:37] [DEBUG] [QUICKAPP372]: onConnected: {"sessionPresent":true,"returnCode":0}
[14.05.2023] [22:43:47] [DEBUG] [QUICKAPP372]: event: {"topic":"riscopanel\/armstatus","dup":false,"payload":"disarmed","qos":0,"retain":true}
[14.05.2023] [22:43:47] [DEBUG] [QUICKAPP372]: Alarm Status: disarmed

 

-- Alarm partition type should handle following actions: arm, disarm
-- To update arm state of alarm partition, update property "armed" with boolean
-- To update alarm state of alarm partiton, update property "alarm" with boolean
-- Eg. self:updateProperty("alarm", true) will indicate that alarm partition was breached
 
function QuickApp:arm()
    self:debug("Alarm Partition armed")
    self:updateProperty("armed"true)
end
 
function QuickApp:disarm()
    self:debug("Alarm partition disarmed")
    self:updateProperty("disarmed"false)    
end
 
-- To update controls you can use method self:updateView(<component ID>, <component property>, <desired value>). Eg:  
-- self:updateView("slider", "value", "55") 
-- self:updateView("button1", "text", "MUTE") 
-- self:updateView("label", "text", "TURNED ON") 
 
-- This is QuickApp inital method. It is called right after your QuickApp starts (after each save or on gateway startup). 
-- Here you can set some default values, setup http connection or get QuickApp variables.
-- To learn more, please visit: 
--    * https://manuals.fibaro.com/home-center-3/
--    * https://manuals.fibaro.com/home-center-3-quick-apps/
 
function QuickApp:onInit()
    QuickApp:EstablishMqttConnection()  
    self.http = net.HTTPClient({timeout=10000})     
    self:loop()
end
 
function QuickApp:loop()
    QuickApp:Subscribe()
    fibaro.setTimeout(10000function()    
        self:loop()
    end
end 


 
function QuickApp:EstablishMqttConnection()    
    local options = {  clientId = "Fibaro", username="xxxx", password="yyyyyyy", port = 1883 }
    local mqtt_server = "xxx.xxx.xxx.xxx"
    self.client = mqtt.Client.connect(mqtt_server, options)      
    self.client:addEventListener('connected'function(event) self:onConnected(event) end
    self.client:addEventListener('message'function(event) self:onMessage(event) end
end
 
function QuickApp:Subscribe()
    self.client:subscribe("riscopanel/armstatus/#", { qos = mqtt.EXACTLY_ONCE }); 
end
 
 
function QuickApp:onMessage(event)
    print("onMessage:", json.encode(event))
    local alarm = event.payload
    self:debug("Alarm Status: ", alarm)
    self:updateView("alarmStatus""text""Alarm  Status: " .. alarm)
end


 
function QuickApp:onPublished(event)
    print("onPublished:", json.encode(event))  
end
 
function QuickApp:onConnected(event)
    print("onConnected:", json.encode(event))  
end

 
Edited by 03397
  • 03397 changed the title to Problem updating label
Posted

Does the label has the correct ID in the GUI editor? -> alarmStatus with the correct upper/lowercase chars?

  • Like 1
  • 2 weeks later...
  • Topic Author
  • Posted (edited)

    Thanks joep for your answer. I have found the issue and corrected it. The problem is the call of the functions inside other functions. 

     

    For example I had

     
    function QuickApp:onInit()
        QuickApp:EstablishMqttConnection()  
        self.http = net.HTTPClient({timeout=10000})     
        self:loop()
     
     
     
    But it needs to be self:EstablishMqttConnection()
     
    I have corrected everything and and now everything works ok. 
    Edited by 03397
    • Like 1

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Reply to this topic...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...