Trouble connecting NodeMCU to Microsoft Azure IoT Hub

Internet of Things IoT Frameworks 3 years ago

2.3K 1 0 0 0

_x000D_ _x000D_ I am trying to connect my ESP8266, running the latest NodeMCU build, to a Microsoft Azure IoT Hub via MQTT Protocol. It appears that this is possible, as it is shown here... http://thinglabs.io/workshop/esp8266/sending-d2c-messages/ I am using the correct syntax as far as I can see from the MS Azure help... https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-mqtt-support Unlike the example in ThingLabs, which creates a SAS token using NodeMCU, I have followed the MS document and generated a SAS token using the Device Explorer, for testing purposes. My LUA code is as follows... -- Create variables DEVICE = "testdevice" IOTHUB = "mynewiothub.azure-devices.net" PORT = 8883 USER = IOTHUB.."/"..DEVICE.."/api-version=2016-11-14" PASS = "SharedAccessSignature sr=mynewiothub.azure-devices.net%2Fdevices%2Ftestdevice&sig=Roa5P8BPiGj...v2Vu%2Bm1j9sas%3D&se=1485704099" -- Create an MQTT Client azure = mqtt.Client(DEVICE, 60, USER, PASS) -- Connect to IoTHub via MQTT azure:connect(IOTHUB, PORT, 1, 0, -- Callback for a successful connection function(client) print("Connected") end, -- Error callback, if connection fails function(client, reason) print("Error Connecting: "..reason) end ) The response is always Error Connecting: -5 which translates to "There is no broker listening at the specified IP Address and Port". I suspected that NodeMCU was struggling with the SSL (port 8883) connection. So I ensured that I was able to make HTTPS connections (after verifying the SSL root certificate) with the following code, this worked but did not help. http.get("https://example.com/info", nil, function (code, resp) print(code, resp) end) I cannot seem to get this to work! @Marcel Stör - any thoughts? Many thanks in advance.

User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 3 years ago
_x000D_ I had the same error Error Connecting: -5 , I have set the time on the ESP and it fix this error. You will find some information about sntp on http://thinglabs.io/workshop/esp8266/sending-d2c-messages/ (as you mention it).
0 views
0 shares

No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Similar Forum


Q

Azure IoT hub and sending messages with mosquitto_pub

_x000D_ _x000D_ I'm trying to send some simple message with mosquitto_pub to Azure IoT HUB but faced...
Q

How to generate AWS bootstrap certificates with java SDK?

_x000D_ _x000D_ According to this docs I need to generate so-called bootstrap certificates for my Io...
Q

is it possible to do 3way handshake only one time with mqtt communication?

_x000D_ _x000D_ I am using mosquitto_pub to publish the data with TLS using a topic. I am using mosq...

Important Internet of Things Links