Sunday, November 19, 2017

MVP IoT with Windows 10, C#, Raspberry Pi and Azure IoT Hub

Boston Code Camp 28 is in the books as one of the greatest community events of recent times in my book.  Attendance was fantastic, we had amazing sponsors, and a ton of great speakers, but the thing that really made things hop was attendance.  I'm personally convinced it was the best attended Code Camp I've ever participated in.

As a presenter, I don't often get to attend as many of the amazing presentations as I'd like, but yesterday I found myself especially regretting that... there was just so much great content from so many great presenters. I did manage to get into more sessions than I usually do... how could I not?

Sure, you get a few "look at this cool stuff I can do" presentations.  These are great for folks looking for inspiration on the tough challenges.  I love the spirit of "look at this cool stuff you can do (if you apply your skills in a modestly different direction)".

This is why I do this MVP IoT presentation.  This presentation is about taking skills you already know and love (namely C# development) and applying them to what's classically though of as "embedded" development.  Yes, there's overhead in this approach...  you might have to use hardware that's slightly better equipped to handle Windows 10 IoT Core such as the Raspberry Pi 2b & 3b... but the difference is mute at small scale, and masked at large scale by not having to have a separate team with different skills. 

IoT apps on the Windows 10 IoT Core platform ARE Windows 10 apps.

The point I always try to drive home is IoT apps on the Windows 10 IoT Core platform ARE Windows 10 apps.  The very same exe you compile for your embedded device runs just as well on laptop, desktop, server, Windows 10 phone, et al.

I do regret the couple snags I had during my demos.  Still, someone approached me after the presentation with the idea that I should pre-record portions of my presentation in order to avoid these kinds of things.  I like to run live for several real reasons.  1)  I'm a coder, not a professional presenter... I don't often have time to polish my presentations to that level.  2)  Glossing over rough edges hides what development is.  Development is tough.  You have to have backup plans and contingencies.  My Raspberry Pi didn't want to connect to the guest WiFi, so I fell back to plan B, and moved on.  It's a real world scenario;  you hit a snag, but keep pressing on.

IoT is already about the last mile of the Sci-fi story, bringing Internet omnipotence to the fringes of reality, enabling the "Computer" of Star Trek (or the Cortana of the modern desktop) to reach it's potential (hopefully without becoming Skynet).
It's the stuff of science fiction... but it's not fiction.
Visual Studio 2017's ability to debug into a remote embedded device and make hot changes to a running executable is beyond top notch; it's the stuff of science fiction... but it's not fiction.



If you look through my post history, you'll see how this presentation has evolved over the past decade.  It's been an interesting evolution...  starting with connecting Windows Phone 7 to SharePoint.  Then Windows Phone 8 and SharePoint online (and the story got really muddy for a bit there).  Then CSOM hit and smoothed out the SharePoint side of things.  I changed the story to Field Enablement using Xamarin for iOS, Android, and Windows Phone with SharePoint as a back end for a bit. (It's a surprisingly compelling story, even if it's only academic).  Eventually I started focusing on UWP for Windows 10, and my love of small form factor development drew me back to Raspberry Pi. 

Finally, I'ved bridged off of SharePoint and started talking about Azure IoT Hub, which is the modern accepted best practice in the domain of this development stack.  This change happened so relatively quickly that if you notice, the synopsis for the session didn't mention it.  (  https://www.bostoncodecamp.com/CC28/sessions/details/16540 )

One can explore the code I developed for the demo at git hub, here:


That leads me to my final bit:  I am sorry I ran out of time in my presentation.  I was so psyched to show how to send telemetry back to Azure IoT Hub, and while I got to step through the code that sends updated reports, I did not get to explore any of what that looks like in the Azure IoT Hub portal, and didn't get to explore the event-driven API on the embedded side that allows you to send code with Device Twin down to a the device.

Here's the event that commits the post:

        private async void iotHubButton_Click(object sender, RoutedEventArgs e)

        {

            try

            {

                using (var client = DeviceClient.CreateFromConnectionString(

                    $"HostName=BOSCC-IOTHub.azure-devices.net;DeviceId=GraniteStHacker;SharedAccessKey={Credentials.LuisAccessKeyFromAzurePortal}", 

                    TransportType.Mqtt))

                {

                    var twinProperties = new TwinCollection();

                    twinProperties["MeasuredTemperature"] = manager.MeasuredTemperature;

                    twinProperties["HeaterPowerOn"] = manager.HeaterPowerOn;

                    twinProperties["ACPowerOn"] = manager.ACPowerOn;

                    twinProperties["Device_BOSCC"] = DateTime.Now.ToString();

                    await client.UpdateReportedPropertiesAsync(twinProperties);

                    Console.WriteLine("Done");

                }

            }

            catch(Exception ex)

            {

                Console.WriteLine(ex);

            }

        }

    }

Click the image below to see the device I was using for the demo in Azure IoT Hub's Device Twin view.


Here's the resulting Device Twin JSON:
{
  "deviceId": "GraniteStHacker",
  "etag": "AAAAAAAAAAE=",
  "version": 8,
  "status": "enabled",
  "statusUpdateTime": "0001-01-01T00:00:00",
  "connectionState": "Disconnected",
  "lastActivityTime": "0001-01-01T00:00:00",
  "cloudToDeviceMessageCount": 0,
  "authenticationType": "sas",
  "x509Thumbprint": {
    "primaryThumbprint": null,
    "secondaryThumbprint": null
  },
  "properties": {
    "desired": {
      "$metadata": {
        "$lastUpdated": "2017-11-14T01:48:45.8322179Z"
      },
      "$version": 1
    },
    "reported": {
      "MeasuredTemperature": 74,
      "HeaterPowerOn": true,
      "ACPowerOn": false,
      "Device_BOSCC": "11/18/2017 8:34:08 AM",
      "$metadata": {
        "$lastUpdated": "2017-11-18T16:34:20.1258514Z",
        "MeasuredTemperature": {
          "$lastUpdated": "2017-11-18T16:34:20.1258514Z"
        },
        "HeaterPowerOn": {
          "$lastUpdated": "2017-11-18T16:34:20.1258514Z"
        },
        "ACPowerOn": {
          "$lastUpdated": "2017-11-18T16:34:20.1258514Z"
        },
        "Device_BOSCC": {
          "$lastUpdated": "2017-11-18T16:34:20.1258514Z"
        }
      },
      "$version": 7
    }
  }
}




16 comments:

cynthia williams said...

Well written post with worthy information. It will definitely be helpful for all. Do post more like this.
Cloud Training in Chennai
Cloud Computing Courses in Chennai
Azure Training in Chennai
Azure Training center in Chennai
VMware course in Chennai
AWS course in Chennai
DevOps Certification in Chennai
Cloud computing Training in Chennai

Sivanandhana Girish said...

This is one of the good blogs where I am able to learn a lot of new information.
IELTS Classes in Mumbai
IELTS Coaching in Mumbai
IELTS Mumbai
Best IELTS Coaching in Mumbai
IELTS Center in Mumbai
IELTS Classes in Chennai
Best IELTS Coaching Centre in Chennai
IELTS Centre in Chennai
IELTS Training Centre in Chennai
IELTS Course in Chennai

sandhiya arav said...

Thanks for sharing these niche piece of info's to our knowledge. Here, I had a solution for my inconclusive problems & it’s really helps me a lot keep updates…
ccna Training in Chennai
Best CCNA Training Institute in Chennai
Ethical Hacking Course in Chennai
PHP Training in Chennai
Angularjs Training in Chennai
ccna course in chennai
ccna training in chennai

lekha mathan said...

Very good information provided, Thanks a lot for sharing such useful information.
Aviation Academy in Chennai
Air hostess training in Chennai
Airport management courses in Chennai
Ground staff training in Chennai
best aviation academy in Chennai
Air Hostess Training Institute in Chennai
Airline Courses in Chennai
airport ground staff training in Chennai

Anbarasan14 said...

I am really impressed with the way of writing of this blog. The author has shared the info in a crisp and short way.
Spoken English Classes in Coimbatore
Best Spoken English Classes in Coimbatore
Spoken English Class in Coimbatore
Spoken English in Coimbatore
Coimbatore Spoken English Centre
Best Spoken English Institute in Coimbatore
Spoken English Institute in Coimbatore
Spoken English Course in Coimbatore

janakikrishnan said...

Most Useful blog for everyone who wants to gather a lot.

CCNA Course in Madurai
CCNA Course in Madurai
Best CCNA Institute in Madurai
CCNA Course in Coimbatore
Best CCNA Institute in Coimbatore
CCNA Training in Coimbatore

Kayal m said...

I recently saw your post! I was very happy to visit your blog. I like so much and I hope more valuable post from your post...

Unix Training in Chennai
Unix shell scripting Training in Chennai
Excel Training in Chennai
Corporate Training in Chennai
Embedded System Course Chennai
Linux Training in Chennai
Tableau Training in Chennai
Unix Training in Chennai
Unix shell scripting Training in Chennai

kim john said...

Great info. The content you wrote is very interesting to read. This will loved by all age groups.
Angularjs Training in Chennai
Angularjs Course in Chennai
CCNA Training in Chennai
Salesforce Training in Chennai
Angular5 Training in Chennai
Angular6 Training in Chennai
Angular7 Training in Chennai
Angularjs Training in Chennai
Angularjs Course in Chennai

Vicky Ram said...

Excellent post! keep sharing such a post

Guest posting sites
Technology

sandeep saxena said...

Thank you very much for shared this. I got lot of ideas after reading this. Share more as similar to this.
core java training in chennai
core java training institutes in chennai
core java Training in Velachery
C C++ Training in Chennai
javascript training in chennai
Appium Training in Chennai
JMeter Training in Chennai
core java training in chennai

kiruthika said...

This is really a valuable post... The info shared is helpful and valuable. Thank you for sharing.
aviation training in Chennai
air hostess academy in Chennai
Airline Courses in Chennai
Ground staff training in Chennai
Aviation Academy in Chennai
air hostess training in Chennai
airport management courses in Chennai
ground staff training in Chennai

Mark ben said...

Thank you for your valuable content , Easy to understand and follow. As said, the migration to cloud is very essential for the protection of the database.

Cloud Migration services
Aws Cloud Migration services
Azure Cloud Migration services
Vmware Cloud Migration services
Database Migration services

kavithasathish said...

Great information you have been shared and it will be useful to everyone.
Spoken English Classes in Chennai
Best Spoken English Classes in Chennai
German Language Classes in Chennai
Japanese Classes in Chennai
spanish language in chennai
IELTS Coaching centre in Chennai
Spoken English Classes in Porur
Spoken English Classes in Adyar

Kerrthika K said...

It's a great article!!look's impressive and it's useful blog for us
Blockchain certification
Blockchain Training in Chennai
film making courses in chennai
film direction course in chennai
part time film direction course in chennai
Data Analytics Courses in Chennai
Hadoop Admin Training in Chennai

MidiTech said...

I am definitely enjoying your website. You definitely have some great insight and great stories.
VPS Hosting India

high technologies solutions said...

I have been following your post for a long time. I always found it very interesting and valuable. keep posting it is really helpful.

cloud computing course in delhi

cloud computing course in Noida

cloud computing course in Gurgaon