Tech in the 603, The Granite State Hacker

Locking Resources in C# for Read/Write Concurrency

In a previous project, I became a big fan of System.Threading.ReaderWriterLockSlim.  It was an excellent way to guard a resource against concurrency in a relatively flexible manner.  

C# has a lock(object) {} syntax for simple concurrency locks, but what if you have a resource that can sometimes be used concurrently, and other times, exclusively?

Enter System.Threading.ReaderWriterLockSlim.  This has a few handy methods on it for guarding code on a non-exclusive (Read) and exclusive (Write) mode, with an upgradeable lock, as well, so you don’t have to release a read lock in order to upgrade it.

This source works just as well in .NET as UWP.

I commented the code enough to try to make it so that someone familiar with ReaderWriterLockSlim and using(IDisposable){} would understand the rest, so without further ado…

https://gist.github.com/GraniteStateHacker/e608eecce2cb3dba0dbf4363b00e941f.js

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

Intro to Rx.NET (Reactive Extensions)

Thanks to the gang for joining me at the Microsoft Store in Salem NH for my preso on “Intro to Rx.NET”   Being that it’s a toolkit I’ve been digging a lot at work lately, I had a feeling folks might appreciate a broad brush into to it.

Please check out the Granite State (NH) Windows Platform App Devs (#WPDevNH) on meetup.com to connect with the group and maybe even participate, yourself.  In addition to the core presentation topic, we had a great debate in speculation on how Microsoft’s purchase of Xamarin might settle out.  Also, I’ll be attending Build 2016, so we’re talking about having a special meeting early in April to recap and consider future presentations. (stay tuned!)

Rx reminds me a lot of other declarative language elements (XSL, XAML) in that it seems really natural, then you start looking at more advanced stuff and the complexity becomes boggling… then you start to really understand the abstractions and it feels natural again.

Without further ado, here’s my slides for the presentation:

[office src=”https://onedrive.live.com/embed?cid=90A564D76FC99F8F&resid=90A564D76FC99F8F%21824879&authkey=AC01r6jwJX5ng5M&em=2″ width=”402″ height=”327″]
I’d like to thank the folks at http://IntroToRx.com, I referenced them more than any other source putting this together.
Finally, for the code I demoed, please check out the post I mentioned, here:
Hope to see you soon!
-Jim Wilcox
The Granite State Hacker
Tech in the 603, The Granite State Hacker

KB3035583 – Where is the Windows 10 Invitation to Upgrade?

I’ve had a lot of folks express confusion over Windows 10…  It is FREE for the vast majority of existing Windows users. (Only some corporate PCs may run into a cash register.)  It’s also very easy to install for the vast majority of users.  I’m so confident with the upgrade process that I’ve handed off one of the URLs below to my folks, and told them to call me if they have a problem… 

The invitation to reserve Windows 10 is triggered from an update that rolls out over WSUS, described by Knowledge Base article KB3035583.  The reservation is essentially passed since the software is officially released, but here’s some detail on it if you’re curious…

The following URL is the KB article, which describes update that triggers the invitation to reserve Windows 10, mentioning that Enterprise machines do not apply:
https://support.microsoft.com/en-us/kb/3035583


The following article indicates that once installed, the KB3035583 update will also exclude itself from being applied Domain Joined machines:
http://rainesy.com/what-is-the-update-kb3035583-you-might-ask/


But the most important question to answer at this point… 
HOW TO UPGRADE TO WINDOWS 10 NOW:

I’ve had a couple links at the ready since I’ve been answering questions like this a lot lately across both business and personal connections…  here’s a post on how to download & install Windows 10 immediately for an individual system: 
www.microsoft.com/en-us/software-download/windows10

If you’re looking for more information on how to roll Windows 10 out across a company infrastructure, there’s a high level set of options, outlined in the following post:
https://technet.microsoft.com/en-us/library/mt158221%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

There’s a ton of great reasons for a company to deploy Windows 10, including

  • Universal Apps that enable you to extend your code base and/or future code effort across the entire Windows spectrum
  • A host of attractive, industrial-strength BYOD options for more than just tablets and smartphones
  • The most efficient and consistent use of latest generation hardware including touchscreen and security measures

Microsoft is preparing to *upgrade* over a billion Windows devices to Windows 10.   We’re proud to be a part of that, and very happy to help in any capacity we can getting the bits pushed out to all your machines. 


As a developer, I’m very happy to promote the platform I most want to work on… I really feel that Windows 10’s success is the foundation of a lot of others’ success, including my own.

Tech in the 603, The Granite State Hacker

Intro to Windows 10 Universal Devices and Raspberry Pi

I really enjoyed presenting “Intro to Windows 10 Universal with Raspberry Pi” to the Granite State Windows Platform App Devs (#WPDevNH) this past week. 

Here’s the slides which have a few decent links in them to get you started.

[office src=”https://onedrive.live.com/embed?cid=90A564D76FC99F8F&resid=90A564D76FC99F8F%21470743&authkey=AFGBvV7-jEFyGVA&em=2″ width=”402″ height=”327″]

I will try to get a presentation on the next part of this sometime over the next couple months, with a dive in on the GPIO libraries.

Check out the group’s Meetup site for stuff going on going forward.

http://www.meetup.com/Granite-State-NH-WPDev/