While there are plenty of smart devices to control central heat and air conditioning, these will not usually work with portable units. Using a Raspberry Pi with a few simple electronics, I was able to upgrade the control of my window A/C unit.
At a minimum, I wanted to turn the A/C on and off from my phone. This is nice at the end of the day when I go to bed and realize I left the A/C running from the other end of the house. A remote control was included with the A/C unit but the range is obviously limiting. By coupling an infrared receiver to my Raspberry Pi, I was able to teach the Pi the infrared signals from the remote using an open source Linux package — LIRC. Then I connected an infrared transmitter to the Raspberry Pi to relay those same signals such as Power, Temperature +/-, Mode, etc… That could allow the unit to be controlled from anywhere.
While sending the remote control’s commands is useful, it also would be helpful to know whether the unit is on or off. For this I attached a vibration sensor that will notify the Pi when any vibration is detected in the last 5 seconds, which will be interpreted as the A/C is running.
This setup allows the Pi to communicate with the A/C unit, but I needed to communicate with the Pi. I opted for an Apple Shortcut that sends SSH commands to trigger the individual scripts. This is not the most elegant interface but it does the job.
If you’ve been watching the server-side Swift changes this year, you may have noticed the building momentum. The Vapor community reinforced their commitment to server-side Swift by pushing significant updates in Vapor version 4. That was followed by a new server-side Swift platform — the Swift AWS Lambda Runtime, complete with a WWDC video. Apple also dropped Vapor’s name during a State of the Union demo. Finally, the Swift Server work group has been expanding, so we should expect to see more server-side Swift features trickling out in the near future.
I hope some of the recent positive developments encourages you to consider why Swift on the server may be a good choice for your next server project. But I’d really like to encourage iOS developers to consider writing Swift server apps, even as experiments, to make better iOS apps. There is a synergy between iOS development and Swift server development that compliment one another and justify the investment.
Modularizing your App
To leverage the benefits of Swift server development, you will likely want to share some existing iOS app code with the server. The server-side solutions are built around the Swift Package Manager. If you are not already using packages to modularize your iOS app, you will need to spend some time moving code into a package. This requires separating the iOS-specific parts (ex: UIKit) from the things you want to reuse on the server. The scope of this effort depends on how intertwined the project code is. But once you move even a portion of your app code to a package, you will likely be thrilled to watch in run on a server. Your code is now more modular, opening up opportunities to extend to even other iOS apps.
Become more proficient with Swift
To learn a new development skill, we often need to experiment with technologies that add little value to our primary skill sets. Take for example my desire to expand to server-side development several years ago. My day job consisted of iOS development but I wanted to learn about the web. So I ventured into the world of Node.js and created a few simple web apps for personal use. While I don’t regret doing that, the results could have been better. These web apps got very little of my attention as I didn’t have a good reason to maintain my Node.js skills and I’d cringe at the idea of jumping back into unfamiliar code.
I can contrast that experience with the time I took recently to convert those apps to Swift Vapor apps. In this case I’m working with Swift — a language I’m familiar with. If I return to that project in a year, I’ll at least be comfortable with the language. Additionally, each time I work with Swift on the server, there is a chance I will learn something new about Swift. That value will translate into better apps on both sides and help justify the time spent.
Time To Learn Something Really New
As I mentioned, it is compelling to learn a new skill that strengthens your existing skills — like cross-platform Swift. But I think we all crave an unfamiliar challenge too. Apple offers a stream of new APIs to keep us busy. But the environment for server-side Swift is a different animal. Working with technologies like Docker, Linux, AWS and Heroku is unlike anything you will see in the Xcode editor. That shift in paradigms may widen your perspective on development possibilities for your company/app and build some confidence to take on even bolder solutions.
How to Get Started
I suggest starting with small experiments to get comfortable in this space. Maybe write a Hello World app with Vapor 4 and contrast that experience with running Swift code on a server with an AWS Lambda deployment. Once you are comfortable with the basics, consider migrating parts of your app to a dedicated Swift Package that can be used by Vapor or AWS. I think you won’t regret the time spent here and at a minimum will learn some new Swift skills, have a more modular app and will have some fun taking on a new challenge.
Productivity is one of my favorite discussion points. Not because I’m an expert (far from it) but rather I’m constantly learning and it affects nearly every aspect of life. I was drawn to the Get Things Done methodology years ago and more recently inspired by a book called Deep Work. There is a firehose of information out there but only so many changes I can make at once. I’ve reflected on some of my core habits and decided it is time for concrete adjustments. Here is a list of my productivity resolutions for the new year which I hope can help you too.
1. Multi-day Project Focus
I previously split up each day to work on several different projects. I’d spend two hours on project A, two hours on project B, …, and rinse and repeat tomorrow. I relied on my Apple Watch timer to tell me when it was time to move to the next project. While touching every active project daily is satisfying, the practice breaks momentum and hinders engagement.
Instead, I plan to work on a single project for several consecutive days, until it is finished. I’ve experimented the last few weeks and the results have been promising. I’ve been more engaged and even caught myself working well past my usual quit time. Additionally, I was thinking more clearly and creatively about the task under focus. Interruptions occurred but I was quick to mitigate the impact on my current project.
2. Define “Done” For Everything
Business projects often have a clear deliverable that will mark its completion: “Email the proposal” or “Publish the blog post”. But personal projects can be more open-ended: “Learn C++” or “Learn how to cook”. The realm of self-development and learning can fall in this trap easily which may only be defined by improving a personal quality. This can lead to aimless experimentation and wandering. These projects tend to outlive everything else on my to-do list.
For the new year, I won’t plan to work on something if I haven’t defined what it means to complete it. Rather than “Learn C++”, try “Release an iOS app that uses C++”. Or instead of “Learn how to cook”, I could “Cook a great meal for my parents” (Mom and Dad: this is an example only).
I recently wanted to learn about Apple Shortcuts. My technique was to make something useful for myself. This was a step in the right direction but it was hard to know when I was done. I decided to define “done” as releasing a post about the experience and sharing the Shortcut. Hitting the “Publish” button and uploading the Shortcut was a small victory and gave me permission to move onto other projects.
3. Face the Unfinished
The early stages of a new project are exciting. The possibilities are wide as you plan for the future. But once the scope is defined and the plan is established, the excitement may dissipate. I’ve been guilty of chasing the initial high on personal projects before. These abandoned efforts are mentally draining. A nagging, half-finished initiative decreases my motivation to conquer new goals.
In 2019, I plan to revisit my unfinished, important work before starting something new. I’ll define a deliverable if one didn’t exist (see #2). Then I’ll singly focus on it until complete (#1). I mentioned the thrill of starting a new project but that is no comparison to the satisfaction of finishing it.
These productivity changes will be experimental for me and I’m sure there will be complications to consider. I’ll report back on the experiences. What productivity strategies work best for you?
Apple’s commitment this year to promote the Shortcuts app, formerly known as Workflow, has spurred excitement among a growing group in the iOS community. Shortcuts allows users to automate iPhone/iPad tasks, analogous to the Mac’s Automator. While this app is accessible to those without any development experience, I’d like to share the experience of developing my first Shortcut as an iOS developer. Additionally, I hope the resulting Shortcut will save some Jira users some time. First, here is the background on the process I chose to optimize with Shortcuts.
Nearly everybody involved in creating software needs tools for documenting software bugs. The most ubiquitous tool for tracking bugs is Jira which I use daily. To track a new bug in Jira I stumble upon on an iOS device, I follow these steps:
Capture a screenshot or video of the bug on my iPad/iPhone.
Create a case in Jira documenting the bug.
Annotate or trim the aforementioned media.
Upload and attach the media to the Jira case.
Delete the media from the iPad/iPhone.
This process seems simple enough in theory but has some minor challenges. My iPhone and iPad Photos app is littered with software screenshots, some months old that I neglected to delete after uploading to Jira. Attaching the screenshot to the case can also be cumbersome as I need to move the media to the device that has the related Jira case open. The Jira App for iOS can make this simpler; however, I prefer to create cases on my Mac for speed of entering the details.
My aim was to optimize this with a Shortcut that can walk me through the steps of uploading my most recent media to my most recent Jira case and the subsequent media deletion. I was excited that Shortcuts was up for the task and jumped right in.
Shortcuts First Impressions
I’ll admit that I spent no time reading documentation or watching tutorials for Shortcuts before getting started. I think that speaks to the approachability of Shortcuts (and my impatience to play).
The Shortcut interface offers many options that require no background in development. Using Shortcuts’ drag-and-drop interface, one can compose actions to play a song, send a text message or search the web, for example, without any familiarity with programming languages. But much more power exists in this tool that will be familiar to developers and an excellent primer for those that want to learn more about development.
Some of the features familiar to developers are variables, conditional and control constructs, arrays/dictionaries and code comments — just to name a few. There are also powerful APIs available to fetch data from from the web, parse JSON and even SSH to other devices (and much more). I was delighted to find so much flexibility so I did not plan to limit the scope of this Shortcut initially.
Like many complex apps, Shortcuts will be more efficient to develop on an iPad than an iPhone. The larger form-factor and persistent sidebar makes it much easier to navigate the interface and add actions. The use of an external keyboard can help as well and I’m curious how the Apple Pencil would improve drag-and-drop functionality. .
But the iPhone makes it very convenient to develop Shortcuts during small idle periods when your iPad may not be on hand (Uber, bank line, etc..). This was a new experience for me and I got hooked to it the way many play games on their phones. I have some mixed feelings on the distractibility factor but developing in spare contexts was interesting.
This Jira Shortcut morphed into a more complex tool than I expected. It makes several API calls to Jira, processes the results, requests input from the user, shows error messages and more. As a developer, my inclination was to break these individual components into smaller Shortcuts for modularity and usability. This was clearly a wrong turn when I decided to share the shortcut which would have required a user to download multiple Shortcuts for one feature. So I ended up joining 3 different Shortcuts into one Shortcut as I neared completion.
Security also required thought on this project. The Shortcut will need access to a user’s Jira credentials (username + password or token). All the actions and parameters for a Shortcut are stored to the Shortcut app’s sandbox. While storing usernames/passwords is not ideal, the primary risk I see here is a user accidentally sharing those credentials if they ever redistribute their Shortcut (“Hello World.. oops here is my login!”). I attempted to work around this by using import questions which will request sensitive user information on installation and not share those user inputs if that Shortcut is later shared. I have not verified this so caution against sharing any Shortcuts with personal information captured.
Nearing the end of this project, I realized there is a limit to how much additional functionality you want to pack into a Shortcut before you may want to consider writing an iOS app instead. It can be tricky editing a Shortcut since it lacks copy/paste support for actions and the lack of functions makes it difficult to reuse logic. I also missed simple common language features such as “else if” and “break/continue”. Finally, all this work to develop the Shortcut cannot be ported outside the context of the Shortcut (i.e. another iOS app, Mac, etc..).
But Shortcuts is not designed to be a replacement for traditional software development or apps. It is however an excellent tool for automating tasks on the iOS platform, even for iOS developers. I’d certainly use Shortcuts again when the task to automate is the appropriate complexity level. Then if it gets too complicated, I’ll consider writing an iOS app. I hope non-developers can use Shortcuts too as an introduction to software development in a familiar environment.
If you are a Jira user and wish to fiddle with this Shortcut with your account, you can download it on my Github. I welcome feedback and pull requests.
I can’t count how many times I’ve started a load of wash and forgot about it until the next day. Then I’m forced to play the game of clothing roulette — maybe it is not too late to throw it in the dryer? But if the post-dryer smell check reveals my assessment was wrong, the cycle needs to repeat again. My 27-year-old washer is not winning any eco-awards these days — it doesn’t need to add “redundant loads” to its list of offenses.
There are features in new washing machines to help prevent the rewash problem – an all-in-one washer/dryer or a smart washer that texts you notifications when the cycle completes. Purchasing a new washer is likely the best solution from the standpoint of energy efficiency and time but where is the fun in that 🙂 I read about a few other hobbyists that tackled this problem so I was inspired to try my own version.
The brains behind this washing machine hack is the Raspberry Pi Zero W model, which can be purchased used for around $25. I coupled it with a vibration sensor, available for less than $5, to detect the shaking of the washing machine. Several magnets were glued to the inside of what was formerly a drill bit case for easy attachment to the side of the washer.
After assembling and coding this simple vibration monitor, I recorded the activity of a single 40 minute wash cycle. The spinning and washing stages of a cycle trigger millions of vibration events while the filling stages produce motionless periods for up to 6 minutes. Understanding these motion and idle phases helped me to write the C++ code that tracks when the cycle appears to start and end.
With this information, I could alert myself after every wash cycle completes with a text message that it is time to unload. While a text reminder is helpful, it seemed like a glorified timer. It would be best to automatically track when I’ve emptied the washer too. That way I only get the text messages when necessary — when I forget to unload. I considered monitoring the existing washing machine lid switch to detect when it was opened and closed but I didn’t have the hardware available to make the connection.
Looking for other options, I observed that this old washer lid makes a surprisingly strong thump when closed. I opted to use the resulting vibration from closing the lid as a cue that the clothes had been removed from the washer. If that thump is detected within 4 hours a of a completed cycle, no notification is necessary as it is assumed it has been emptied; otherwise, I get the following text message.
This project was fun to implement, troubleshoot, and solves a unique personal challenge which is always a bonus. I don’t really have plans to expand this hack as it basically resolves this very specific problem. I am looking forward to finding another excuse, I mean reason, to “fix” something else around the house with a Raspberry Pi.
I’ve been looking for an excuse to make something useful out of my Raspberry Pi. For those unfamiliar, the Raspberry Pi is an inexpensive, small, programmable computer which can interface between just about any “kind” of hardware you can imagine. You can use it to automate your home, create your own robots and much, much more. As a software developer, tinkering with real-world hardware that can be controlled by my own software is a very compelling prospect.
I had high ambitions initially of creating my own robots, magic mirrors, and smart locks. Reality set in that this tech is new to me and I need a low bar for the first experiment. After weeks of tinkering with the basics of electronics, I opted to focus on building something for our two dogs whom I likely won’t disappoint.
Schenley and Luna’s dog food resides in this dresser in our living room. They are fed 3 meals per day on a schedule. My wife and I sometimes lose track of when the last feeding occurred. This leads to the dogs occasionally skipping a meal or getting fed too often.
I wrote a simple software program for the Raspberry Pi that is aware of their ideal feeding schedule — 6am, 12pm and 6pm. This program will signal a small red LED, mounted just below the cabinet drawer, when a feeding is due. A completed feeding is detected by a magnetic sensor, hidden under the dresser drawer, that tracks when the cabinet drawer is opened then closed.
The basic flow is if the LED is on, we fill the bowls with food. The light will then go out until it is time to feed them again. This removes the guess-work out of when they had their last meal or if it is too early for the next feeding.
I have a few ideas for expanding this dog feeding theme. A text messaging service running on the Raspberry Pi could alert us when a feeding is overdue. On the hardware end, I can include a water sensor in their water bowl to monitor when their water is low and send similar alerts.
This Raspberry Pi project was easy enough that I could hack something together using just some basic online tutorials. I recommend exploring this if you are new to hardware or software projects and want to learn more.