ABOUT THIS PROJECT
Sitting in a bigggggg house and you wanna use a toilet.
What if all washrooms are already occupied ?
What if you do’t know which one to go ?
Then what would you do, go and search each toilet to check its availability? LOL
So here comes a toilet queueing app for serious poopers. Uses resin.io, firebase and twilio to notify people when the toilet is open – runs on the RPI.
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.
- Raspberry PI B+
- A Magnetic Reed Switch
- Ethernet cable or Wifi Dongle.
Let’s Start Building
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.
- Sign up with resin.io. Create an app, download the image and make sure the device is online on your resin dashboard. You can find more detailed instructions here.
2.Sign up with firebase, create an app. And create a simple data store layout like this.
3.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.
fbRef = os.getenv(‘FIREBASE’)
twilio_acc_id = os.getenv(‘TWILIO_ACC_ID’)
twilio_acc_auth_token = os.getenv(‘TWILIO_ACC_AUTH_TOKEN’)
twilio_number = os.getenv(‘TWILIO_NUMBER’)
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.