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 subscribe
#1
Hello,

I'm trying to subscribe to a MQTT topic ("arqueta/humedad") and asign his value to an object of logic machine.

I'm using de test Mosquitto broker and I publish previously a value to the topic "arqueta/humedad".

I'm using this code (extracted from here) as a resident script but It seems doesn't works and I don't know what I'm doing wrong...

Code:
-- Define a function which is called by mqtt_client:handler(),
-- whenever messages are received on the subscribed topics

    function callback(topic, message)
    print("Received: " .. topic .. ": " .. message)
    if (message == "quit") then running = false end
  end

-- Create an MQTT client instance, connect to the MQTT server and
-- subscribe to the topic called "arqueta/humedad"

    MQTT = require("mosquitto")
  MQTT.Utility.set_debug(true)
    mqtt_client = MQTT.client.create("https://test.mosquitto.org", 1883, callback)
    mqtt_client:connect("logicmachine")
    local humedad = mqtt_client:subscribe("arqueta/humedad")
    grp.update('1/1/27', humedad)


-- Continously invoke mqtt_client:handler() to process the MQTT protocol and
-- handle any received messages.  Also, publish a message on topic "test/1"

  running = true

  while (running) do
    mqtt_client:handler()
    mqtt_client:publish("test/1", "test message")
    socket.sleep(1.0)  -- seconds
  end

-- Clean-up by unsubscribing from the topic and closing the MQTT connection

  mqtt_client:unsubscribe({"arqueta/humedad"})
  mqtt_client:destroy()
Reply


Messages In This Thread
MQTT subscribe - by pentadom - 30.11.2018, 17:39
RE: MQTT subscribe - by admin - 03.12.2018, 08:43
RE: MQTT subscribe - by pentadom - 03.12.2018, 10:18
RE: MQTT subscribe - by Dario - 04.02.2020, 12:10
RE: MQTT subscribe - by admin - 04.02.2020, 12:40
RE: MQTT subscribe - by Dario - 04.02.2020, 16:39
RE: MQTT subscribe - by Tifon - 08.03.2020, 09:33
RE: MQTT subscribe - by admin - 09.03.2020, 08:46
RE: MQTT subscribe - by admin - 19.02.2021, 12:10
RE: MQTT subscribe - by admin - 22.02.2021, 07:24
RE: MQTT subscribe - by admin - 22.02.2021, 08:10
RE: MQTT subscribe - by myg - 25.02.2021, 09:35
RE: MQTT subscribe - by admin - 26.02.2021, 11:59
RE: MQTT subscribe - by admin - 19.03.2021, 09:33
RE: MQTT subscribe - by a455115 - 12.12.2022, 14:05
RE: MQTT subscribe - by admin - 12.12.2022, 16:00
RE: MQTT subscribe - by a455115 - 13.12.2022, 07:23
RE: MQTT subscribe - by admin - 13.12.2022, 08:48
RE: MQTT subscribe - by a455115 - 14.12.2022, 07:09
RE: MQTT subscribe - by admin - 14.12.2022, 08:10
RE: MQTT subscribe - by a455115 - 14.12.2022, 10:05
RE: MQTT subscribe - by admin - 14.12.2022, 12:49
RE: MQTT subscribe - by a455115 - 14.12.2022, 15:04
RE: MQTT subscribe - by admin - 15.12.2022, 08:40
RE: MQTT subscribe - by tomnord - 18.01.2024, 13:16
RE: MQTT subscribe - by admin - 18.01.2024, 13:38
RE: MQTT subscribe - by tomnord - 18.01.2024, 13:51
RE: MQTT subscribe - by tomnord - 23.01.2024, 08:08
RE: MQTT subscribe - by Daniel - 23.01.2024, 08:09
RE: MQTT subscribe - by tomnord - 23.01.2024, 11:01
RE: MQTT subscribe - by Daniel - 23.01.2024, 11:16
RE: MQTT subscribe - by tomnord - 23.01.2024, 12:08
RE: MQTT subscribe - by Daniel - 23.01.2024, 12:41
RE: MQTT subscribe - by FatMax - 31.01.2024, 08:49
RE: MQTT subscribe - by Daniel - 31.01.2024, 09:28
RE: MQTT subscribe - by FatMax - 31.01.2024, 12:49
RE: MQTT subscribe - by admin - 31.01.2024, 12:52
RE: MQTT subscribe - by FatMax - 31.01.2024, 12:59
RE: MQTT subscribe - by admin - 31.01.2024, 13:01
RE: MQTT subscribe - by FatMax - 31.01.2024, 13:18
RE: MQTT subscribe - by admin - 31.01.2024, 13:23
RE: MQTT subscribe - by FatMax - 31.01.2024, 13:31
RE: MQTT subscribe - by admin - 31.01.2024, 13:53

Forum Jump: