IoT in .NET with a Raspberry Pi, Azure IoT Hub, and Xamarin

Back in November 2017 I blogged about a small home IoT project, wiring up garden lights and my garage to the internet through a Spark Core IoT device, accessed via a Xamarin app. That was so fun, I got more ideas and thought I’d do it again with a much more ambitious project. A fully automated and autonomous, IoT home security system.

This blog post is on Medium, so please go here to read it.

I’ll also be presenting this at the next Melbourne Xamarin Meetup, so if you’re in Melbourne come down on April 15, 2018.

IoT Internet Connected Home Project - Garden Lights and Garage Door with a Mobile App!

I’ve finally got in to some long awaited IoT with items I bought over 4 years ago that were lying dormant in storage containers. I backed Spark Core on Kickstarter on 31 May 2013, that’s how long I’ve been meaning to do something with it. Finally that time arrived.

Together with a Spark Core Relay Shield and a garage door magnetic reed switch which I bought around the same time, four years later I was ready to go.

Read More

My Xamarin Melbourne Meetup Presentation – September 2016

Today, Thursday 22 September, I spoke at the Xamarin Melbourne Meetup Presentation. The topic was “Getting an app ready for release - The optional things which probably shouldn’t be optional”. It was a discussion on the steps and measures developers should probably take to make their Xamarin Forms apps faster, more secure and more stable.

It went well with lots of discussion :) I’m hoping most people found the content useful for their apps.

Below is a link to download the presentation, where I covered 2 main topics. Network Resiliency & Speed, and Security. There are lots of links in the PDF with further, more complete information.

Download Presentation in PDF

Good luck, and if anyone at the meetup has any questions, just send me an email.

A Xamarin Forms example using SQLite.NET-PCL with Async

UPDATE: I do not recommend this solution anymore. The SQLite library used is unmaintained, has locking issues, and does not work with Android 8 (however someone kindly sent through a PR to update Android support). I recommend this nuget package moving forward.

It took me a while to gather information from various sources to get a working base of SQLite.NET in Xamarin Forms using all asynchronous operations, so I thought I'd whip up a small demo app showing all the plumbing in place, with basic data been added and retrieved from the database.

The solution can be found here:

I had a lot of issues with how dates got stored in the database. Everything coming from and back to the server was in UTC, and the only way I could reliably get dates out of the SQLite database was by storing DateTime as ticks in SQLite. This is an optional parameter on SQLiteConnectionString in the iOS/Android concrete connection implementations. Also make sure you explicitly set DateTimeKind to UTC when inserting DateTime's in the SQLite database.

Another thing is, you need class level locking around your database calls, or else you risk dead locking the app. This is a must. AsyncSemaphore comes to the rescue here.

Also there was no way I could drop database tables asynchronously, it just simply didn't work. I had to always use non async connection for dropping tables.

You also might find SQLite-Net Extensions very useful, I did, and it reduced the amount of code I had to write greatly. You can find more information about it here I might blog about some tips and tricks of using this simple ORM at a later date.

Hope this helps getting you started :)