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 broker app communication with local client event based script
#1
broker = "localhost"
port = 1883
username = "admin"
password = "password"
topic = "casambi/1/set/target_level"

value = event.getvalue()

if value == 1
  then
  topic = "casambi/1/set/target_level"
payload = tostring"("level":255,"duration":1,"targetid":177,"targettype":1,)"
else
  payload = tostring"("level":0,"duration":1,"targetid":177,"targettype":1,)"
  end
 
mqtt = require("mosquitto")
client = mqtt.new()

client.ON_CONNECT = function(status, rc, msg)
  if status then
    log("mqtt connected")
    client:publish(topic, tostring(payload))
  else
    log("mqtt connect failed " .. tostring(msg))
    client:disconnect()
  end
end

client.ON_PUBLISH = function()
  client:disconnect()
end

client:login_set(username, password)
status, rc, msg = client:connect(broker, port)

if status then
  client:loop_forever()
else
  log("connect failed: " .. tostring(msg))
end

Error log shows:
attempt to call global 'level' (a nil value)
stack traceback:
Reply


Messages In This Thread
Mqtt broker app communication with local client event based script - by Rajesh - 13.02.2023, 12:25

Forum Jump: