Trouble connecting NodeMCU to Microsoft Azure IoT Hub

Internet of Things IoT Frameworks 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating
_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.

Posted on 16 Aug 2022, this text provides information on IoT Frameworks related to Internet of Things. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 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).

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.

Important Internet of Things Links