nodemcu-firmware: Problem with multiple MQTT subscriptions

I’m setting up an application where the nodemcu firmware is supposed to subscribe to 3 topics as shown here:

m = mqtt.Client("esp8266", 120, "", "")

m:on("message", function(conn, topic, data) 
  print(topic .. ":" ) 
  if data ~= nil then
    print(data)
  end
end)

m:connect("192.168.0.254", 1883, 0, 0, function(conn) print("connected") end)

m:subscribe("/topic1", 0, nil)
m:subscribe("/topic2", 0, nil)
m:subscribe("/topic3", 0, nil)

All seems fine as long as the messages come in asynchronously. But when all three topics deliver messages (more or less) at the same time, the third topic is not processed properly. Eg publishing on another client as follows (srv is on IP 192.168.0.254):

mosquitto_pub -h srv -i cli -q 0 -t /topic1 -m 1; mosquitto_pub -h srv -i cli -q 0 -t /topic2 -m 2; mosquitto_pub -h srv -i cli -q 0 -t /topic3 -m 3

yields:

/topic1:
1
/topic2:
2
/topic2:
2

Two messages at once is no problem, no matter which topics are used. But having all 3 in one row causes the last message on the 3rd channel being overwritten by the 2nd message.

Am I doing something wrong here? I’d guess the callback is somehow interlocked, but it seems strange. BTW the other method to subscribe to multiple channles in the README.md doesn’t work at all for me:

m:subscribe({["/topic1"]=0, ["/topic2"]=0, ["/topic3"]=0, nil})

It spawns a huge number of prints for a single publish…

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 19 (7 by maintainers)

Commits related to this issue

Most upvoted comments

СТАЛИН БЫ ЗА ТАКОЕ - РАССТРЕЛЯЛ!