ENGAGED/NON-ENGAGED

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.

HARDWARE NEEDED

  1. Raspberry PI B+
  2. A Magnetic Reed Switch
  3. Ethernet cable or Wifi Dongle.

SOFTWARE NEEDED

  1. Resin.io

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.

  1. 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.

import os

# CONFIG
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.

Connect to pin 1 and 6, which match to 3,3v and GPIO 17 respectively.

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).

The reed switches are about 5 cm apart when the doors closed, but it maybe better to initially set them with temporary adhesive as you may have to move them slightly if it’s not reading the door close/opens accurately.

Step 5: Clone and push code to device

Clone my occupied-device repo. It’s a couple a couple python files and docker file which tells  resin.io how to build the image and what packages to include.

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.

You can find your app’s repository url on the apps page in the top right corner.
Untitled file
$ git remote add resin git@git.resin.io:USERNAME/YOUR-APP.git

Then run git push resin master

Untitled file
git push resin master
You’ll get a cool success message after the image has uploaded.
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.

Conclusion

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.

Uses firebase’s angularfire, so you don’t have to refresh the page to see the new state which is pretty sweet.
If it’s occupied you have the option of joining the queue, it’ll give you a random article to read and text you when the toilet is open again.
Screen_Shot_2015-02-17_at_9.43.37_AM

Todo:

Add a humidity sensor to see if the shower is in use.

Add analytics.

CODES

Py code

Untitled resin

Untitled 2

LEAVE YOUR COMMENTS BELOW.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s