kyberpunk
kyberpunk

Reputation: 21

ESP8266 with NodeMCU firmware: receiving empty messages with secured MQTT subscription

I'm trying to securely connect ESP8266 to MQTT Azure Protocol Gateway broker on cloud or local computer (tried both) like this (not important - connection works correctly):

m = mqtt.Client("{deviceId}", "3600", "{iotHub}/{deviceId}", "{SASToken}")
...
m:on("message", function(conn, top, data)
  print(data) -- EMPTY string here!
end)
  ...
m:connect({IP}, 8883, 1, function(conn)
  m:subscribe("devices/{deviceId}/messages/devicebound/#", 1, function(conn) 
    ...
  end)
end)

ESP connects to server and handshake is completed successfully. When I publish some data, I can read it on server properly, it is OK. I subscribe to topic without problems. When I send data in cloud-to-device message from server to ESP to subscribed topic, 'on message' event is called but data attribute passed to the function is EMPTY string.

I'm using latest NodeMCU master build based on 1.4.0 SDK (tried both integer and float version). I can't turn on debugging, because i don't have NodeMCU developer yet.

I tried following:

Can someone please advise me where could be a problem or how to debug it for more info? I would approciate any ideas. Thank you.

EDIT: I've tried debug mode, and there is nothing interesting on output:

enter mqtt_socket_received.
MQTT_DATA: type: 3, qos: 0, msg_id: 0, pending_id: 0
enter deliver_publish.
string
userdata: 3fff3e88
devices/ESP/messages/devicebound
          <- here should be printed data
On
leave deliver_publish.
receive, queue size: 0
leave mqtt_socket_received.
enter mqtt_socket_timer.
timer, queue size: 0
keep_alive_tick: 71
leave mqtt_socket_timer.
enter mqtt_socket_received.
MQTT_DATA: type: 7, qos: 1, msg_id: 8813, pending_id: 0
receive, queue size: 0
leave mqtt_socket_received.

Upvotes: 0

Views: 490

Answers (1)

IgnacioF
IgnacioF

Reputation: 51

This may be stupid but sometimes lua expects specific names in some functions. Change this function(conn, top, data) for this function(conn, topic, data)

I have worked previously with mqtt in lua with password protection, and i had to drop it beacuse i wasnt recieving the message content either, however i think mine was due to the amount of messages i was recieving/delivering. I also changed broker from mosquitto to mosca.

I hope you find a fix soon and please share it we might be able to use it to :)

Upvotes: 0

Related Questions