Dismiss Notice

Register now to be one of the first members of this SharePoint Community! Click here it just takes seconds!

Dismiss Notice
Welcome Guest from Country Flag

Function Apps. Serverless Compute. Simulated Devices. How simple is this…

Discussion in 'Official Microsoft News' started by Pete Laker, Apr 1, 2017.

Thread Status:
Not open for further replies.
  1. Pete Laker

    Pete Laker Guest

    Blog Posts:
    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}.azure-devices.net/devices/{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.

    Thanks for reading!


    Continue reading...
Thread Status:
Not open for further replies.

Share This Page

LiveZilla Live Chat Software