Azure-Samples / azure-serverless-iot-button

Build a serverless powered IoT application using Azure IoT Hub, Functions, and Logic Apps
MIT License
49 stars 17 forks source link

IoT Hub trigger template is not available in VS 2017 #6

Open tanwang99 opened 6 years ago

tanwang99 commented 6 years ago

VS 2017 version 15.7.1

jeffhollan commented 6 years ago

Can you try step 2 of the instructions here. More than just VS you need the latest version of the Azure Functions tools to have the latest templates

niels9001 commented 6 years ago

And make sure to update your project / start new. After installing the update I couldn't see the template, created a new project and then it was visible.

belurd commented 6 years ago

tanwang99, did you managed to fix it? I have the same issue. VS 15.7.4, Tools of version 15.0.40608.0. i can't find Azure Function in template list at all. In fact there is no Azure-connected templates when trying to add new item to the project.

jeffhollan commented 6 years ago

@belurd do you see Functions when you create a new project? Wondering if you have the right VS packages installed (the cloud workload)

belurd commented 6 years ago

Yes. Create a project works fine. azuretemplates

belurd commented 6 years ago

Could it be something that broke the template usage? I newly created project I got warning on ...Sdk.Functions with text "Not available at this source". image

jeffhollan commented 6 years ago

Very likely. The SDK is what signals to VS to expose the function templates I believe. Can you copy the error you see? And confirm you have the nuget gallery in your nuget sources

gusmally commented 6 years ago

I saw this issue too and was able to work around it. When you are creating the new Azure Functions project, look for a spinning wheel in the bottom left corner saying something like "making sure templates are up to date." I had to wait for that to stop spinning and refresh (took a few minutes), and then when I went to add a new function to the project, the IoT Hub trigger was there.

belurd commented 6 years ago

Thanks for help. I have fixed nuget packages now and can see Azure function in the templates list.

The new problem for me is that in the "New Azure Function" list there is no "IoT Hub Trigger" template: image

Microsoft.NET.Sdk.Functions version is 1.0.14 Azure Functions and Web Job Tools version is 15.0.40608.0

What will differ if I use Event Hub Trigger template?

jeffhollan commented 6 years ago

Event Triggers works fine. Just make sure you have the right path / event Hub name which is by default like “events/messages” — same as IoT Hub trigger template in README

belurd commented 6 years ago

Thank you. I have tried this way too.

What I got at the end:

  1. Used EventHubTrigger.
  2. As a name parameter used Event Hub-compatible name obtained from portal. Sample looks like this now:
    public static class ClickFunction
    {
        [FunctionName("ClickFunction")]
        public static void Run([EventHubTrigger("hubcompatiblename", Connection = "IoTHubConnectionString")]string myEventHubMessage, TraceWriter log)
        {
            log.Info($"C# Event Hub trigger function processed a message: {myEventHubMessage}");
        }
    }

Packages added are Microsoft.SDK.Net.Functions v,1.0.13 and Microsoft.Azure.WebJobs.Extensions.EventHubs v.3.0.0-beta5.

When running debug getting this errors: image As I found in issue tracker the Java error is nothing to be worry about. But those PartitionsIds...

Is there anywhere on GitHub the code example from KeyNote? Have you shared it, @jeffhollan ?

Again, thank you for your time and help. I got the Texxmo button at https://globaldevopsbootcamp.com/ event and really want to make it work.

jeffhollan commented 6 years ago

By default with IoT Hub the name is “messages/events” - try using that and see if it works

belurd commented 6 years ago

Thanks @jeffhollan . I will check it tomorrow.

At the end I fixed function at the Azure portal. Button click tweets now a time when it was clicked.