Logic Machine Forum
Uuable to connect to MQTT Broker - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Uuable to connect to MQTT Broker (/showthread.php?tid=5505)



Uuable to connect to MQTT Broker - Hadeel - 10.07.2024

Hi!

In our project we have homeassistant MQTT Broker and I am trying to use it from LM.

While I can connect to the same broker from my PC as follows, with LM I am getting an log saying "connect failed: Lookup error".

mosquitto command from my PC terminal is working fine as follows:
Code:
mosquitto_pub -h homeassistant.local -t "test/topic" -m "aaa_message" -u mqtt -P 0000 -q 1 -r

while my LM script gets an log saying "connect failed: Lookup error".

Code:
broker = 'homeassistant.local'
port = 1883
username = 'mqtt'
password = '0000'
topic = 'lm/test/1'
payload ="aaa_message"

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


I have two questions:
1. Why is my LM script not working while I can publish message on my PC successfully?
2. I know LM can be MQTT Broker itself but I am trying to use homeassistant MQTT Broker in order to reduce the CPU/IO of LM. We are trying to provide a function for our client to send MQTT message to control facilities that we automate with KNX. Do you think this is effective to reduce CPU/IO of LM?


RE: Uuable to connect to MQTT Broker - admin - 10.07.2024

LM won't resolve *.local addresses, use an IP address instead. Are you sure that the MQTT broker is causing high CPU load? Install the System load app on LM and sort the list by CPU usage to find out.


RE: Uuable to connect to MQTT Broker - Hadeel - 26.07.2024

Thank you !
I use IP address instead and I checked the load with System load app.
As you told me, even when I use LM MQTT broker it does not cause the high load.
Therefore I am using LM MQTT broker now : ) Thank you so much for you help!