Thomas Telaak

Earlier this year Microsoft released a new feature in Azure – Azure Functions.

Azure Functions opens the possibility to write serverless code (JavaScript, C#, Python and PHP) which can be triggered by events (or by a timer) in Azure.

Recently we used Azure Functions in a project to send a file upload command to a device connected to an Azure IoT Hub triggered by an http call.

After creating a function app in Azure Portal we were able to choose between a lot of examples to get started. We chose the HTTP Trigger C# example.

Azure Functions Examples

We changed the query parameter to ask for a device id, so that we could invoke this function with the URL provided by Azure Functions + our Device ID.

Then we needed a C# method to send a command to the IoT Hub which delegates it to the corresponding device.

To do it easy like this we needed to add some dependencies (Azure IoT Hub Service SDK) to our function. Luckily we were able to use Nuget in Azure Functions.

The trick is to add a new file project.json (klick on “View Files” bottom left of the code window to see and add your function’s files) and add your dependencies like this:

Function App Project JSON

To test the code immediately Azure Functions provides a “Run” Button and a “Log” window for debug information.

Azure Function Debug

It is also possible to use Visual Studio Online (Open Azure Function App Settings -> go to App Service Settings -> Tools -> App Service Editor) to write your code with features like IntelliSense.

So if you need a fast way to develop a small solution to process data inside Azure – Functions is a great tool to this.

If you have any questions – feel free to ask.

Have Fun !