Python software that is aimed to run on a Raspberry Pi to access Tilt Data and store it in Firebase Database.
- Raspberry Pi with Bluetooth LE support - tested on B3 but Zero W should be ok.
- Tilt Hydrometer.
- Install latest raspian.
- Install following components:
sudo apt-get install python-dev
sudo apt-get install libbluetooth-dev
sudo pip3 install pybluez
sudo pip3 install pyrebase
-
Grab blescan.py, tiltblescan.py and firebasesend.py using wget or similar software.
-
Configure Firebase
- Create a project.
- Import initial database structure:
{ "batch" : 1, "calibration" : { "sg" : 0.006, "temperature" : 0 }, "measurements" : [] }
- From service accounts create key in json format and put it in same directory as
.py
files. - Update configuration section in
firebasesend.py
file:
config = { "apiKey": "apiKey", "authDomain": "projectId.firebaseapp.com", "databaseURL": "https://databaseName.firebaseio.com", "storageBucket": "projectId.appspot.com", "serviceAccount": "path/to/serviceAccountCredentials.json" }
Where:
apiKey
andprojectId
can be found in Firebase project settings.databaseURL
can be found inDatabase
section in Firebase console.serviceAccountCredentials.json
is previously generated key in json format. Keep in mind to provide full path here in order to run this script periodically by cron.
If everything was configured properly run:
sudo python3 tiltblescan.py
Output should be similar to:
temp correction: 0 sg correction: 0.006 batch: 1
temp F: 84 sg uncal: 1036
temp C: 28.89 sg: 1.042 plato: 10.48
Before putting Tilt into fermenter remember to calibrate, then to sanitize it and set appropriate batch number in your Firebase DB.
Collecting data from tilt hydrometer and saving it in Firebase can be automated using cron
.
Eg. To run script for every five minutes edit crontab file by calling crontab -e
and add following line"
*/5 * * * * sudo /usr/bin/python /home/pi/firebasesend.py
In order to get best measurements tilt hydrometer needs to be calibrated before putting it into fermenter.
Put tilt hydrometer in water and read SG using provided mobile application.
If SG differs from 1.000 then put appropriate value in calibration > sg
section in your Firebase DB.
Eg. For 0.996
put 0.004
as offset that would be added to measurement.
After about 10 minutes in water you can calibrate temperature. Use electronic thermometer and similarly put offset value in calibration > temperature
.
This script stores each measurement on a path in Firebase: measurements/1/1492706249
.
In above case 1
is a batch number and 1492706249
is an unix timestamp in GMT.
Every measurement has two values - plato degrees and temperature in celesius:
"1492706249" : {
"plato" : "10.48",
"temp" : "28.89"
}
IMPORTANT! Remember to update batch number before each fermentation process. Failing to do so will result in data inconsistency in your database.
Bluetooth scanning and parsing data from tilt is based on code from: https://github.com/jimmayhugh/TiltRPi
Thanks to https://github.com/mjarco for porting ble scanner to python3