Sending data from a device to Microsoft Azure IoT Hub
- Prerequisite
- The device must be registered with Microsoft Azure IoT Hub.
- The device must be connected to the internet.
- Open Node-RED.
- Add the following nodes to the workspace and connect them to a flow:
- inject node from the input category
- Azure IoT Hub node from the cloud category
- debug node from the output category
- Double-click the inject node to open the Edit node dialogue.
- In the Payload text box, enter a message as JSON in the following format:
{ "deviceId": "yourDeviceId","key": "eitherYourPrimaryOrYourSecondaryKey","protocol": "egMqtt","data": "yourData"}
You can replace the inject node with any node, that generates similar messages.
- Click Done to apply your changes.
- Double-click the Azure IoT Hub node to open the Edit node dialogue.
- In the Protocol drop-down list, select the protocol you want to use.
- In the Hostname text box, enter your hostname.
- Click Done to apply your changes.
- Click Deploy.
- Click the button on the left side of the inject node.
- The configured message is sent to Azure IoT Hub. The status of the Azure IoT Hub node changes to Sent message.