Brewometer integration

thanks @Richard_Crump

So another step in “Teach Yourself Linux”. I used the -v parameter on the setcap command, and got “OK”. So that is working.
Who of the erudite forum members can now help me determine why I can see the Tilt in the ‘lescan’ but not in Simon’s test script?

Stefan

Put my Tilt in a recent brew, so I can track the fermentation using my wife’s iPhone (my own Android is too old and does not have BLE). But it would be great if I can get the BrewPi integration working. Still hoping that someone in the forum can come up with some good ideas for me to try. :disappointed:

I think that I have to give up (or rebuild all of my BrewPi). I thought that, in spite of not connecting to the Tilt, what harm would it do to load @sbowler’s version it will not show anything until I get the Tilt connection working. But it cannot do any harm…

So I will have to restore my back up to use for now. And then maybe I will do a total rebuild :frowning:

Heh, that error is not very helpful.
The server returned ‘Could not connect to script’ or something similar, but when you try to parse that as JSON, you’ll get ‘Unexpected token C’.

Look in the log file to see why your script doesn’t run.

Probably because I was running without my controller connected.

Unfortunately, when I run connected to the controller I do not have a local HDMI screen. Also, for some strange reason the WiFi network does not seem to connect so I cannot use Putty to view either, So I might have to take a screen off my monitor stand, take it to the basement as see exactly what is going on.

Thanks for the quick reply and the support. I WILL get this working

Stefan

Hi All,

Apologies for the lack of participation over the last week, have been away with family in the country with minimal access to internet. I’ve only just arrived back so will try and read through and reply later today for any issues that haven’t been resolved (including your PM, @NottingHill).

Cheers,

Simon

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.