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 gpio.read(1)
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
For more details on how to use MQTT directly you can read this blog.
Hi there!
Thanks for your guide.
It’s very detailed.
I was wondering though, what would the code look like if you were using C? I code my NodeMCU from the Arduino IDE, and I think many people search for how to connect the C coded NodeMCU to Azure, but there is little info.
And I am new at this too…
Kind Regards
Paul
Hi Paul,
I never tried that way
http://icircuit.net/using-nodemcu-arduino-ide/1396