Connecting to Azure IoT Hub from Mbed OS device.
Mbed-to-Azure-IoT-Hub
Mbed OS example program connecting to Azure IoT Hub with MQTT over TLS. You can authenticate through X.509 certificates or through a symmetric key.
Setting your device identity
Using an X.509 certificate
See Azure IoT Hub from Mbed OS device for more details on how to create a new certificate.
Using symmetric keys
- In the Azure IoT Hub, click IoT Devices > Add.
- Enter a Device ID.
- Under ‘Authentication type’, select Symmetric key.
- In this application, open MQTT_server_setting.h, and:
- Set
IOTHUB_AUTH_METHOD
toIOTHUB_AUTH_SYMMETRIC_KEY
. - Set
DEVICE_ID
to your Device ID. - Set
MQTT_SERVER_HOST_NAME
to your IoT Hub hostname (you can find this under the ‘Overview’ tab in the IoT Hub). - Set
MQTT_SERVER_PASSWORD
to an SAS token.- You can generate one easily from the ‘Azure IoT Hub Toolkit‘ extension in Visual Studio Code.
- Set
If authentication failed, you’ll see ERROR: rc from MQTT connect is 5
in the console.
Memory usage
Azure IoT Hub uses RSA to authenticate, which requires a significant amount of memory. This library has the following heap requirements:
Symmetric keys
While connecting: 36594 bytes
After connecting: 30098 bytes
X.509 certificates
While connecting: 54673 bytes
After connecting: 42865 bytes