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

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

问题描述

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

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?

推荐答案

使用Visual Studio 2017的步骤:

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

  1. 转到文件"->新建"->项目"->"Azure函数",然后选择"IoT Hub触发器"

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

选择功能V1或V2(了解存在的差异这里).然后输入一个任意名称作​​为您的连接字符串配置的键.

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.

打开local.settings.json并为您的连接字符串输入键/值对:

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>"
    }
}

重要

如果使用功能V1 ,请使用从门户网站从以下位置获得的IoTHub连接字符串:

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

如果使用功能V2 ,请使用从此处从门户网站中获得的IoTHub的EventHub兼容端点:

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

  1. 现在在函数中设置一个断点,然后按F5.您将看到消息从IoTHub流到Azure函数(假设您已连接正在发送数据的设备或模拟器)
  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)

使用Azure门户的步骤

  1. 创建一个新的Function App资源并选择EventHub触发器模板

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

在EventHub Connection中单击新建",然后选择IotHub和所需的集线器

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

编辑并保存您的功能代码-您现在已启动并运行!

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

切换到监视器"以查看事件的流向

Switch to "Monitor" see your events flowing in

创建IoTHub触发Azure功能的更多选项

a)将VS代码与 Azure函数扩展一起使用
b)从命令行使用 Azure函数核心工具

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

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

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