0
votes

I am new to Azure IoT hub. I signed up for the free tier for Azure. I am trying to test a very simple scenario:

Raspbary Pi Simulator -----> IoT Hub ----> Azure Function

I have set up the IoT Hub and Pi simulator. I am sending data from the simulator to the IoT hub and I can see the messages are received by the IoT hub and the messages received count is going up so the telemetry data is getting to the IoT hub.

Then I created a function app with the following parameters:

  • Runtime Stack ----> .Net
  • Version ----------> 3.1
  • Plan Type --------> App service plan

Then I created a function within this function App using IoT Hub trigger template. I created a new Event Hub Connection and chose IoT Hub as an option and picked my IoT Hub from the list. This created a function for me with the standard implementation of printing any incoming message to logs.

I tried to test the function in the portal by sending the test message from the portal but the function was never triggered and no logs were printed. I did get HTTP code 202 accepted back but the function was never called. The execution count for the function stayed at 0.

I also tried to test the function by sending telemetry data from the simulator to the IoT Hub. My IoT hub message count increases but the function never gets called.

Any pointers you can provide to help me debug this would be greatly appreciated.

Thanks

Karim

Images:

1
Make sure you are using the right connection string as called out in this answer: stackoverflow.com/questions/52743156/…Stefan Wick MSFT
Another thing to check: use a dedicated consumer group, in case the default one is in use by something else on your system.Stefan Wick MSFT
Thanks Stefan for quick response. I have added 2 images to the original question. Image 1 shows the connection string in the Event Trigger screen and image 2 shows the connection string in the function app's configuration. This was added automatically when I created the function. The value of this is set to IoT Hub -> Built-in-end-point -> Event Hub-compatible endpoint. I also tried creating a new consumer group using that but that didn't help. One thing to note is that I do not have any storage in my account. Is that required for functions to work? If yes then what type do I create?Karim Mardhani
I just went through the setup from scratch and everything works fine for me. Two more questions to narrow this down: 1. do you have any routes configured in your IoTHub? 2. if you turn off the Function App do you see the telemetry messages coming out of IoTHub (run 'az iot hub monitor-events -n <iothubname>')Stefan Wick MSFT

1 Answers

0
votes

I was stuck on the same issue too for a while.

To help debug, you can check the function's logs using the Azure Functions extension in VSCode (sadly I haven't found any other way that worked for me yet).

For me the logs had two errors:

[Error] Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.IoTHub_EventHub1'. Microsoft.Azure.WebJobs.EventHubs: Value cannot be null. (Parameter 'receiverConnectionString').
[Error] Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.IoTHub_EventHub1'. Microsoft.WindowsAzure.Storage: Value cannot be null. (Parameter 'connectionString').

Turns out both could be fixed by adding a link to a Storage Account as explained in this answer.

In the end, the new Application Setting named AzureWebJobsStorage should appear like this in your function configuration.