0
votes

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:

  • dev version - not help
  • free memory up to 32kB - not help
  • captured packets with WireShark: packets contain encrypted data with some lenght, so it is not empty and packet size is less than 2kB buffer size

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.
1
Try the dev branch and turn on debugging e.g. using nodemcu-build.com/index.php.Marcel Stör
I tried also dev version. Can't enable debugging, because my NodeMCU developer board is not delivered yet and witch ESP12E only I'm not able to upload scripts while using firmware with debug on.kyberpunk
Now i found it in the mailbox :D I will try ...kyberpunk
having the same issue with azure, will try a different broker latermarkusf

1 Answers

0
votes

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 :)