Sending data from a device to Microsoft Azure IoT Hub

  1. The device must be registered with Microsoft Azure IoT Hub.
  2. The controller 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 text box Payload, enter a message as JSON in the following format:
  8. NOTICE

    notice

    {    "deviceId": "yourDeviceId",

        "key": "eitherYourPrimaryOrYourSecondaryKey",

        "protocol": "egMqtt",

        "data": "yourData"

    }

  9. NOTICE

    notice

    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 drop-down list Protocol, select the protocol you want to use.
  13. In the text box Hostname, 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.