Skip to content

Reads from Tilt Hydrometer and writes results to a database

License

Notifications You must be signed in to change notification settings

mjlocat/tilt2db

Repository files navigation

tilt2db

Reads from Tilt Hydrometer and writes results to a database

Why?

The Android app for the Tilt Hydrometer requires a device is always on and in BLE range to read the data and forward it on to a service or a logger. I already have a Raspberry Pi near my fermentation fridge and wanted to leverage that to get the data and move it along. There is the TiltPi, but I'm not a huge fan of Node Red and found it to lose the connection every so often requiring the service to be restarted. Building on the aioblescan library modifications from baronbrew, it didn't look too hard to read the data and push them to a database. My ultimate goal is to pair this with tilt2bf to publish the data to Brewer's Friend to track the fermentation process.

Prerequisites

  • Tilt Hydrometer
  • Linux machine with BLE capabilities (Raspberry Pi 3B or 4 work nicely)
  • Python3
  • A MySQL or MariaDB database

Installation

  1. Install the aioblescan package, but not the one from pip (TODO: eventually update this code to use aioblescan from pip)

    wget https://github.com/baronbrew/aioblescan/archive/master.zip
    unzip master.zip
    cd aioblescan-master/
    sudo -H python3 setup.py install
  2. Clone the repository

    git clone https://github.com/mjlocat/tilt2db.git && cd tilt2db

  3. Install the python libraries

    pip3 install -r requirements.txt

  4. Set up the database

    CREATE DATABASE tilt;
    CREATE USER tilt IDENTIFIED BY 'mypassword';
    GRANT ALL PRIVILEGES ON tilt.* TO tilt@'%';
    # If using a database on the same machine
    mysql -u tilt -p tilt < create_table.sql
    
    # if using a database on another machine
    mysql -h dbhostname -u tilt -p tilt < create_table.sql
  5. Copy config.yaml.sample to config.yaml and update the database credentials and calibration settings (see Calibration)

Usage

Invoke using python3 tilt2db.py (If python is version 3, you can use that)

usage: tilt2db.py [-h] [-c CONFIG] (-s | -t TIME)

optional arguments:
  -h, --help            show this help message and exit
  -c CONFIG, --config CONFIG
                        Location of the configuration file
  -s, --single          Get one reading then exit
  -t TIME, --time TIME  Minimum time between stored readings in seconds
Command Options Description
-c CONFIG, --config CONFIG Specify the location of the config.yaml file
-s, --single Get one reading, then exit, useful if running in a cronjob. Either this option or -t must be specified
-t TIME, --time TIME Wait TIME seconds between readings. Either this option or -s must be specified

Calibration

Fill a large bowl with water and place the Tilt Hydrometer in it. Take the temperature of the water. The temperature reading shown should match the temperature of the water and the Specific Gravity reading should be 1.000. Adjust the temp_correction or sg_correction values in config.yaml to offset the values. For example:

temp_correction: 1 # Add one degree to the reading
sg_correction: -0.003 # Subtract 3 thousandths from the reading

NOTE: In this early stage, I'm assuming the offsets are linear. The Fermentrack documentation leads me to believe it may be non-linear.

About

Reads from Tilt Hydrometer and writes results to a database

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages