Tech in the 603, The Granite State Hacker

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.

[office src=”https://onedrive.live.com/embed?cid=90A564D76FC99F8F&resid=90A564D76FC99F8F%211283217&authkey=AKQG9LbQcNcUSkk&em=2&wdAr=1.7777777777777776″]

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
    }
  }
}

Tech in the 603, The Granite State Hacker

Is Your Solution Delivery Strategy About to get Avalanched by Windows 10?

HoloLens took the spotlight when //build/ 2015 announced it had sold out in under an hour, but I can’t help but think at least as big a chunk of the excitement is around Windows 10 (or as we developers like to think of it, Windows Unified). As cool as HoloLens is, Windows 10 will most likely be landing in your lap long before HoloLens has images dancing in your living room. 

If you’re not already preparing for Windows 10, your solution delivery stack could be in for a shock from the client up. Microsoft is in the process of launching a re-boot of itself, and Windows 10 is the fulcrum of that effort. As usual, many of its changes are aimed at pulling developers in. If solution development has a place in your organization, this will likely impact you as well. 

“Mobile First / Cloud First” is, as always, the key phrase, and for a client OS… if it’s not for cloud devices…. give it a moment…  let that sink in…   Yes.  Windows 10 is an OS for mobile devices. Even if your device is a big heavy block of a workstation sitting near your monitor.  It will have the same mobile app store as phones and tablets, and it can be managed by the same Enterprise Mobile Device Manager (MDM).

Windows 8 was an introductory / transitional OS. With Windows 10, the transition matures.  Windows 10’s maturity is likely to make it far more palatable than Windows 8 was. (Keep in mind that Windows 8 is only a “failure” in terms of Microsoft’s other OS releases… Windows 8/8.1 has a bigger install base than some of the most “successful” of its non-Microsoft competitors. If Windows 10 becomes the hit many foresee it to be, it has potential to become the de facto standard platform to truly de-throne XP and even Windows 7.)

Windows 10 also adds a bit of a surprise, especially around browser technology.  Microsoft is tossing in to Windows 10 a whole new web browser (in addition to Internet Explorer) currently code-named Spartan. This new browser is intended to go after the consumer browser market, which IE has lost considerable ground in. I speculate that Spartan will be a breath of fresh air for consumers who feel IE’s bloat-related flaws collectively compels them to download Chrome or Firefox.

If you’re a web application developer who does more than a little HTML, on the other hand, you’re probably already groaning. You know what a pain browser compatibility is. (The browser was never intended to be a homogenous cross-everything platform, but that’s how a lot of web designers treat it, and they’ve shaped culture to expect it. Despite the best efforts of tools like jQuery and others to try homogenize, and trends like responsive to try to change the culture of presentation homogeny, web application developers get severely burned in the crossfire.  I’ve got more than a few scars to prove this, but you don’t have to look further than jQuery’s failed mechanisms for helping developers with these issues.    (First there was $.browser and $.browser.version, then $.support… then, “awe… heck… we give up, use Modernizr“.) /rant )

Spartan is a move that makes total sense, but it can’t help but add complexity to web application developers’ lives.  

In fact, in my mind, the long term net message is… there’s only one way to end browser pain… by getting out of web as a client platform. (Web services are the only part of the web worth salvaging.)

Microsoft has seen what platform diversification has done to its core OS business, and it’s not good. Developers need a consistent platform to deliver consistent solutions on, and that’s been a bigger part of Microsoft’s success over the years than even they seem to have realize.

So if web application development is becoming ever more complex in an already over complicated domain, how should one produce and deploy apps?

In a word:  native (aka mobile).

