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 protocol using resident scripts
#4
For testing you can enable "Allow anonymous connections (no username/password)" and remove client:login_set(...) from your script.

Instead of adding log calls to the script you can enable logging for a certain object that will be written to via MQTT. Then you can check the timestamps in Object logs to determine how many telegrams are handled per second.

Code:
require('json')
broker = '127.0.0.1'
port = 1883

mqtt = require('mosquitto')
client = mqtt.new()

client.ON_CONNECT = function(status, rc, msg)
  log('connect', status, rc, msg)

  if status then
    client:subscribe('#')
  else
    client:disconnect()
  end
end

client.ON_MESSAGE = function(mid, topic, payload)
  local decoded = json.pdecode(payload)

  if type(decoded) == 'table' then
    for i, m in ipairs(decoded.commands) do
      grp.write(m.alias, m.value)
    end
  end
end

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

client:loop_forever()

Some further improvements can be made with object datatype caching. Otherwise each grp.write call requires a database query to determine the object data type. But keep in mind that the main bottleneck is KNX/TP low speed.
Reply


Messages In This Thread
RE: MQTT protocol using resident scripts - by admin - 24.05.2022, 07:22

Forum Jump: