Brewometer integration

Confirmed, ran BrewPi with the Photon connected, all is well.

Thanks again for you help.

Stefan

P.S. My Tilt integration is almost working too

Anyone able to help me on this one? Following Simonā€™s (@sibowler) script I get this error message and I cannot access my Tilt in anything but root.

sudo setcap -v cap_net_raw+eip $(eval readlink -f `which python`)
/usr/bin/python2.7 differs in [pie]

TIA
Stefan

Almost there, I am now showing Tilt logging in BrewPi. Need to get the C-F switch set, the SG numbers on the right butI am almost there. @sbowler has been very helpful with getting me here, he has been a real trooper.

Stefan

Hi Raptor,
Thanks for the education. Your solution looks pretty cool.
Could you share more details about your cron job and gattool python script from step 3 please?

Post from December:

Raptor:
sure - I would post my code to github but it is part of a bigger process within my home virtual environment that includes custom monitoring etc based on a sqlite database. I need to spend some time in the new year seeing if I can refactor this into a standard facility as such. Need to think about this as the code base is changing soon via Elco and I am on Arduino.

But in outline:

  1. I created a sqlite database holding a brew/brewlog/brew_device table structure. The brew_device table contains the Tilt address and current battery level reading. This is used for other purposes too - hence the database approach.
  1. I added a new subroutine to the brewpi.py python script that inserts the current tilt SG and temp readings to the new brewlog table every x mins along with the standard brewpi logging data.
  1. I added a new python script that is run via cron twice a day and this runs gatttool to grab the battery status and updates the device table with this.

Much appreciated!

[Edit: not sure why this didnā€™t includeRaptorā€™s earlier post as intended]

Had sbowlerā€™s tilt integration working with the newest firmware, etcā€¦ until I started mucking about with gatttool, then the brewpi/tilt integration stopped graphing.

Restarting the brewpi script didnā€™t seem to unjam it.

Any suggestions?

Hereā€™s the PHP code I ran twice (which returned battery data, etcā€¦) but the brewpi Tilt logging died at that time.

Any idea why the other BLE query would cause the unhandled exception shown in the log?

Further, why it wouldnā€™t recover after restarting the script?

brewpi log:

Jan 12 2017 19:12:36 Notification: Beer temperature set to 75.0 degrees in web interface
Jan 12 2017 19:12:36 Controller debug message: INFO MESSAGE 12: Received new setting: mode = b
Jan 12 2017 19:12:36 Controller debug message: INFO MESSAGE 12: Received new setting: beerSet = 75.0
> Unhandled exception in thread started by >
> Traceback (most recent call last):
> File ā€œ/home/brewpi/TiltHydrometer.pyā€, line 352, in scan
> returnedList = blescan.parse_events(sock, 10)
> File ā€œ/home/brewpi/blescan.pyā€, line 143, in parse_events
> le_handle_connection_complete(pkt)
> NameError: global name ā€˜le_handle_connection_completeā€™ is not defined
Jan 12 2017 20:02:50 stopScript message received on socket. Stopping script and writing dontrunfile to prevent automatic restart
Jan 12 2017 20:03:17 Opening serial port
Jan 12 2017 20:03:17 Notification: Script started for beer ā€˜2017InstallTestDataā€™
Jan 12 2017 20:03:27 Checking software version on controllerā€¦
Jan 12 2017 20:03:27 Found BrewPi v0.4.3 build 0.4.3-0-g4d00879, running on a Particle Photon with a V2 shield on port /dev/ttyACM0

tiltStats.php:

<?php

//Reduce errors
error_reporting(~E_WARNING);

$brewometer = ā€œ88:C2:55:AC:30:0Dā€; // put your brewometer MAC address here

$command1 = ā€œgatttool -b ā€œ.$brewometer.ā€ --char-read -a 0x3bā€; // get SG
$command2 = ā€œgatttool -b ā€œ.$brewometer.ā€ --char-read -a 0x37ā€; // get temp
$command3 = ā€œgatttool -b ā€œ.$brewometer.ā€ --char-read -a 0x48ā€; // get battery

$result = exec ( $command1 );
$resultArray = explode(":", $result);
$result = hexdec(trim($resultArray[1]));
$result = (float)(($result-19) / 1000) + (float)1.000;
$sgStr = sprintf(ā€œSG - %01.3fā€, $result);
$result = exec ( $command2 );
$resultArray = explode(":", $result);
$tempStr = hexdec(trim($resultArray[1]));
$result = exec ( $command3 );
$resultArray = explode(":", $result);
$batStr = hexdec(trim($resultArray[1]));
echo $sgStr."\n".ā€œTemp - ā€œ.$tempStr.ā€ degrees\nā€.$batStr."% remaining\n\n";
?>

@sbowler @Richard_Crump
Same problem with my calibration file.

in stdout.txt, I see one error message upon startup:

ERROR: TiltHydrometer (Black): Unable to initialise Gravity Calibration data (tiltHydrometer/GRAVITY.black) - list index out of range

That GRAVITY.black file has one calibration point from 1.011 -> 1.000 (basically a ā€œtareā€ with water adjustment while testing during a 12-hour soak.)

#Gravity Calibration file for Tilt Hydrometer
#To be active, the file should be named GRAVITY.<colour> in the tiltHydrometer/ folder
#and have at least one calibration value inside.
#So to calibrate a black tilt hydrometer, the file would be called GRAVITY.black
#The following example two calibration points are used. 
#0.997 read from the tilt hydrometer will be calibrated to the actual value of 0.999
#1.056 read from the tilt hydrometer will be calibrated to the actual value of 1.060
#Other calibration points will be calculated.

#Original SG Value, Calibrated Value
#0.997, 0.999
#1.056, 1.060
1.011, 1.000

@SBowler, the author of the Tilt modifications can probably confirm, but to me your GRAVITY file looks wrong. If I am not mistaken, GRAVITY needs two entries, the TEMPERATURE file only needs one.
For the second calibration point, mix some sugar or DME in water and confirm with a glass hydrometer. I would calibrate somewhere in the 1.050 - 1.060 range.

Stefan

@frizzo simply remove the blank line so your file looks like this. It the problem was the same as mine, itā€™ll work.

@sbowler told me the code canā€™t handle the blank line

#Gravity Calibration file for Tilt Hydrometer
#To be active, the file should be named GRAVITY.<colour> in the tiltHydrometer/ folder
#and have at least one calibration value inside.
#So to calibrate a black tilt hydrometer, the file would be called GRAVITY.black
#The following example two calibration points are used. 
#0.997 read from the tilt hydrometer will be calibrated to the actual value of 0.999
#1.056 read from the tilt hydrometer will be calibrated to the actual value of 1.060
#Other calibration points will be calculated.
#Original SG Value, Calibrated Value
#0.997, 0.999
#1.056, 1.060
1.011, 1.000

@Richard_Crump @sbowler
understood. got it tweaked and working now. Much obliged.
Added an issue in github for the project to track this.

seems like an easy fix to the sample file to clear this upā€¦

  1. add another instruction/warning in the comments
  2. replace blank lines with empty comment lines
  3. explicitly add an #EOF comment at end to avoid trailing empty lines

GRAVITY.colour:

#Gravity Calibration file for Tilt Hydrometer
#To be active, the file should be named GRAVITY.<colour> in the tiltHydrometer/ folder
#and have at least one calibration value inside.
#File must not have any blank lines.
#To calibrate a black tilt hydrometer, the file would be called GRAVITY.black
#The following example two calibration points are used. 
#0.997 read from the tilt hydrometer will be calibrated to the actual value of 0.999
#1.056 read from the tilt hydrometer will be calibrated to the actual value of 1.060
#Other calibration points will be calculated.
#
#Original SG Value, Calibrated Value
0.997, 0.999
1.056, 1.060
#EOF

Iā€™ve been struggling with this issue all day. When I try to run the test python script and I keep getting ā€œImportError: No module named scipy.interpolateā€. Anyone have any ideas?

Hi @jasonumd,

Did you run the full apt-get command from the readme?

sudo apt-get install bluez python-bluez python-scipy python-numpy libcap2-bin

That should fix the scipy error

1 Like

Thanks for the reply @sbowler! I have tried that many times. I keep getting this error:

Err http://mirrordirector.raspbian.org/raspbian/ jessie/main python-imaging all 2.6.1-2+deb8u2
404 Not Found [IP: 5.153.225.207 80]
E: Failed to fetch http://mirrordirector.raspbian.org/raspbian/pool/main/p/pillow/python-imaging_2.6.1-2+deb8u2_all.deb 404 Not Found [IP: 5.153.225.207 80]

E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

Disregard! I think I fixed it. The command was referencing u2 and the online directory has u3. Manually downloaded and installed the suspect package.

First of all, many thanks to @sbowler for the work on the TiltHydrometer itegration!

After setting up Tilt integration, which seemed to go without error, I see all possible Tilt colors on the graph ā€œbeer panelā€ and additionally the point-in-time data values do not show up on the ā€œbeer panelā€. The line graph seems to show the data points for the Red Tilt SG, but not for Red Tilt Temp.

Hardware versions:
Raspberry Pi 3 Model B V1.2
BrewPi Spark Photon

Software versions:
Raspbian GNU/Linux 8.0 (jessie)
BrewPi v0.4.4 build 0.4.4-0-g6d17ff1, running on a Particle Photon with a V2 shield
Brewpi-Brewometer commit f37870b

Before setting up the Tilt, I ran the updater script on Brewpi, which updated everything to the latest version (those shown above). Following the Tilt integration instructions from github, all the steps seemed to go smoothly. I saw no errors and the TiltHydrometerTest successfully read data from the Tilt. I am now running the BrewPi in FridgeConstant mode and see the following issues on the graph:

  1. The ā€œbeer panelā€ on the BrewPi graph shows a reference key for every possible color of TiltHydrometer.
  1. When hovering the mouse over the graph, the ā€œbeer panelā€ does not show point in time data values for the red Tilt (the regular brewpi categories [FridgeTemp, FridgeSetting, RoomTemp, ā€¦] do show individual values). Both the json and csv data files have data values for ā€œRed Tilt temp.ā€ and ā€œRed Tilt Gravityā€.
  1. The line graph appears to show the data for the Red Tilt SG but not for the Red Tilt Temp. The tilt is sitting in a pitcher of water outside the fermentation chamber, so I expect the Red Tilt Temp to be similar to the Room Temp and Red Tilt SG to be close to 1. The data in the json file matches expectations but there is no corresponding line on the graph for Red Tilt Temp.

Thoughts?

I just realized the data for Red Tilt Temp are actually shown in the graph, but in green instead of the expected color of red.

I also just found this post from @sbowler about why extra Tilt colors are displayed. Iā€™ll double-check the files listed in that post.

I walked through all the setup steps again and havenā€™t found anything wrong, broken or out of the ordinary. I even considered trying a previous release but it looks like changes on 16Dec2016 were made specifically for brewpi-v0.4.4 (and Iā€™m not going to downgrade my brewpi code). So at this point, guess Iā€™ll go have a homebrew and patiently wait and hope for other comments or suggestions.

@andylytical
FWIWā€¦
for #1, Not seeing what you areā€¦ only my [black] tilt shows up on the graphs, not all of them

For #2, no ideaā€¦ guessing your tilt code is out of date or incorrectly installed

For #3, Also, are you sure youā€™ve pulled the latest tiltHydrometer code?
check your tiltHydrometer.css file:

.beer-chart-legend-row .toggle.redTemp{
background-color:rgba(255, 0, 0, 0.5);
border:1px solid rgba(255, 0, 0, 1);
}

.beer-chart-legend-row .toggle.redSG{
background-color:rgba(255, 0, 0, 0.5);
border:1px solid rgba(255, 0, 0, 1);
}

Latest is working just fine here.

So jealous, got mine to look like this for a very short time. Now it is back to a mixed up view. Going to try a total rebuild from NOOBS.

Thanks for the response. I trust git clone to have gotten me the latest code. I re-read, slowly, this entire forum thread and spent (probably too much) time examining the js and php code. In light of all the success stories, I decided itā€™s time to start from scratch. Tonight I plan to wipe the SD card and do a complete re-install of everything (OS, brewpi, tilt). I hope Iā€™ll be posting back with a success story.

Well, Iā€™m completely stumped. I rebuilt completely from scratch, starting from the latest (2017-01-11) Raspbian Jessie Lite image. Still no luck, I have the exact same behavior as before. Iā€™ve included an image of my graph; note that tilt temp and tilt SG are being collected and graphed (the red line at 1.0 is the SG from the tilt in water and the green line at 8C is the tilt temperature). I have only one tilt, color=red.

The exact rebuild procedure I followed is at: https://github.com/andylytical/brewpi-scripts. Hopefully these scripts will be useful to others ā€¦ once the issue here is figured out.

@frizzo, just curious, what hardware and software versions are you running?
@NottingHill, also curious, same question.

@andylytical
rpi2 model b, 2017-01-11-raspbian-jessie-lite.img (reloaded scratch last weekend actually)

My notes FWIWā€¦ Sorry about not quoting things wellā€¦ sending via mobile & rushing through this for ya.

ssh pi@IP
passwd
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install rpi-update
sudo rpi-update
sudo apt-get install git
sudo reboot

# configure locale, tz, kbd, ssh
sudo raspi-config 
set locale
set timezone
set keyboard
enable ssh
exit the tool
edit /etc/ssh/sshd_conf
confirm: TCPKeepAlive yes
Add entries as follows
ClientAliveInterval 30
ClientAliveCountMax 99999

try:
sudo service ssh restart
otherwise:
sudo reboot

    # Static IP setup:
    ssh into your RaspPi:
    sudo ssh pi@YOUR.RASP.Pi.IP
    sudo cd /etc/
    sudo nano /etc/dhcpcd.conf

# Custom static IP address for wlan0.
interface wlan0
static ip_address=192.168.4.241/24
static routers=192.168.4.1
static domain_name_servers=192.168.4.1 
# setup wifi
sudo iwlist wlan0 scan
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
network={
    ssid="Your_ESSID"
    psk="Your_wifi_password"
}
sudo ifdown wlan0
sudo ifup wlan0
ifconfig wlan0


git clone https://github.com/BrewPi/brewpi-tools.git ~/brewpi-tools
sudo ~/brewpi-tools/install.sh

brewpi web files location:  /var/www/html/brewpi  (NOT DEFAULT OF /var/www/html)

#
# Update process for latest tools and firmware
#
ssh -l pi brewpi.local
sudo python brewpi-tools/updater.py
sudo ~brewpi/utils/runAfterUpdate.sh (updater does this, redid this to confirm)


pi@brewpi:~ $ sudo vi /etc/apache2/apache2.conf
#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
#KeepAliveTimeout 5
KeepAliveTimeout 99

pi@brewpi:~ $ sudo service apache2 restart

then I installed the Tilt Hydrometer mods.

cd /home/brewpi
sudo git clone https://github.com/sibowler/brewpi-brewometer.git
sudo apt-get install bluetooth bluez python-bluez python-scipy python-numpy libcap2-bin
sudo setcap cap_net_raw+eip $(eval readlink -f `which python`)
python /home/brewpi/brewpi-brewometer/tiltHydrometer-test/TiltHydrometerTest.py

cd brewpi-brewometer/brewpi-web/
sudo cp -r * /var/www/html/brewpi/
sudo chown -R www-data:www-data /var/www/html/brewpi/
cd /home/brewpi/brewpi-brewometer/brewpi-script/
sudo cp -r * /home/brewpi/
sudo chown -R brewpi:brewpi /home/brewpi
sudo shutdown -r

after verifying this is working, I also did the public/admin webpage mods, installed LetsEncrypt SSL and generated a cert for the public site. LE was a pain on raspbianā€¦ lots of conflicting instructions online.
This one workedā€¦ https://lordofthemoon.com/blog/2016/08/lets-encrypt-for-the-raspberry-pi-model-b/

1 Like

After fighting with this thing. I found there is a fork for us legacy users thats closer to being current to SBowlers master. https://github.com/supercow/brewpi-brewometer
Thinking this would help me I cloned it. I still canā€™t get the tilt to convert from C to F. And now it seems there are 3 settings.ini files to modify. This is not any easier. :frowning:
So rather than fight with this function I really donā€™t need anyway. How can I just remove the temperature function from the tilt modification?

I did exactly this and still have an issue with brewpi not being able to use this data.
ERROR: Brewometer (Black): Unable to initialise Temperature Calibration data (brewometer/TEMPERATURE.black) - list index out of range
ERROR: Brewometer (Black): Unable to initialise Gravity Calibration data (brewometer/GRAVITY.black) - list index out of range
ERROR: Brewometer (Purple): Unable to initialise Temperature Calibration data (brewometer/TEMPERATURE.purple) - list index out of range
ERROR: Brewometer (Purple): Unable to initialise Gravity Calibration data (brewometer/GRAVITY.purple) - list index out of range