IoT Garage door monitor based on Adabox003

Software - iOS

You can get a copy of the iOS app (free) from the Apple app store here.

Below are screen captures of the iOS app. As you can see, it's fairly basic.

     

Swift is the current language of choice for building iOS apps. So, I needed to find an MQTT library for Swift 3.1. The CocoaMQTT framework worked nicely for this project. There are several other Swift based MQTT frameworks available.

If you are not already an Apple developer, it may be more effort (and expense) than you're willing to deal with to install XCode (Mac only) and pay for a Developer account ($99). For those of you who are Apple developers, or just want to try the source code out in the simulator, the github page is here. The source files and a .zip of the entire folder including project and workspace files is in the iOS folder.

When the app starts up, it first checks to see if it has a remembered AdafruitIO account and password. If not, the code will immediately request an account name and AIO (password) for your io.adafruit.com account. The password generated by Adafruit is rather long to transcribe. I'd suggest you copy and paste it to make it easy. The app will remember the account and password for subsequent uses.

After that, the app is fairly simple. When the app becomes active, it checks the state of the connection to the broker. If a reconnection is required, the garage door state is set to "Unknown" and the open/close buttons are set to disabled with a label of "open/close". Once the broker connect is established, a count down timer is shown to provide some feedback as to how long the user may have to wait to get the state of the garage doors.

There is a "Log" button in the interface that allows the user to show, hide, clear, and email the log file. The app records many of the states it transitions through as it works. The size of the log file is currently limited to about 15,000 characters. The log was created for debugging purposes.

Things learned writing/debugging the iOS code

This isn't news to iOS developers, but iOS apps can exist in a few states on your iPhone. The most obvious are the active app (foreground) and not the active app (background). However, apps in the background are permitted to run for a short time when they move from foreground to background. After this grace period, they become inactive (except for some special cases). After some period of inactivity, any network connections the app once had are closed (timed out really). So as the app moves into the foreground, it may have to reestablish any network connections.

Again for robustness, when moving to the foreground the iOS app checks to see if the network connection is intact or 30 seconds has elapsed since it was moved to the background. If either is true, it closes the "current" connection and reestablished a connection to the MQTT broker.

The app logs almost everything it is doing. By default, the log is hidden. By clicking the "Log" button in the upper right, you can hide/show the log, clear it, or EMail the contents of the log to someone. The log is currently limited to roughly 15,000 characters and is saved between sessions.

As built, the app can only use io.adafruit.com as the broker. Perhaps in a future version this will be configurable as well.