Windows 10 is a unifying platform, a “pentecostal” event to counter the “tower of babel” event of Windows platforms that have fractured into existence since the end of the .NET Compact Framework era. Where before development was requiring more and more effort to support PC, tablet, smartphone, wearable and even Xbox, Windows 10 has a unified SDK across all those platforms. For the first time ever, a .NET developer can build a single solution that runs in all those devices. There may be runtime differences between platforms that have to be ironed out, still, but not compile-time  (if(system.capability.phone) {} rather than #ifdef WINDOWS_PHONE_APP)

And think about it… what are the big reasons for web deployment?   Centralized management and centralized deployment.  Think back to MDMs and mobile app stores.

(Xamarin plays a roll in all this as well. Between Windows 10 and Xamarin, developers will be able to leverage a good chunk of their code base across all hardware, even non Microsoft platforms such as IOS and Android. This, too, is a breath of fresh air, because the cost of maintaining multiple code bases (and talent pools) is ever climbing. Xamarin will likely never be the 110% development experience that the latest .NET framework is, but neither was Silverlight for Windows Phone 7, yet one could do some fairly heavy lifting with it.)

Because Windows 10 is one platform that runs across form factors, it essentially means that any app written for Windows 10 is a mobile app. In that light, it means that Windows 10 is most likely to vault Windows into the top spot for mobile platforms by its projected install base. 

This on top of Microsoft’s recent “trickle up” theory of mobile market share growth, where Microsoft has been grabbing market share by targeting the feature phone market.  (This tactic has little effect in the US, where carrier subsidies nullify the low end to “$0”)  At some point Windows Phone will hit critical mass outside the US. Once that happens, even US developers will no longer be able to afford to ignore it.

Even if Microsoft is not contributing directly to your solution stack, Windows 10 and its biases have potential to culturally influence your solutions and solution delivery over the next decade.

Tech in the 603, The Granite State Hacker

Lumia Denim, Windows 10 Phone

Lots of folks have been looking forward to the impending Lumia Denim update for Lumia Windows Phones.  I know, cause I’m one of them.   I wish I had special insight into when my AT&T 1520 will be updated, but I don’t… so I find myself checking sometimes multiple times a day hoping that the upgrade will suddenly become available. 

The amount of buzz on Lumia Denim is overshadowing a more important update, in my humble opinion.  The Windows 10 Phone update (not Windows Phone 10, but Windows 10 Phone.)

The killer feature for Windows 10 is the integration across hardware form factors…  Desktop, Laptop, Tablet, Phone and even Xbox will all be running editions of Windows 10 (thus we will have a Windows 10 Phone OS, rather than a Windows Phone 10 OS).

Recently my son ran across my old Windows Phone 6.   One thing that made me really love the platform was that I could develop code using the .NET Compact Framework, and the EXE worked anywhere that had a .NET runtime installed… and I mean anywhere.   I literally was able to take an EXE and drag it from phone to desktop and back without any form of recompile, and it would run great on either hardware.   More impressively still, I was able to take DLLs compiled for the .NET CF, and run them in unexpected places, like reference them in ASP.NET web applications…   at one point, I had code for a Sudoku game model that was running desktop, phone, and WEB server!  🙂

Needless to say, I was disappointed by the fact that Windows Phone 7 used a different flavor of the .NET Compact Framework called Silverlight, and Silverlight was a lot less compatible, and required a re-write of my hobby code to make it run.   This re-write wasn’t nearly so portable.  In fact, come Windows Phone 8, I had to we-write a chunk of the code I’d done for Windows Phone 7.   This has been the plight of the Windows Phone developer;  with each release of the OS comes a new set of SDKs to code against.

Like the undoing of the curse of the tower of Babelon, with Windows 10, we’ll see the all the hardware speak the same language again, and this will be huge.   It’s already massive to be able to suggest that you can run tablet apps on your Windows 8.1 machine.  Imagine how it will be when the lines blur further.

So… bring on Denim, please, but don’t hold back Windows 10!

Tech in the 603, The Granite State Hacker

Compact and Full .NET Frameworks

One of the things I’ve been intrigued by for a while now is the fact that code compiled for the .NET Compact Framework (all versions) executes very nicely on the full .NET Framework.

For example, my personal hobby project, “Jimmy Sudoku”, is written in C# for the .NET Compact Framework 2.0. There are actually two install kits. The first is a .CAB file for Windows Mobile devices. The second is an .MSI for Windows 9x, XP, and Vista. The desktop install kit even serves two purposes. First, it installs the program on the desktop. Second, it leverages ActiveSync to push the .CAB up to the Windows Mobile device.

It’s a .NET Compact Framework app especially for Windows Mobile devices, but many ‘Jimmy’ fans don’t have a Windows Mobile device to run it on.

The coolest part is the ease in which all of the components inter-operate. The .EXE and .DLL’s that are delivered to the mobile device are the very same as the ones that are delivered to the desktop. Like Silverlight to WPF, the Compact Framework is a compatible subset of the full framework, so interoperability is a given.

Even better, you can reference CF assemblies in Full framework assemblies. One immediate offshoot of this in my hobby project… the web service I built to service “Game of the Day” requests actually references the CF assembly that implements the game state model and game generator code. The assembly that generates games on Windows Mobile PDA’s & cell phones is the very same assembly that generates games in the ASP.NET web service.

Admittedly, there are some bothersome differences between the CF and the Full .NET Framework. The CF does not support WPF. The CF has no facilities for printing. Also, while the CF does supports some of the common Windows Forms dialogs, it does not support File Save and File Open dialogs on Windows Mobile Standard Edition (Smart Phone / non-touchscreen) devices.

These differences can be overlooked to some extent, though, for the fact that one compiled assembly can execute on so many very different machine types. Further, with interoperability, one can extend a CF-based core code with full-framework support. For example, I’m currently playing with desktop print functionality for my hobby project.

Something that I’d really love to see, some day, is a good excuse to develop a Windows Forms app for a client that had shared components between the desktop and a mobile.

I can imagine that this model would be superb for a huge variety of applications, allowing a fully featured UI for the desktop version, and an excellent, 100% compatible, very low risk (almost “free”) portable version.

I’ve often thought this would work great for apps that interface hardware, like:
field equipment,
mobile equipment,
vehicles of all sorts,

…simply plug in your PDA (via USB or Bluetooth), and it becomes a smart management device for the equipment, using the very same code that also runs on the desktop.

Tech in the 603, The Granite State Hacker

Compromise & Capitulation

There’s three different flavors of Windows Mobile in the 6.x line. Standard, Classic, and Professional.

Standard = Smart Phone, no touchscreen
Classic = PDA w/touchscreen
Professional = PDA / Phone with Touchscreen

One of the other interesting little gotchas is that the .Net Compact Framework 2.0 compiles the same for all three editions. Unfortunately, once in a while, you get a “NotSupportedException” out of the Standard edition.

A few days ago, in order to get my sudoku program published, I decided to simply avoid a problem I had with the Standard edition’s lack of a SaveFileDialog and OpenFileDialog. My avoidance manifested in a “not supported” message of my own, if the user tried to save / load a file in that environment.

Today, I capitulated… I implemented an alternative file save/load functionality which kicks in automatically when the program gets a “NotSupportedException” on the common dialogs.

It’s in 3.0.3, which I’ve re-published on PocketGear.

Tech in the 603, The Granite State Hacker

Jimmy SuDoku 3.0 Released

Those of you who have worked with me on a project in the past few years probably know of my hobby project. It’s an implementation of SuDoku. It’s made for Windows Mobile devices (cell phones, etc.), but it also runs on Windows XP (et al).

The old version, 2.5, had been published on PocketGear. This last update was published in January, 2007, just before I started with Edgewater.

I’ve been hacking at it here & there since then, but the project suffered from lots of maladies… most significantly lack of time.

So after more than a year and a half, I’m happy to finally announce Jimmy SuDoku 3.0!

3.0 has a whole new game state model, based on CLR classes rather than an XML DOM. This means the puzzle generator’s fast enough on hand-held devices that it doesn’t need a web service to do the work for it. Another side-effect of this change is a smaller run-time memory footprint, though I’m not sure by exactly how much.

I also figured out how to leverage the hardware controls on WM6.0 & 6.1 devices so that non-touchscreen devices can play, too.