Keg Volume Kalculator Mod: How to install
Difficulty level: Medium (requires command line and SFTP).
Assumptions/dependencies: Assumes that you have official RPints 2.0.1 installed on a PHP5 environment (Wheezy/Jessie), forked versions of RPints are not currently supported.
Warning: Before proceeding any further take a fresh
disaster recovery backup of your Pi, I will attempt to assist anyone that gets stuck along the way, but sometimes things can go wrong and you'll need a rollback strategy in place.
Step 1: Altering the config and kegs database tables
Warning: Here be dragons!
I decided to add a few new rows to the config table to store our brewery default settings, so that you don't need to populate these every time you tap a keg, and also created a new column in the kegs table to store individual keg maximum volume as generic values based on keg type is not granular enough in a real world environment (eg one of your kegs may have a big dent in the side of it so it holds less than it used to).
So SSH into your Pi and then run the following command:
Enter your RPints password then copy the entire following and paste in into the terminal:
Code:
use raspberrypints;
INSERT INTO config ( configName, configValue, displayName, showOnPanel, createdDate, modifiedDate ) VALUES
( 'altitude', '0', 'Altitude', '0', NOW(), NOW() ),
( 'temperature', '0', 'Temperature', '0', NOW(), NOW() ),
( 'pressure', '0', 'Pressure', '0', NOW(), NOW() );
ALTER TABLE kegs
ADD COLUMN maxVolume decimal(6,3) NOT NULL AFTER weight;
UPDATE kegs SET maxVolume = '5' WHERE kegTypeId = '1';
UPDATE kegs SET maxVolume = '2.5' WHERE kegTypeId = '2';
UPDATE kegs SET maxVolume = '3' WHERE kegTypeId = '3';
UPDATE kegs SET maxVolume = '10' WHERE kegTypeId = '4';
UPDATE kegs SET maxVolume = '5' WHERE kegTypeId = '5';
UPDATE kegs SET maxVolume = '5.16' WHERE kegTypeId = '6';
UPDATE kegs SET maxVolume = '7.75' WHERE kegTypeId = '7';
UPDATE kegs SET maxVolume = '7.75' WHERE kegTypeId = '8';
UPDATE kegs SET maxVolume = '15.5' WHERE kegTypeId = '9';
UPDATE kegs SET maxVolume = '13.2' WHERE kegTypeId = '10';
UPDATE kegs SET maxVolume = '10.81' WHERE kegTypeId = '11';
UPDATE kegs SET maxVolume = '10.81' WHERE kegTypeId = '12';
UPDATE kegs SET maxVolume = '21.62' WHERE kegTypeId = '13';
UPDATE kegs SET maxVolume = '43.23' WHERE kegTypeId = '14';
UPDATE kegs SET maxVolume = '64.85' WHERE kegTypeId = '15';
Quit;
This will not only create the rows/column but also set the default max volume for your existing kegs so you don't have to update them all manually.
Step 2: Copying the new files across to your Pi
Warning: Here be dragons!
I've attempted to maintain the same file structure that the original developers used in case they one day return and decide to incorporate this into the official version, so due to the fact that many files needed to be edited, I've put them all together in a zip file for you here:
RPintsKegVolCalc.zip (MD5 checksum: 3231513238b679284fcdfeae353e8f3f).
The contents of that zip are as follows:
Code:
├── admin
│ ├── includes
│ │ ├── managers
│ │ │ └── keg_manager.php
│ │ └── models
│ │ └── keg.php
│ ├── keg_form.php
│ ├── keg_list.php
│ ├── left_bar.php
│ ├── personalize.php
│ ├── tap_form.php
│ ├── update_altitude.php *
│ ├── update_pressure.php *
│ └── update_temperature.php *
└── includes
└── config_names.php
(the files with an asterisk next to them are newly created files that previously didn't exist)
Before copying these files across it's a good idea to diff your existing files against original RPints files to ensure any changes you've made to them are not lost (using WinDiff on Windows or DiffMerge on Mac for example). Here's a zip with just the unedited versions of the original files in it for you to use:
RPintsRevert.zip
(MD5 checksum: 852eb0280408903060a4144b19212a79).
Here's an example of changes on my tap_form.php file that I'll need to redo in order to get my metric back on again:
Once you've done the SFTP transfer, make sure you've got the right permissions with the following command:
Code:
sudo chmod -R 777 /var/www
Step 3: Editing your index.php file
No dragons here!
As index.php is the first file we all hack, I figured it would be easier to just provide the one line of code that needs updating rather than including the file then everyone having to hack all their changes back into in.
Find the following line:
PHP:
$sql = "SELECT `kegTypes`.`maxAmount` as kVolume FROM `kegs`,`kegTypes` where kegs.kegTypeId = kegTypes.id and kegs.id =".$kegID[0]."";
Change it to:
PHP:
$sql = "SELECT `kegs`.`maxVolume` as kVolume FROM `kegs` where kegs.id =".$kegID[0]."";
Then do a reboot just to be sure:
This makes sure that the percentage indicator on the keg is using our new max volume instead of the generic max amount value.
That's it, stay tuned for our next episode where I explain how to use it ;-)
Cheers,
Kal