My Doorbell Runs Swift – iOSDevCampDC 2017

Screen Shot 2017-08-04 at 1.57.34 PM

I just gave a talk at iOSDevCampDC 2017 about building an Internet of Things bridge in Swift on a Raspberry Pi.  Here’s the deck on SpeakerDeck, and I also exported the slides with my notes into a PDF:

Slides on SpeakerDeck

Download Slides with Notes (PDF)

Also, here’s my demo video:

My Doorbell Runs Swift DEMO on Vimeo

Advertisements
Featured

Setting up a Raspberry Pi for Swifty IoT

I recently gave a talk on implementing an Internet of Things bridge in Swift using a Raspberry Pi. If you’re interested in following in my footsteps, here’s a quick abridged guide on how to set up your Pi. Many smart people have done the heavy lifting here, I’ve just put the building blocks together. Where appropriate, steps link out to these external tutorials with more information.

Prerequisites:

  • Raspberry Pi 3
  • 8GB+ SD Card
  • HDMI Display
  • USB Keyboard and Mouse
  • A way to connect your Pi to the internet (WiFi or Ethernet)

1. Install Ubuntu

The best distribution of Linux for running Swift on Pi is Ubuntu Mate. Version 16.04 is recommended for compatibility with Swift. You can find instructions for installing it on your Pi here.

2. Install Swift

Swift is open-source and supports Linux as a platform for running the compiler. Getting the whole thing standing up on a Pi is a bit complicated, but luckily Umberto Raimondi has provided an amazing service by hosting precompiled Swift binaries for the Raspberry Pi 3. Instructions for installing those are available here.

3. Start a Vapor project

I found that the easiest way to get a Vapor project started is to just clone a simple sample project and build off it. Here’s a good starting point, git clone this to a directory on your Pi.

4. Add Dependencies

My project used additional libraries, SwiftyGPIO and vapor-apns. To install these, add the following dependencies to the Package.swift file:

        .Package(url: "https://github.com/uraimo/SwiftyGPIO.git", majorVersion: 0),
        .Package(url: "https://github.com/matthijs2704/vapor-apns.git", majorVersion: 2)

Then, run a swift package install

5. (BONUS!) Install Dataplicity

If you want to access your Pi from outside your network, Dataplicity hosts a remote access service designed for Raspberry Pi, and it’s currently free for one device! I can’t recommend them enough, they even provide an externally resolvable hostname for your Pi to use, so you can connect to it from the internet. Here are instructions for setting up Dataplicity

The End!

That should be it! You should now have everything you need to do cool, Swifty IoT things with your Raspberry Pi!

If you have any questions or concerns, feel free to reach out on Twitter: @huebnerob

ADAPTiD

Image

Aesthetic Design Algorithm for Public Transit Information Diagrams, ADAPTiD for short.  As of yet, it’s just a dinky line simplifier that has been fed data from NYC’s PATH rail system, which connects Manhattan with points west across the Hudson.  Yes, giving such a project an acronym already is perhaps akin to publishing my work on “Hello World”.  This is true, but there’s no one out there to deny my request to acronym-ize myself so soon; perhaps I’ve abused this liberty.

So why does the world need a program that can automatically generate subway maps? Well if you’re anything like me and you live in a city, public transit is how you get around.  You refuel not at a gas pump but at a MetroCard machine.  You laugh as drivers kill each other over parking spots.

But then there are those times you’re left standing on a train platform — you’re waiting for a train that you must eventually admit will never come. Transit maps are designed to be accurate at one time: rush hour on a weekday.  Every other second (which is a lot of seconds), you need to know what the exceptions are and what they mean.  And when you start considering planned and unplanned service disruptions, that map might never be accurate.  So keep on waiting, that train’s not coming, not today.

But what if you could design a subway map that’s always right? It would look at the day and time and show you only the service that’s running.  If you’re lucky, it would even check for reroutes and suspensions, and adjust itself accordingly. I think we have the technology.