Skip to content

Part 4. The Final Script

jrbail01 edited this page Jul 16, 2015 · 4 revisions

Assuming you ran the "git clone https://github.com/InitialState/beerfridge.git beerfridge" command in Part 2, the final script that puts everything together is called beerfridge.py in your ~/beerfridge directory. (https://github.com/InitialState/beerfridge/blob/master/beerfridge.py)

A few settings need to be set in the script before you can run it. Open up beerfridge.py in your favorite text editor such as nano.

$ cd ~
$ cd beerfridge
$ nano beerfridge.py

Near the top of this file, there is a User Settings section.

# --------- User Settings ---------
WEIGHT_SAMPLES = 1500
WEIGHT_BASE = 83.04
WEIGHT_BOTTLE = 1.266
FRIDGE_GETTING_LOW = 32
FRIDGE_EMPTY = 22
TEMPERATURE_DELAY = 60
TEMPERATURE_TOO_HIGH_F = 50
TEMPERATURE_TOO_LOW_F = 27
BUCKET_NAME = "Beer Fridge"
BUCKET_KEY = "INSERT_BUCKET_KEY_HERE"
ACCESS_KEY = "INSERT_ACCESS_KEY_HERE"
# ---------------------------------
  • WEIGHT_SAMPLES sets how many weight measurements the Wii Balance Board takes and averages before computing how many bottles are present. 1500 seemed to provide a nice balance of accuracy while not taking too long to complete. Feel free to tweak this setting to your liking.
  • WEIGHT_BASE specifies the weight of your empty refrigerator in pounds. Use the value that you wrote down in the Part 2: Final Destination section.
  • WEIGHT_BOTTLE specifies the average weight of a bottle in pounds. Use the value that you wrote down in the Part 2: Final Destination section.
  • FRIDGE_GETTING_LOW specifies the number of bottles present that is deemed to be few enough that a warning status should be displayed.
  • FRIDGE_EMPTY specifies the number of bottles present that is deemed to be few enough that a severe warning status should be displayed.
  • TEMPERATURE_DELAY specifies the delay in seconds between temperature measurements. If you stream a temperature measurement every 60 seconds, this will be ~44,000 data points per month.
  • TEMPERATURE_TOO_HIGH_F specifies the temperature (in Fahrenheit) that is high enough that a warning status should be displayed.
  • TEMPERATURE_TOO_LOW_F specifies the temperature (in Fahrenheit) that is low enough that a warning status should be displayed.
  • BUCKET_NAME specifies the name of the data bucket that will show up in your Initial State account.
  • BUCKET_KEY should be set to a unique name. The BUCKET_KEY parameter allows you to append to an existing bucket or create a new bucket. Simply pick a name for this parameter (i.e. beerfridge1234).
  • ACCESS_KEY is your Initial State account key that you used in the Part 4: Initial State section.

Once you have specified each parameter in this section and saved your changes, you are ready to run the final script. Before we run the script, let's go through what it is going to do.

  • At the start of the script, you will be asked to pair your Wii Balance Board with your Raspberry Pi. Use the lever that you hacked together in section Part 2: Hardware Tweaks to press the sync button when prompted.
  • Once the script is running, the number of bottles present in your refrigerator will be calculated only when the door closes. This value will be streamed to your Initial State account when it changes.
  • Every time a bottle is removed from your refrigerator, a bottle removed event will be streamed to your Initial State account.
  • Every time the door opens or closes, a door status event will be streamed to your Initial State account.
  • The temperature inside your refrigerator will be streamed to your Initial State account at the interval specified by TEMPERATURE_DELAY.

Run the script to start the magic.

$ sudo python beerfridge.py

<< Part 4: Initial State - Part 4: Your Personal Dashboard >>