Function Apps. Serverless Compute. Simulated Devices. NOW with added Application Insights! How simple is this...
Published Feb 12 2019 02:52 PM 263 Views
Bronze Contributor
First published on MSDN on Mar 31, 2017

Authored by Peter Laker

Just another post about my love of the serverless compute that Microsoft now give us.

So I wanted to spin up a simulated device to pump some dummy data into IoT Hub.

Reach for the Console App? Not my first choice these days.

Reach for a NodeJS script, or NodeRed flow on a Linux VM? Too old skool. Overkill even!

New C# Timer-triggered function (default option), with just this code:

#r "Newtonsoft.Json"
using System;
using Newtonsoft.Json;
using System.Text;

public static void Run(TimerInfo myTimer, TraceWriter log)
var msg = new { Value = DateTime.Now.Second.ToString() };
SendMessage(msg, "MyIoTHub",

static void SendMessage(object body, string iotHub, string deviceId, string apiVer, string sas)
string restUri = $"https://{iotHub}{deviceId}/messages/events?api-version={apiVer}";
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", sas);

var content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
var result = client.PostAsync(restUri, content).Result;

And that's it!

No dlls to upload (it's just HTTP REST)

No config or deploy or setup

It defaults to once per five minutes, but you can change that in the "Integrate" section of your App editor.

And of course I can ARM deploy this, code sourced from GitHub.

And if that weren't good enough, I now hear that Application Insights is available in beta for you to try with your [non-production] Logic Apps.

The Function App team listening to user requests once again , have delivered as promised.

This gives us a feature rich array of tools to monitor and analyse performance, throughput and so much more!

Thanks for reading!

Pete Laker (Azure MVP)
Version history
Last update:
‎Feb 12 2019 02:52 PM
Updated by: