Software apps and online services
I just moved into a three story house with 6 people and 1 toilet. Running down stairs every morning to find the bathroom occupied became a common annoyance for everyone in the house. So I made this monitoring system so we can check if anyone is in the bathroom from the comfort of our rooms.
The project is pretty simple. It uses a magnetic reed switch to check if the door is open or closed. On a change event it updates the data on firebase and the data on firebase is then synced with the frontend. If there is anyone in the cue when the door is opened it'll send them a text from twilio notifying them that the toilet is now available.
The device side code is written in python. The front-end is powered by firebase's angular-fire which allows the data on the front-end to be updated without a page refresh or an ajax method, which is awesome.
I've detailed the steps below so you can knock up your own occupied app if you are facing a similar issue.
Step one: Sign up for third party apps
Resin.io, is a update platform that uses docker and git to allow you to update code on your Pi over the air. It also makes the initial set up a breeze.
2.Sign up with firebase, create an app. And create a simple data store layout like this.
Then signup with Twilio, and verify all your housemates or colleagues phone numbers. (If you have a paid account you won't have to verify the numbers).
Step 2: Add environment variables to resin app
Add all API keys and housemates phone numbers as environment variables on the resin app page. Adding them as envars, keeps 'em out of your code base making it safer and easier to update on the fly.
Step 4: Connect your Pi to the reed switch and then to resin.io
Solder the reed switch to some female connectors and connect them to the appropriate pins.
Once it's connected, attach it to the door. Then power up your pi and make sure you it is connected to the internet (The green light will cycle 4 slow flashes if it cannot connect).
Step 5: Clone and push code to device
The code is pretty simple, there is a loop that reads the input from gpio connected to the reed switch. If that input state changes it updates firebase with the new state and sends a text if there is anyone in the queue.
After cloning, cd in to the directory and add your resin app's endpoint as a remote repo.
Then run git push resin master
On your resin dashboard navigate to your device. View the logs tab, you should see a print loop of the prev_state and the input_state. When these to values are different, it'll update firebase which will then update the front-end.
Step 6: Set up the front-end
Pretty simple. Clone the front-end source.
There are two things you'll need to change.
1. In fun.js navigate to line 2 and change the FbURL var to your firebase app's url.
2. Change the names to your housemates names (match the case you used when setting up the resin envars).
Then simply deploy your firebase frontend as instructed here.
It's really cool building something that actually get's used on a daily basis, even if it something as silly as a toilet checker. And it's now really easy to do with services like firebase and resin.io. Hope this gets your excited to build some real world apps! It's a really exciting time to be alive. Here is my demo.
Add a humidity sensor to see if the shower is in use.