Page 1 of 1

event driven mqtt subscription in love2d

Posted: Sat Nov 04, 2017 11:53 am
by lsr
Hi,

I'm new to the forum and this is my first post - my apologies in advance if I am violating some unspoken rules (I did read the Forum etiquette).

I am trying to build a kiosk style display that is fed by mqtt messages. My general problem is that my callback from the mqtt subscribe function seems not to be fired. I wonder if this is a general problem (only love internal callbacks are called/permitted, e.g. draw) or if I am doing something wrong?

Code: Select all

--set up all mqtt related -> https://github.com/Yongke/luamqttc

local MQTT = require("luamqttc/client")
local myMQTT = MQTT.new("showy") --showy = clientID
local myMQTT_server = "lsrpi"
local myMQTT_port = "1883"
local myMQTT_timeout = 1

local myMQTT_topic = "#" 

function mqttMsgReceived(topic, data, packet_id, dup, qos, retained)
      print("cb 1: ", topic, data, packet_id, dup, qos, retained)
end

function love.load()
  if myMQTT:connect(myMQTT_server, myMQTT_port, {timeout=myMQTT_timeout}) == false then
        print("mqtt connect failed")
  else
        print("mqtt connect ok")
  end

  myMQTT:subscribe(myMQTT_topic, 2, mqttMsgReceived, myMQTT_timeout)
  mqttMsgReceived("topic", "data", "packetid", "dup", "qos", "retained")
end

function love.update(dt)
end

function love.draw()
end
Thank you very much for your help!

Re: event driven mqtt subscription in love2d

Posted: Sat Nov 04, 2017 12:28 pm
by grump
Hey there. Should have posted in the support forum instead of the showcase forum.

This looks like it's an issue with the mqtt library. You should ask the author. love does not limit you to specific callbacks.

Re: event driven mqtt subscription in love2d

Posted: Sat Nov 04, 2017 3:05 pm
by bartbes
I took a quick look at the library, and it seems to expect you to call the message_loop function in order to actually receive messages.

Re: event driven mqtt subscription in love2d

Posted: Sun Nov 05, 2017 1:55 pm
by lsr
Hi bartbes,

thank you very much for your reply - your solution worked. I really should have been able to find this out myself ... :-/

lsr