Connecting to Azure IoT Hub from Mbed OS device.
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:
DEVICE_IDto your Device ID.
MQTT_SERVER_HOST_NAMEto your IoT Hub hostname (you can find this under the ‘Overview’ tab in the IoT Hub).
MQTT_SERVER_PASSWORDto an SAS token.
- You can generate one easily from the ‘Azure IoT Hub Toolkit‘ extension in Visual Studio Code.
If authentication failed, you’ll see
ERROR: rc from MQTT connect is 5 in the console.
Azure IoT Hub uses RSA to authenticate, which requires a significant amount of memory. This library has the following heap requirements:
While connecting: 36594 bytes After connecting: 30098 bytes
While connecting: 54673 bytes After connecting: 42865 bytes