I am a newbie with Azure and I want to send a message periodically from Raspberry Pi to Azure IoT Hub then trigger Azure Function (instead of using Stream Analystic) and then save the message to database. I have seen some online tutorials but I have found that, these tutorial is old and only using C#. And I want to use Python because I am familiar with this language. Is there any updated Azure Function tutorial using Python? Or could you guy please give me an example?
Thanks in advance to those who can enlighten me!
CodePudding user response:
Based on your requirement you can follow the below steps:
Create Storage Account with your resource group.
Go to IoT Hub and get the connection string.
Create a consumer group for IoT Hub.
Install VS Code and install all the Azure related Extensions.
Go to Function App in VS Code and Create a new function app.
Select the Interpreter as Python.
Select any one of the trigger (EventHubTrigger). Provide required inputs related to event hub.
At input and output of function app, configure it accordingly to table storage as target. Refer to this documentation and below is the sample binding trigger:
{ "scriptFile": "__init__.py", "bindings": [ { "name": "message", "type": "table", "tableName": "messages", "partitionKey": "message", "connection": "AzureWebJobsStorage", "direction": "out" }, { "authLevel": "function", "type": "httpTrigger", "direction": "in", "name": "req", "methods": [ "get", "post" ] }, { "type": "http", "direction": "out", "name": "$return" } ] }
Add your basic logic python code and test it.
After successful execution, deploy the function to Azure from VS Code.
Add local.settings.json keys and values to Configuration --> Application settings in your function app.
You can achieve your task with these steps, If you find any difficulty in any of the step, you can go through the MS documentation related to it.