event driven mqtt subscription in love2d

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
lsr
Prole
Posts: 2
Joined: Sat Nov 04, 2017 11:38 am

event driven mqtt subscription in love2d

Post 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!
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: event driven mqtt subscription in love2d

Post 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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: event driven mqtt subscription in love2d

Post 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.
lsr
Prole
Posts: 2
Joined: Sat Nov 04, 2017 11:38 am

Re: event driven mqtt subscription in love2d

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests