This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

MQTT Client app - Beta testing
#7
UPD: i moved all my rules to the new application (54 total) Smile hope it won't break anything :-D

so regarding throttle, the following approach seems to be working, with the knowledge that i should use unique names per each script

"In" event:
Code:
ls_bedroom_throttle = ls_bedroom_throttle or require('user.mqttclient_common').throttle(60)

local data = json.pdecode(payload)
if type(data) == 'table' then
  return ls_bedroom_throttle(data.illuminance)
end

user library:
Code:
return {
  throttle = function(timeout)
    local last_update = 0
    return function(val)
      if(val ~= nil) then
        local now = os.time()
        if((now - last_update) < timeout) then
          return nil
        else
          last_update = now
          return val
        end
      end
    end
  end
}

SUGGESTION: 
1) in error log make it obvious which script contains error, so i can fix it easily. For example this error does not have information where to look:
Quote:error: failed to run script - [string "in-26"]:9: attempt to compare nil with number
2) output errors in global error log so they can be noticed in time
Reply


Messages In This Thread
MQTT Client app - Beta testing - by Daniel - 10.09.2024, 14:12
RE: MQTT Client app - Beta testing - by myg - 23.09.2024, 08:58
RE: MQTT Client app - Beta testing - by myg - 23.09.2024, 09:50
RE: MQTT Client app - Beta testing - by admin - 23.09.2024, 10:04
RE: MQTT Client app - Beta testing - by myg - 23.09.2024, 10:41
RE: MQTT Client app - Beta testing - by myg - 23.09.2024, 12:50

Forum Jump: