├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md └── images ├── manage.png ├── new_project.png └── shared_selectdevice.png /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 4 | > Please provide us with the following information: 5 | > --------------------------------------------------------------- 6 | 7 | ### This issue is for a: (mark with an `x`) 8 | ``` 9 | - [ ] bug report -> please search issues before submitting 10 | - [ ] feature request 11 | - [ ] documentation issue or request 12 | - [ ] regression (a behavior that used to work and stopped in a new release) 13 | ``` 14 | 15 | ### Minimal steps to reproduce 16 | > 17 | 18 | ### Any log messages given by the failure 19 | > 20 | 21 | ### Expected/desired behavior 22 | > 23 | 24 | ### OS and Version? 25 | > Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?) 26 | 27 | ### Versions 28 | > 29 | 30 | ### Mention any other details that might be useful 31 | 32 | > --------------------------------------------------------------- 33 | > Thanks! We'll be in touch soon. 34 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Purpose 2 | 3 | * ... 4 | 5 | ## Does this introduce a breaking change? 6 | 7 | ``` 8 | [ ] Yes 9 | [ ] No 10 | ``` 11 | 12 | ## Pull Request Type 13 | What kind of change does this Pull Request introduce? 14 | 15 | 16 | ``` 17 | [ ] Bugfix 18 | [ ] Feature 19 | [ ] Code style update (formatting, local variables) 20 | [ ] Refactoring (no functional changes, no api changes) 21 | [ ] Documentation content changes 22 | [ ] Other... Please describe: 23 | ``` 24 | 25 | ## How to Test 26 | * Get the code 27 | 28 | ``` 29 | git clone [repo-address] 30 | cd [repo-name] 31 | git checkout [branch-name] 32 | npm install 33 | ``` 34 | 35 | * Test the code 36 | 37 | ``` 38 | ``` 39 | 40 | ## What to Check 41 | Verify that the following are valid 42 | * ... 43 | 44 | ## Other Information 45 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # .NET Core 46 | project.lock.json 47 | project.fragment.lock.json 48 | artifacts/ 49 | **/Properties/launchSettings.json 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # Visual Studio code coverage results 117 | *.coverage 118 | *.coveragexml 119 | 120 | # NCrunch 121 | _NCrunch_* 122 | .*crunch*.local.xml 123 | nCrunchTemp_* 124 | 125 | # MightyMoose 126 | *.mm.* 127 | AutoTest.Net/ 128 | 129 | # Web workbench (sass) 130 | .sass-cache/ 131 | 132 | # Installshield output folder 133 | [Ee]xpress/ 134 | 135 | # DocProject is a documentation generator add-in 136 | DocProject/buildhelp/ 137 | DocProject/Help/*.HxT 138 | DocProject/Help/*.HxC 139 | DocProject/Help/*.hhc 140 | DocProject/Help/*.hhk 141 | DocProject/Help/*.hhp 142 | DocProject/Help/Html2 143 | DocProject/Help/html 144 | 145 | # Click-Once directory 146 | publish/ 147 | 148 | # Publish Web Output 149 | *.[Pp]ublish.xml 150 | *.azurePubxml 151 | # TODO: Comment the next line if you want to checkin your web deploy settings 152 | # but database connection strings (with potential passwords) will be unencrypted 153 | *.pubxml 154 | *.publishproj 155 | 156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 157 | # checkin your Azure Web App publish settings, but sensitive information contained 158 | # in these scripts will be unencrypted 159 | PublishScripts/ 160 | 161 | # NuGet Packages 162 | *.nupkg 163 | # The packages folder can be ignored because of Package Restore 164 | **/packages/* 165 | # except build/, which is used as an MSBuild target. 166 | !**/packages/build/ 167 | # Uncomment if necessary however generally it will be regenerated when needed 168 | #!**/packages/repositories.config 169 | # NuGet v3's project.json files produces more ignorable files 170 | *.nuget.props 171 | *.nuget.targets 172 | 173 | # Microsoft Azure Build Output 174 | csx/ 175 | *.build.csdef 176 | 177 | # Microsoft Azure Emulator 178 | ecf/ 179 | rcf/ 180 | 181 | # Windows Store app package directories and files 182 | AppPackages/ 183 | BundleArtifacts/ 184 | Package.StoreAssociation.xml 185 | _pkginfo.txt 186 | 187 | # Visual Studio cache files 188 | # files ending in .cache can be ignored 189 | *.[Cc]ache 190 | # but keep track of directories ending in .cache 191 | !*.[Cc]ache/ 192 | 193 | # Others 194 | ClientBin/ 195 | ~$* 196 | *~ 197 | *.dbmdl 198 | *.dbproj.schemaview 199 | *.jfm 200 | *.pfx 201 | *.publishsettings 202 | orleans.codegen.cs 203 | 204 | # Since there are multiple workflows, uncomment next line to ignore bower_components 205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 206 | #bower_components/ 207 | 208 | # RIA/Silverlight projects 209 | Generated_Code/ 210 | 211 | # Backup & report files from converting an old project file 212 | # to a newer Visual Studio version. Backup files are not needed, 213 | # because we have git ;-) 214 | _UpgradeReport_Files/ 215 | Backup*/ 216 | UpgradeLog*.XML 217 | UpgradeLog*.htm 218 | 219 | # SQL Server files 220 | *.mdf 221 | *.ldf 222 | *.ndf 223 | 224 | # Business Intelligence projects 225 | *.rdl.data 226 | *.bim.layout 227 | *.bim_*.settings 228 | 229 | # Microsoft Fakes 230 | FakesAssemblies/ 231 | 232 | # GhostDoc plugin setting file 233 | *.GhostDoc.xml 234 | 235 | # Node.js Tools for Visual Studio 236 | .ntvs_analysis.dat 237 | node_modules/ 238 | 239 | # Typescript v1 declaration files 240 | typings/ 241 | 242 | # Visual Studio 6 build log 243 | *.plg 244 | 245 | # Visual Studio 6 workspace options file 246 | *.opt 247 | 248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 249 | *.vbw 250 | 251 | # Visual Studio LightSwitch build output 252 | **/*.HTMLClient/GeneratedArtifacts 253 | **/*.DesktopClient/GeneratedArtifacts 254 | **/*.DesktopClient/ModelManifest.xml 255 | **/*.Server/GeneratedArtifacts 256 | **/*.Server/ModelManifest.xml 257 | _Pvt_Extensions 258 | 259 | # Paket dependency manager 260 | .paket/paket.exe 261 | paket-files/ 262 | 263 | # FAKE - F# Make 264 | .fake/ 265 | 266 | # JetBrains Rider 267 | .idea/ 268 | *.sln.iml 269 | 270 | # CodeRush 271 | .cr/ 272 | 273 | # Python Tools for Visual Studio (PTVS) 274 | __pycache__/ 275 | *.pyc 276 | 277 | # Cake - Uncomment if you are using it 278 | # tools/** 279 | # !tools/packages.config 280 | 281 | # Telerik's JustMock configuration file 282 | *.jmconfig 283 | 284 | # BizTalk build output 285 | *.btp.cs 286 | *.btm.cs 287 | *.odx.cs 288 | *.xsd.cs 289 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [project-title] Changelog 2 | 3 | 4 | # x.y.z (yyyy-mm-dd) 5 | 6 | *Features* 7 | * ... 8 | 9 | *Bug Fixes* 10 | * ... 11 | 12 | *Breaking Changes* 13 | * ... 14 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to [project-title] 2 | 3 | This project welcomes contributions and suggestions. Most contributions require you to agree to a 4 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us 5 | the rights to use your contribution. For details, visit https://cla.microsoft.com. 6 | 7 | When you submit a pull request, a CLA-bot will automatically determine whether you need to provide 8 | a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions 9 | provided by the bot. You will only need to do this once across all repos using our CLA. 10 | 11 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 12 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or 13 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 14 | 15 | - [Code of Conduct](#coc) 16 | - [Issues and Bugs](#issue) 17 | - [Feature Requests](#feature) 18 | - [Submission Guidelines](#submit) 19 | 20 | ## Code of Conduct 21 | Help us keep this project open and inclusive. Please read and follow our [Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 22 | 23 | ## Found an Issue? 24 | If you find a bug in the source code or a mistake in the documentation, you can help us by 25 | [submitting an issue](#submit-issue) to the GitHub Repository. Even better, you can 26 | [submit a Pull Request](#submit-pr) with a fix. 27 | 28 | ## Want a Feature? 29 | You can *request* a new feature by [submitting an issue](#submit-issue) to the GitHub 30 | Repository. If you would like to *implement* a new feature, please submit an issue with 31 | a proposal for your work first, to be sure that we can use it. 32 | 33 | * **Small Features** can be crafted and directly [submitted as a Pull Request](#submit-pr). 34 | 35 | ## Submission Guidelines 36 | 37 | ### Submitting an Issue 38 | Before you submit an issue, search the archive, maybe your question was already answered. 39 | 40 | If your issue appears to be a bug, and hasn't been reported, open a new issue. 41 | Help us to maximize the effort we can spend fixing issues and adding new 42 | features, by not reporting duplicate issues. Providing the following information will increase the 43 | chances of your issue being dealt with quickly: 44 | 45 | * **Overview of the Issue** - if an error is being thrown a non-minified stack trace helps 46 | * **Version** - what version is affected (e.g. 0.1.2) 47 | * **Motivation for or Use Case** - explain what are you trying to do and why the current behavior is a bug for you 48 | * **Browsers and Operating System** - is this a problem with all browsers? 49 | * **Reproduce the Error** - provide a live example or a unambiguous set of steps 50 | * **Related Issues** - has a similar issue been reported before? 51 | * **Suggest a Fix** - if you can't fix the bug yourself, perhaps you can point to what might be 52 | causing the problem (line of code or commit) 53 | 54 | You can file new issues by providing the above information at the corresponding repository's issues link: https://github.com/[organization-name]/[repository-name]/issues/new]. 55 | 56 | ### Submitting a Pull Request (PR) 57 | Before you submit your Pull Request (PR) consider the following guidelines: 58 | 59 | * Search the repository (https://github.com/[organization-name]/[repository-name]/pulls) for an open or closed PR 60 | that relates to your submission. You don't want to duplicate effort. 61 | 62 | * Make your changes in a new git fork: 63 | 64 | * Commit your changes using a descriptive commit message 65 | * Push your fork to GitHub: 66 | * In GitHub, create a pull request 67 | * If we suggest changes then: 68 | * Make the required updates. 69 | * Rebase your fork and force push to your GitHub repository (this will update your Pull Request): 70 | 71 | ```shell 72 | git rebase master -i 73 | git push -f 74 | ``` 75 | 76 | That's it! Thank you for your contribution! 77 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Azure IoT and Serverless Button Sample 2 | 3 | The following sample will walk you through building an IoT application to post a tweet to Twitter. 4 | 5 | If you have any questions or issues feel free to create them on this repo following the provided templates. 6 | 7 | ## Visual Studio 2017 and C# Walkthrough 8 | 9 | The following walkthrough will guide you in building an application that can process IoT messages and have them take an action like sending a tweet. 10 | 11 | ## Pre-requisites 12 | 13 | The sample assumes the following are already installed and prepared: 14 | 15 | * [Visual Studio 2017 (any edition) with the Cloud workload included](https://www.visualstudio.com/downloads/) 16 | * [An Azure Subscription (free trial works great)](https://azure.microsoft.com/en-us/free/) 17 | 18 | The following are optional: 19 | 20 | * An IoT button that can send an event to IoT Hub (the teXXmo Azure Certified button works great) 21 | 22 | ## Creating an IoT Hub 23 | 24 | The first step we need to do is create the IoT Hub. Azure IoT Hub allows you to manage, configure, and monitor IoT devices. 25 | 26 | 1. Open the [Azure Portal](https://portal.azure.com) and sign-in with an account 27 | 1. Click the **+** or **Create a resource** button in the top left, select **Internet of Things** and then **IoT Hub** 28 | 1. Provide a *globally* unique name for your hub, and optionally select the pricing tier (Basic tier if fine) 29 | 1. Create/Select a resource group 30 | 1. Select the option to pin to dashboard 31 | 1. Click the create button 32 | 1. Click the **IoT Devices** section of the settings pane 33 | ![IoT Device](images/shared_selectdevice.png) 34 | 1. Click **Add** and create a device ID for this device. Click **Save** 35 | 1. Select and open the newly created device. You will need this info to connect the device to the cloud. 36 | 37 | ## Connecting a Device to the IoT Hub 38 | 39 | ### With a device simulator 40 | 41 | If you do not have a teXXmo button, you are welcome to use the community managed simulator which will send a "device to cloud" to your IoT hub. To use visit [this link](https://prodiotsimulator.blob.core.windows.net/site/index.html) and simulate a button press by pressing the "Submit" button after adding the device connection string from the previous section (Device details page). 42 | 43 | > NOTE: This site is community managed. Only use for simple tests with non-production IoT Hubs 44 | 45 | ### With a teXXmo button 46 | 47 | If using the teXXmo button to connect with Azure IoT Hub, follow the instructions to connect to the button access point (hold down button for a few seconds until blinking yellow, then connect to the broadcast access point). Go to the device configuration page in a web browser (http://192.168.4.1) and configure the IoT Hub with your Device Id, Key, and Hub hostname. The IoT Hub Hostname can be found on the **Overview** section of IoT Hub. 48 | 49 | ### With the IoT Hub SDK 50 | 51 | If you do not have a button and don't want to use the community button simulator, I recommend using the SDK directly in your own Visual Studio project. Instructions can be [found here](https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-csharp-csharp-getstarted#introduction) 52 | 53 | ## Creating the Azure Function 54 | 55 | Now that you have an IoT Hub and a connected device, we need to write a simple Azure Function to process the data the devices are generating. 56 | 57 | 1. Open Visual Studio 2017 58 | 1. **Tool** -> **Extensions and Updates** to [check your Azure Functions and Web Jobs Tools version](https://docs.microsoft.com/azure/azure-functions/functions-develop-vs#check-your-tools-version). Make sure you have at least **version 15.0.40502.0**. If not, [update your tools](https://docs.microsoft.com/azure/azure-functions/functions-develop-vs#update-your-tools). 59 | 1. **File** -> **New Project** and under **Visual C#** -> **Cloud** select **Azure Functions**, then select **OK**. 60 | 1. Select the **Azure Functions v2 Preview** runtime in the dropdown and start with an **empty project**. Leave the defaults as-is, then select **OK**. 61 | 1. Right-click the project created in the **Solution Explorer** on the right-hand side and select **Add** -> **New Item** 62 | 1. Select **Azure Function** from the list of Visual C# Items and select **Add** 63 | 1. Choose the **IoT Hub trigger** template. If you don't see this template, [update your tools](https://docs.microsoft.com/azure/azure-functions/functions-develop-vs#update-your-tools). 64 | 1. The IoT Hub **Connection String setting** is the name of the environment variable that contains the connection string. We will set this up later, but for now enter `IoTHubConnectionString` as the name of the environment variable. 65 | 1. Leave **Path** as `messages/events` and click **OK** 66 | ![New Project](images/new_project.png) 67 | 68 | ### Getting the IoT Hub connection string 69 | 70 | IoT Hub communicates with Azure Functions triggers via the events endpoint. First we need to get the events endpoint connection string. 71 | 72 | 1. Open up your previously created IoT Hub in the [Azure Portal](https://portal.azure.com) 73 | 1. On the left-hand navigation select **Endpoints** 74 | 1. Click the **Events** endpoint 75 | 1. Copy the **Event Hub-compatible endpoint** and also the **Event Hub-compatible name** 76 | 1. To generate a valid Connection String you need to append the **name** to the **endpoint** with the following template: {endpoint};EntityPath={name} 77 | * For example: if my **compatible endpoint** was `Endpoint=sb://myendpoint.net/;SharedAccessKeyName=123=` and my **compatible name** was `myiothub` my **Connection String** would be `Endpoint=sb://myendpoint.net/;SharedAccessKeyName=123=;EntityPath=myiothub` 78 | 79 | ### Setting the IoT Hub Connection String in the Function 80 | 81 | If you recall from the project creation of the Azure Function, you set an environment variable called `IoTHubConnectionString` as the connection string setting. In order to set this environment variable in your local development, the easiest method is to set it as a value in the `local.settings.json` file. This can store and create environment variables for local development. 82 | 83 | 1. Open the Azure Function project in Visual Studio 2017 84 | 1. Open the **local.settings.json** file 85 | 1. Add an additional `Values` for the `IoTHubConnectionString`. For example (NOTE: don't use this connection string, use yours) 86 | ```json 87 | { 88 | "IsEncrypted": false, 89 | "Values": { 90 | "AzureWebJobsStorage": "UseDevelopmentStorage=true", 91 | "AzureWebJobsDashboard": "UseDevelopmentStorage=true", 92 | "IoTHubConnectionString": "Endpoint=sb://myendpoint.net/;SharedAccessKeyName=123=;EntityPath=myiothub" 93 | } 94 | } 95 | ``` 96 | 1. Save the local.settings.json file 97 | 98 | Now let's test to make sure everything is wired up correctly. 99 | 100 | 1. Click the Run button in Visual Studio (Or in the menu under **Debug** -> **Start Debugging**) 101 | 1. The Azure Functions runtime should start running on your local machine. If you have previous unprocessed events you should see those running and showing the device message. You can continue to simulate or send more messages using the tools outlined in the Connecting a Device section above. 102 | 1. After doing some tests, go ahead and close the Azure Functions runtime and stop the debug session. 103 | 104 | Finally, we will add some simple logic to call an Azure Logic App and post a tweet. 105 | 106 | ## Creating the Azure Logic App 107 | 108 | 1. Open the [Azure Portal](https://portal.azure.com) 109 | 1. Select the **+** or **Create a resource** button and under **Enterprise Integration** choose **Logic App** 110 | 1. Give it a Name, Resource Group, and Region (any will do) and click **Create** 111 | 1. After the logic app is created, open it 112 | 1. The designer should automatically load - if not click the **Edit** button 113 | 1. Select the **When an HTTP request is received** trigger 114 | 1. Click **New Step** to add a step to the workflow and **Add an action** 115 | 1. Search for or select the **Twitter** connector 116 | > NOTE: You are more than welcome to use any action you want to perform on an IoT event 117 | 1. Select the **Post a tweet** action and authenticate this logic app against a valid Twitter account. 118 | 1. Provide some text to be posted. For example: `I just built something awesome with Azure IoT! Try it yourself here: http://aka.ms/azureiotdemo` 119 | 1. Click the **Save** button to save this serverless workflow 120 | 1. Click the **When a HTTP request is received** card to open and reveal the URL generated after saving. Copy that URL. 121 | 122 | ## Calling the Logic App from the Function 123 | 124 | Now that we have the workflow created, we simply need to call it from our Azure Function. 125 | 126 | 1. Open the Azure Function in Visual Studio 127 | 1. Open the `.cs` file (default named `Function1.cs`) to edit the code for your function. 128 | 1. Add the following lines after the `log.Info($"..")` line: 129 | ```csharp 130 | await client.PostAsync("https://prod-07..yourLogicAppURL..", null); 131 | ``` 132 | > NOTE: replace the URL with the unique URL of your workflow 133 | 1. Select the light-bulb prompt to make the method `async` which should change the method signature to: 134 | ```csharp 135 | public static async System.Threading.Tasks.Task RunAsync([IoTHubTrigger("messages/events", Connection = "IoTHubConnectionString")]EventData message, TraceWriter log) 136 | ``` 137 | 1. Click save and test out the function. You should notice that whenever an IoT message is sent the Logic App is called 138 | 139 | Feel free to continue to add logic to the function or logic app as desired. 140 | 141 | Run the function again and test out with the button. It should call the logic app and post a tweet! 142 | 143 | ## Publishing the Function 144 | 145 | When everything is working as expected, right-click the Azure Function project and select **Publish**. You can then set this project to run in your Azure Subscription. Since this entire solution is serverless, you won't pay for the function or logic app unless they are actually executed. 146 | 147 | **Be sure to edit the application settings of the function after publishing** to make sure the environment in Azure is correct. This includes saying **Yes** to the prompt to upgrade the runtime version to `beta` (the v2 setting we specified for our Function on create), and adding an **IoTConnectionString** Application Setting and pasting in the connection string you have in the `local.settings.json` file. 148 | 149 | 1. On the Publish Profile screen after publishing, select the **Manage Application Settings** 150 | ![](images/manage.png) 151 | 1. Click **Add** and add a cloud environment variable for `IoTHubConnectionString` and paste in the value from your `local.settings.json` connection string. 152 | 1. Click **OK** to save the changes - the function show now be listening to the IoT Hub you used locally in the cloud. 153 | 154 | This is just a simple IoT backend leveraging IoT Hub and Azure serverless. You could continue to build more features to this solution as needed. 155 | -------------------------------------------------------------------------------- /images/manage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-Samples/azure-serverless-iot-button/6c0d6c6b933e791543f3dbab383a5cc997aea6d5/images/manage.png -------------------------------------------------------------------------------- /images/new_project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-Samples/azure-serverless-iot-button/6c0d6c6b933e791543f3dbab383a5cc997aea6d5/images/new_project.png -------------------------------------------------------------------------------- /images/shared_selectdevice.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-Samples/azure-serverless-iot-button/6c0d6c6b933e791543f3dbab383a5cc997aea6d5/images/shared_selectdevice.png --------------------------------------------------------------------------------