# Sending data from a device to Microsoft Azure IoT Hub

1. Prerequisite
2. The device must be registered with Microsoft Azure IoT Hub.
3. The device must be connected to the internet.

1. Open Node-RED.
2. Add the following nodes to the workspace and connect them to a flow:
3. inject node from the input category
4. Azure IoT Hub node from the cloud category
5. debug node from the output category
6. Double-click the inject node to open the Edit node dialogue.
7. In the Payload text box, enter a message as JSON in the following format:

8. `{ "deviceId": "yourDeviceId",`

   `"key": "eitherYourPrimaryOrYourSecondaryKey",`

   `"protocol": "egMqtt",`

   `"data": "yourData"`

   `}`

9. You can replace the inject node with any node, that generates similar messages.

10. Click Done to apply your changes.
11. Double-click the Azure IoT Hub node to open the Edit node dialogue.
12. In the Protocol drop-down list, select the protocol you want to use.
13. In the Hostname text box, enter your hostname.
14. Click Done to apply your changes.
15. Click Deploy.
16. Click the button on the left side of the inject node.

1. The configured message is sent to Azure IoT Hub. The status of the Azure IoT Hub node changes to Sent message.

Registering a device with Microsoft Azure IoT Hub