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 Project with 2024 FW Problem
#7
Try changing object value and the topic will appear in MQTT Explorer.

If you want to keep last topic values for other clients then you need to enable retain flag for messages. To do this replace last line in publishvalue:
Code:
mclient:publish(topic, tostring(value))

With this:
Code:
mclient:publish(topic, tostring(value), 0, true)

Note that LM MQTT broker does not have any persistence. If the broker is restarted then retained topics are lost until new value is published.


Additionally you can modify the script to publish all mapped values after a connection to broker is established. Replace mclient.ON_CONNECT with this:
Code:
  mclient.ON_CONNECT = function(res, ...)
    log('mqtt connect status', res, ...)

    if res then
      for addr, topic in pairs(object_to_mqtt) do
        local value = grp.getvalue(addr)

        if value ~= nil then
          if type(value) == 'boolean' then
            value = value and 1 or 0
          end

          mclient:publish(topic, tostring(value), 0, true)
        end
      end

      for topic, _ in pairs(mqtt_to_object) do
        mclient:subscribe(topic)
      end
    else
      mclient:disconnect()
    end
  end
Reply


Messages In This Thread
RE: MQTT Broker Project with 2024 FW Problem - by admin - 20.09.2024, 08:55

Forum Jump: