Azure Functions - 如何为我的 IoTHub 消息设置 IoTHubTrigger? [英] Azure Functions - how to set up IoTHubTrigger for my IoTHub messages?

查看:21
本文介绍了Azure Functions - 如何为我的 IoTHub 消息设置 IoTHubTrigger?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何正确设置和配置 IoTHubTrigger 以触发我的 IoTHub 消息的 Azure 函数 (C#)?在何处以及如何插入 IoTHub 的连接字符串?

解决方案

使用 Visual Studio 2017 的步骤:

  1. 首先确保您拥有最新版本的 Azure Functions 和 Web 作业工具

  1. 转到 File->New->Project->Azure Functions 并选择IoT Hub Trigger"

  2. 选择函数 V1 或 V2(了解其中的差异

    如果使用 Functions V2,请使用从这里的门户中获取的 IoTHub 的 EventHub 兼容端点:

    1. 现在在您的函数中设置一个断点并按 F5.您将看到您的消息从 IoTHub 流向您的 Azure 函数(假设您连接了正在发送数据的设备或模拟器)

    使用 Azure 门户的步骤

    1. 创建新的函数应用资源并选择 EventHub 触发器模板

    2. 为 EventHub 连接点击新建"并选择 IotHub 和您想要的集线器

    3. 编辑并保存您的函数代码 - 您现在可以开始运行了!

    4. 切换到监控"查看您的事件流入

    创建 IoTHub 触发 Azure 函数的更多选项

    a) 将 VS Code 与 Azure 函数扩展一起使用
    b) 从命令行使用 Azure Functions Core Tools

    How do I setup and configure an IoTHubTrigger correctly to trigger an Azure Function (C#) for my IoTHub messages? Where and how do I plug in my IoTHub's connection string?

    Steps using Visual Studio 2017:

    1. First make sure you have the latest version of the Azure Functions and Web Jobs Tools

    1. Go to File->New->Project->Azure Functions and select "IoT Hub Trigger"

    2. Select Functions V1 or V2 (learn about there differences here). And enter an arbitrary name that will serve as key for your connection string configuration.

    3. Open local.settings.json and enter a key/value pair for your connection string:

    {
        "IsEncrypted": false,
        "Values": {
            "AzureWebJobsStorage": "UseDevelopmentStorage=true",
            "AzureWebJobsDashboard": "UseDevelopmentStorage=true",
            "ConnectionString":  "<your connection string>"
        }
    }
    

    IMPORTANT

    If using Functions V1, use your IoTHub connection string obtained in the portal from here:

    If using Functions V2, use your IoTHub's EventHub compatible endpoint obtained in the portal from here:

    1. Now set a breakpoint in your function and hit F5. You will see your messages flowing from IoTHub to your Azure Function (assuming you have devices or simulators connected that are sending data)

    Steps using the Azure Portal

    1. Create a new Function App resource and select the EventHub Trigger template

    2. Hit "New" for EventHub Connection and select IotHub and your desired hub

    3. Edit and save your function code - you are now up and running!

    4. Switch to "Monitor" see your events flowing in

    More options to create IoTHub Trigger Azure Functions

    a) Using VS Code with the Azure Functions Extension
    b) From the command line using Azure Functions Core Tools

    这篇关于Azure Functions - 如何为我的 IoTHub 消息设置 IoTHubTrigger?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