azure-functions-iothub-extension

所属分类:物联网
开发工具:C#
文件大小:82KB
下载次数:0
上传日期:2023-01-11 11:40:24
上 传 者sh-1993
说明:  Azure功能的IOT中心扩展
(IOT Hub Extension for Azure Functions)

文件列表:
LICENSE (1177, 2022-11-29)
SECURITY.md (2757, 2022-11-29)
WebJobs.Extensions.IoTHub.sln (2036, 2022-11-29)
samples (0, 2022-11-29)
samples\functions (0, 2022-11-29)
samples\functions\C2D_SetDeviceTwin (0, 2022-11-29)
samples\functions\C2D_SetDeviceTwin\function.json (562, 2022-11-29)
samples\functions\C2D_SetDeviceTwin\run.csx (1576, 2022-11-29)
samples\functions\DirectMethod (0, 2022-11-29)
samples\functions\DirectMethod\function.json (392, 2022-11-29)
samples\functions\DirectMethod\project.json (129, 2022-11-29)
samples\functions\DirectMethod\run.csx (568, 2022-11-29)
samples\functions\GetDeviceTwin_SetDeviceTwin (0, 2022-11-29)
samples\functions\GetDeviceTwin_SetDeviceTwin\function.json (582, 2022-11-29)
samples\functions\GetDeviceTwin_SetDeviceTwin\project.json (130, 2022-11-29)
samples\functions\GetDeviceTwin_SetDeviceTwin\run.csx (1412, 2022-11-29)
samples\simulatedDevices (0, 2022-11-29)
samples\simulatedDevices\receiverAlice (0, 2022-11-29)
samples\simulatedDevices\receiverAlice\package-lock.json (44243, 2022-11-29)
samples\simulatedDevices\receiverAlice\package.json (308, 2022-11-29)
samples\simulatedDevices\receiverAlice\receiveralice.js (3663, 2022-11-29)
samples\simulatedDevices\receiverBob (0, 2022-11-29)
samples\simulatedDevices\receiverBob\package-lock.json (121690, 2022-11-29)
samples\simulatedDevices\receiverBob\package.json (339, 2022-11-29)
samples\simulatedDevices\receiverBob\receiverbob.js (4092, 2022-11-29)
samples\simulatedDevices\receiverCarol (0, 2022-11-29)
samples\simulatedDevices\receiverCarol\package.json (316, 2022-11-29)
samples\simulatedDevices\receiverCarol\receivercarol.js (3199, 2022-11-29)
samples\simulatedDevices\receiverDave (0, 2022-11-29)
samples\simulatedDevices\receiverDave\package-lock.json (44242, 2022-11-29)
samples\simulatedDevices\receiverDave\package.json (272, 2022-11-29)
samples\simulatedDevices\receiverDave\receiverDave.js (4092, 2022-11-29)
samples\simulatedDevices\sender (0, 2022-11-29)
samples\simulatedDevices\sender\package.json (435, 2022-11-29)
samples\simulatedDevices\sender\sender.js (5726, 2022-11-29)
src (0, 2022-11-29)
src\WebJobs.Extensions.IoTHub (0, 2022-11-29)
... ...

### IoTHub Extension Fully featured IoT Hub input and output bindings to Azure IoT Hub, allowing common interactions between cloud and devices to be done from Azure Functions. Common scenarios currently supported are: * Cloud to Device: output binding that sends messages from Azure Functions to IoTHub, which then transfer the messages to specified device id in the message structure * Direct Method: output binding that invokes methods in the device from Azure Functions * Set Device Twin: output binding that updates desired properties of specified device from Azure Functions * Get Device Twin: input binding that gets device twin of the specified device once the Function's trigger is fired #### Current Status This extension is still in the prototype phase and has not been published to NuGet. If you need to process IOT Hub messages with Azure Functions, the currently supported method is documented [here](https://docs.microsoft.com/en-us/samples/azure-samples/functions-js-iot-hub-processing/processing-data-from-iot-hub-with-azure-functions/). #### Example ##### Cloud to Device ###### function.json ```csharp { "bindings": [ { "type": "eventHubTrigger", "name": "myEventHubMessage", "direction": "in", "path": "messages/events", "connection": "IoTConnectionString", "consumerGroup": "secondconsumergroup" }, { "name": "cloudToDevice", "type": "ioTCloudToDevice", "direction": "out", "connection": "IoTConnectionString" // connection string can differ from the trigger's } ], "disabled": false } ``` ###### run.csx ```csharp using System; public static void Run(string myEventHubMessage, ICollector cloudToDevice, ICollector setDeviceTwin, TraceWriter log) { cloudToDevice.Add("{\"DeviceId\":\"myFirstDevice\",\"MessageId\":1,\"Message\":\"C2D message\"}"); } ``` See more [sample code](https://github.com/ElleTojaroon/azure-functions-iothub-extension/tree/master/samples/functions) for each scenario #### Sample Code [functions folders](https://github.com/ElleTojaroon/azure-functions-iothub-extension/tree/master/samples/functions) contains functions to use in Azure Functions portal. To run, do the following: 1. Zip extension .dll files and put them in Function's library via **Advanced tools (Kudu)** 2. Add the path where the extension lives to appsetting using **AzureWebJobs_ExtensionsPath** as key 3. Create a new function in portal and copy codes from selected scenario in the sample folder 4. Change the appsetting key for **connection string** in function.json to **IoTConnectionString** or change the key for **connection string** (and/or **consumerGroup** for EventHubTrigger) in function.json according to your custom app setting. 5. Run your device code or [sender.js](https://github.com/ElleTojaroon/azure-functions-iothub-extension/tree/master/samples/simulatedDevices/sender) Your function should receive messages from **sender.js** 6. Run your device receiver code or select ones in [simulatedDevices folder](https://github.com/ElleTojaroon/azure-functions-iothub-extension/tree/master/samples/simulatedDevices) according to your scenario. * [receiverAlice](https://github.com/ElleTojaroon/azure-functions-iothub-extension/tree/master/samples/simulatedDevices/receiverAlice): **Direct Method** or **Set/Get Device Twin** * [receiverBob](https://github.com/ElleTojaroon/azure-functions-iothub-extension/tree/master/samples/simulatedDevices/receiverBob): **Cloud to Device** or **Set/Get Device Twin** * [receiverCarol](https://github.com/ElleTojaroon/azure-functions-iothub-extension/tree/master/samples/simulatedDevices/receiverCarol): **Set/Get Device Twin** * [receiverDave](https://github.com/ElleTojaroon/azure-functions-iothub-extension/tree/master/samples/simulatedDevices/receiverDave): **Cloud to Device** or **Set/Get Device Twin** > Direct Method assumes that the device has a method matched with the specified method's name given in the argument. Otherwise, Function throws an exception. > Executing direct method that takes longer than the lifetime of a Function (5 minutes by default and can be set up to 10 minutes) can never be completed. ## License This project is under the benevolent umbrella of the [.NET Foundation](http://www.dotnetfoundation.org/) and is licensed under [the MIT License](https://github.com/Azure/azure-webjobs-sdk/blob/master/LICENSE.txt) ## Contributing This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

近期下载者

相关文件


收藏者