Connecting Node MCU with Azure IoT hub

Azure IoT hub allows direct MQTT connections. So we can use MQTT module of the Node MCU to connect with the Azure IoT hub. You need a SAS token in order to connect with the Azure IoT hub. You can generate one by following this blog. You need to follow the mentioned blog in order to get the following details. You need to change the following details in the code  in config.lua file and load the all the files to NodeMCU.  I have included a firmware build as well, you may need to load the firmware first . You can find the details here.

Connection Details:


Connection details

Client ID : device ID

User Name : {iot hub host name}/{device id}

Password : SAS token

Open up the Device Explorer to monitor the messages from the devices

DE -> Data -> Monitor

You can receive all the messages sent by the device here.


To send messages to the device

print(‘Hello NodeMCU !!’) return

Instead of a “Hello World ” project, I reimplemented my previous project . The idea is that NodeMCU will try to execute whatever message you send to it. So it should be valid lua script

DM -> Messages To Device


You can see that the node executed the print statement we sent

Data On node mcu console
Data On node mcu console

For more details on how to use MQTT directly you can read this blog.

One Comment

Add a Comment

Your email address will not be published. Required fields are marked *