This repository contains sample code for messaging over the Azure IoT Hub.
The scenario demonstrated is:
- How to upload blobs from Python
- How send device to cloud messages that contain metadata about the uploaded files
- How to use Azure Functions to store the metadata onto a PostgreSQL database
- How to call device methods
- Create IoT Hub
- Configure file uploads
- Create a consumer group that will be used by the Azure Functions to read device to cloud messages
- Clone
- Build using the script appropriate for you platform https://github.com/Azure/azure-iot-sdk-python/tree/master/build_all
- After success build, copy the native library (e.g.
iothub_client.so
) onto root of this repository or to a system path (or editLD_LIBRARY_PATH
) - Update line
CONNECTION_STRING = "[Device Connection String]"
in fileiothub_upload_sample.py
to have your device connection string- If you haven't created a device yet, you can do that in Azure Portal
- Run the sample with
python iothub_upload_sample.py
- Create an Azure Function
- Setup the Function to be deployed from a local Git repository
- Edit file
IoTHubToPostgreSQL/config.js
to have connection details for you PostgreSQL database - Edit file
IoTHubToPostgreSQL/function.js
to have right Event Hub name and consumer group - Push this repository into the local Git repository that you created above
- Construct an Event Hub compatible connection string
- Due to Azure Functions not supporting IoT Hub trigger directly, you have to contruct the connection string manually
- Update the Azure Function to have the right connection string in App Settings with key
iothub-ehub
(this key is referenced from fileIoTHubToPostgreSQL/function.json
):
You can use https://github.com/Azure/iothub-explorer to test invocation of device methods. At the same time, you can observe that the Azure Function is not getting triggered from these, because the device method messaging is not routed via the same pipeline as cloud to device messages.