Brewometer integration


#166

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


#167

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


#168

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


#169

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.

  2. 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.

  3. 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]


#170

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";
?>


#171

@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

#172

@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


#173

@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

#174

@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

#175

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?


#176

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


#177

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?


#178

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


#179

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.

  2. 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".

  3. 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.


#181

@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.


#182

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.


#183

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.


#184

@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/


#185

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?


#186

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