Web-Accessible Temperature Logger for Raspberry Pi

HomeBrewTalk.com - Beer, Wine, Mead, & Cider Brewing Discussion Community.

Help Support Homebrew Talk:

day_trippr

Covid-19 Vaccine Effectivity Test Subject
Joined
May 31, 2011
Messages
35,832
Reaction score
18,201
Location
Stow, MA
When Thadius and company came out with their RaspberryPints project I immediately grabbed up all the recommended parts, put my system together and got my taplist displayed above my keezer and accessible via my intranet or even the internet.

But what I have really been wanting for some time was a networked temperature logger that could drive a web page without needing to use an external service to access the information. There really isn't anything out there that does this well - if at all - aside from "home brewed" solutions.

Which brings me to this little project.

By implementing the RaspberryPints kit I had nearly everything I needed to cobble together a solution for remotely monitoring system temperatures in my little brewery. Starting with my keezer and adding a pair of DS18B20 "One Wire" digital temperature probes I can now monitor my keezer air temperature and the temperature of the "fullest" keg therein as measured by a probe in contact with the middle of the keg exterior, insulated with a 1" thick piece of closed cell foam roughly 4" on a side. I intend to add at least two more probes which will monitor my fermentation fridge and my cold conditioning/carbonation fridge.

I linked the temperature log page to my RaspberryPints taplist via the hotspot temperature icon at the top-right corner for easy access. The interactive graph is generated by a Google service using Javascript, then the page is served by my 'Pi. The user can display a plot of temperatures over the last hour, 6 hours, 12 hours, 24 hours, and a full week.

With that intro out of the way...I've put together an archive file with the files needed to implement one and two channel temperature loggers, along with instructions and a few images for orientation when wiring the sensors to the 'Pi. I pretty much assume the user has the 'Pi for RaspberryPints service and is looking to expand its utility - hence certain prerequisite packages are also assumed to have been installed (eg: Raspbian OS with LXDE, Apache2, Chromium browser) and aren't dealt with at length.

I think the procedure is solid - I actually walked through the installation twice and let the results run for over a day (and still have both versions running) - but then again, that was on my 'Pi - which I've been thrashing pretty thoroughly - so there's always the possibly there's an undocumented step that will have to be exposed on a "virgin" 'Pi.

The archive file is located on my Google Drive share here. It contains:

2x13_header.jpg RPi' GPIO header diagram
ds18b20.jpg picture of a typical wired DS18B20 probe with wire colors
GPIO_header.jpg Another diagram of the RPi' GPIO header
monitor_1sensor.py logging script for 1 probe system
monitor_2sensors.py logging script for 2 probe system
pint.ico RaspberryPints icon for shortcuts
temp_logger_instructions.txt
test_sensors.py detect and test script for up to five probes
thermometer.png icon image for RaspberryPints integration
thermometer4k.png icon image for RaspberryPints integration HD
webgui1.py web page driver script for one sensor system
webgui2.py web page driver script for two sensor system

The rest is covered in the instructions which follow. The first user will receive mega golf claps for any debugging feedback received ;)

Cheers!

==========================================================
RaspberryPi Web Accessible Temperature Logger

This kit will install support to read one or two DS18B20 "OneWire" temperature sensors, log the reading(s) to a database with a timestamp, and fetch entries from that database to drive a web page with a temperature chart and statistics.

Assumptions:
- Raspbian (Debian "Wheezy") OS, Apache2 web server, Chromium or compatible web browser already installed.
- user (default = pi) with superuser access

Components needed:
- one or two wired DS18B20 sensors
- 4.7K ohm axial lead resistor, preferably 1/8W
- hookup wires

Overview: Connect sensors, unpack archive files and move to require folders, set ownership & permissions for files, enable OneWire GPIO support, test the sensor(s), install SQLITE3, create the database, move database to require folder, set ownership & permission for database, create a CRON job to run the sensor polling code, and test the result.


1. Shut down, remove power, video cable, network cable, SD card, USB devices, etc, and open case (if used).

2. Wire up DS18B20 sensor(s):

Sensor red wire(s) to +3.3V (GPIO header pin 1 or 17)
Sensor black wire(s) to GND (GPIO header pin 6,9,14,20 or 25)
Sensor yellow (or white) wire(s) to GPIO4 (GPIO header pin 7)
Add a 4.7K ohm 1/8w resistor across GPIO header pins 1 and 7 (ie: between red and yellow/white wires).


3. Reconnect all cables and devices. Power up, then download and unpack the archive into /home/pi, then:

Move files to /usr/lib/cgi-bin : monitor_1sensor.py, monitor_2sensors.py, pint.ico, webgui1.py, webgui2.py (SEE NOTE)
Move files to /var/www/img: thermometer.png, thermometer4k.png
Leave files in /home/pi : test_sensors.py, 2x13_header.jpg, ds18b20.jpg, GPIO_header.jpg, temp_logger.txt

NOTE: You only need the files for the number of sensors installed. You can delete the extras.


4. Change ownership and permissions on monitor scripts:

$ sudo chown www-data:www-data /usr/lib/cgi-bin/monitor_1sensor.py (or monitor_2sensors.py)
$ sudo chmod +x /usr/lib/cgi-bin/monitor_1sensor.py (or monitor_2sensors.py)


5. Change ownership and permissions on web server scripts:

$ sudo chown www-data:www-data /usr/lib/cgi-bin/webgui1.py (or webgui2.py)
$ sudo chmod +x /usr/lib/cgi-bin/webgui1.py (or webgui2.py)


6. Enable w1 bus support: Edit file /etc/modules

$ sudo nano /etc/modules
w1-gpio <- add this line
w1-therm <- and this line

^o to save the file
^x to exit nano


7. Reboot the RPi


8. Test temperature sensors: (do this in /home/pi)

$ python test_sensors.py

Up to five sensors can be detected and interrogated by this program.
If no sensors are found, shut down and check wiring.
If sensors are detected, they will be listed in order of their device addresses (each device has a unique hard-coded address).
The logging program will always use the sensors in numeric order (first = channel 0, second = channel 1).
If using multiple sensors, use this program to determine which is which by observing which sensor changes temperature while being warmed in the hand.
Label each sensor with its channel number.


9. Install SQLITE3:

$ sudo apt-get update
$ sudo apt-get install sqlite3


10. Create SQLITE3 temperature database: (do this in /home/pi)

For one channel:

$ sqlite3 temp_data.db
BEGIN;
CREATE TABLE temps (timestamp DATETIME, temp0 NUMERIC);
COMMIT;
.quit


For two channels:

$ sqlite3 temp_data2.db
BEGIN;
CREATE TABLE temps (timestamp DATETIME, temp0 NUMERIC, temp1 NUMERIC);
COMMIT;
.quit



11. Move database to /var/www, change ownership to www-data, and set permissions:

For one sensor:

$ sudo mv temp_data.db /var/www/
$ sudo chown www-data:www-data /var/www/temp_data.db
$ sudo chmod +x /var/www/temp_data.db

For two sensors:

$ sudo mv temp_data2.db /var/www/
$ sudo chown www-data:www-data /var/www/temp_data2.db
$ sudo chmod +x /var/www/temp_data2.db


12. Create cron job for temperature monitor python script

NOTE: the leading '*/5' sets the period to 5 minutes. Adjust as desired.
Only one of the entry lines is required to be added.

$ sudo crontab -u www-data -e
*/5 * * * * /usr/lib/cgi-bin/monitor_1sensor.py <- add this line near bottom for one sensor, OR
*/5 * * * * /usr/lib/cgi-bin/monitor_2sensors.py <- add this line near bottom for two sensors

^o to save the file
^x to exit


At this point the python monitor script should run every 5 minutes, read the sensor(s), and post the data to the database temp_data.db (for one sensor operation) or temp_data2.db (for two sensor operation). All that remains is running the web server python script from a browser to access the database and format and display the resulting web page.


13. Launch Chromium on the RaspberryPi and enter the url for your RPi, followed by the file name for the webgui version used (ie: webgui1.py or webgui2.py). You can use the localhost address as a test.

Eg: http://127.0.0.1/cgi-bin/webgui1.py or http://127.0.0.1/cgi-bin/webgui2.py

Replace 127.0.0.1 with LAN IP address to access web page from a web browser on another system on your LAN.

To access the web page from a system external to your LAN you'll need to determine the external IP address for your network and establish port-forwarding rules through any routers between the public internet and your LAN.



Extra:

Integration with RaspberryPints:

You can replace the RaspberryPints icon with the thermometer icons provided with this kit, and change the http hotspot link to point to the temperature logger page.

Edit the file /var/www/index.php

$ sudo nano /var/www/index.php

Find the .png file tags:

^W (where is) then enter .png and hit Enter
The cursor will move to the first instance.
We will change the http url and the filename

Replace "http://www.raspberrypints.com" with the url of your RPi server
Replace "raspberrypints-4k" with "thermometer4k"

Two lines below is the other instance.

Replace "http://www.raspberrypints.com" with the url of your RPi server
Replace "raspberrypints" with "thermometer".

^o to save the file
^x to exit nano


Examples:

<a href="http://96.252.83.5:84/cgi-bin/webgui2.py"><img src="img/thermometer4k.png" height="200" alt=""></a>

<a href="http://96.252.83.5:84/cgi-bin/webgui2.py"><img src="img/thermometer.png" height="100" alt=""></a>

[Note: for now, at least, those two urls will access my 'Pi]

Now, when you load your RaspberryPints taplist, there should be a thermometer icon in the top right corner than when clicked will load your temperature logger page.

================================================================================================================
Credits!

Totally facilitated by Steve Breuning's work found here: http://raspberrywebserver.com/cgiscripting/rpi-temperature-logger/
I merely expanded the database for multiple probes and tweaked some database, python and html code. I'd be at Square One without his precedent.

And, of course, fellow HBTer Thadius856 and his RaspberryPints crew for not only the Digital Tap List effort but for the inspiration to get off my ass and build what I couldn't buy.

Cheers!

/Dave T. (aka day_trippr)
 
OP
day_trippr

day_trippr

Covid-19 Vaccine Effectivity Test Subject
Joined
May 31, 2011
Messages
35,832
Reaction score
18,201
Location
Stow, MA
Thanks, it's truly a pleasure to pass this forward. I've been having a ball with the wee Raspberry Pi and can see all kinds of geeky functions in store.

wrt to this project, along with expanding the number of supported probes to at least four if not five, I'll be adding "alert" functions to cover out-of-band operation - certainly temperature thresholds for both probes, but perhaps a "short cycle" warning as well.

And for those not interested in "historic" data I'll write up a script that can be run nightly via CRON to scrub out aged database entries [I intend to acquire a full year of data just to have as a baseline for performance comparisons in the future - but I'm slightly "off" ;) ]

I built my current keezer at the end of last year and have been wondering what the compressor cycle time actually was ever since. I've yet to be in the vicinity of the keezer through a full cycle and while I could guess it was at least an hour I had no actual evidence in support of that "best guess".

This goes to the crux of why I wanted a temperature logger than I could access easily (read: remotely). Having experienced the prolonged demise of my previous keezer (RIP) due to compressor seal wear (poor thing was 18+ years old) and seeing the duty cycle slowly approach 100% I thought it would be nice to have hard data to know what was going on with my next keezer, not to mention being able to see how my fermentation fridge is doing, as well as my cold conditioning/carbonation fridge. This widget solves that problem nicely for me. It's just a matter of adding probes and expanding the database.

The graph is interactive in the sense you can position the cursor over the plot lines and the node data will appear. Makes it easy to calculate cycle times by comparing the timestamps for the peaks. Gotta love Google services :)

Cheers!
 
OP
day_trippr

day_trippr

Covid-19 Vaccine Effectivity Test Subject
Joined
May 31, 2011
Messages
35,832
Reaction score
18,201
Location
Stow, MA
Installed support for issuing emails from my wee 'Pi and sent a couple of test messages successfully. They made this almost too easy - I think it took all of 15 minutes, from the time I Googled for what I needed to get it running to the reception of the first email. Gotta love the Raspberry Pi and Unix communities.

Might be a couple weeks before I get much further as I'll be traveling quite a bit shortly, but out-of-band operation emailed alerts will be a piece of cake...

Cheers!
 

rabeb25

HE of who can not be spoken of.
Joined
Jan 30, 2009
Messages
694
Reaction score
145
Location
IDB
NICE WORK!

I don't want to steal your thunder in any way shape or form, but I wanted to show you what I integrated into Rpints. It not only logs, but can control as well. Since you already bought the sensors, it would only cost the the $18 for the arduino, and $8 for the relay.

http://taplist.noip.me (top right corner)

Cheers!
 

rabeb25

HE of who can not be spoken of.
Joined
Jan 30, 2009
Messages
694
Reaction score
145
Location
IDB
Installed support for issuing emails from my wee 'Pi and sent a couple of test messages successfully. They made this almost too easy - I think it took all of 15 minutes, from the time I Googled for what I needed to get it running to the reception of the first email. Gotta love the Raspberry Pi and Unix communities.

Might be a couple weeks before I get much further as I'll be traveling quite a bit shortly, but out-of-band operation emailed alerts will be a piece of cake...

Cheers!
I am very interested in this.. How about some tweeting ability.. its got to be easy enough, my meat smoker controller will do it!
 
OP
day_trippr

day_trippr

Covid-19 Vaccine Effectivity Test Subject
Joined
May 31, 2011
Messages
35,832
Reaction score
18,201
Location
Stow, MA
NICE WORK!

I don't want to steal your thunder in any way shape or form, but I wanted to show you what I integrated into Rpints. It not only logs, but can control as well. Since you already bought the sensors, it would only cost the the $18 for the arduino, and $8 for the relay.[...]
Yup, I've been following the various BrewPi threads. It certainly looked easy enough to bolt on via page links, but I already have a controller integrated into the lid on my keezer so that's an unnecessary capability for me. I also want more temperature channels than BrewPi appeared to support. The Arduino Alamode I have will be handling the flow meters once RaspberryPints is ready...

Cheers!
 
OP
day_trippr

day_trippr

Covid-19 Vaccine Effectivity Test Subject
Joined
May 31, 2011
Messages
35,832
Reaction score
18,201
Location
Stow, MA
I am very interested in this.. How about some tweeting ability.. its got to be easy enough, my meat smoker controller will do it!
I don't tweet, but if someone's interested in that ability they're welcome to cobble it together. If it works I'd be happy to include it, or they can package it up on their own, no problem here...

Cheers!
 

rabeb25

HE of who can not be spoken of.
Joined
Jan 30, 2009
Messages
694
Reaction score
145
Location
IDB
Can you tell me what you googled, or if you have your configs somewhere? My googlefu is not working today apparently, for email/sms that is.
 

bonebrews

Active Member
Joined
Jan 28, 2014
Messages
25
Reaction score
2
Working with the ds18b20's is incredibly easy. Combine that with a microcontroller & relay and you have a very powerful combo for homebrewers. I'm using a beaglebone black with NodeJS/apache/mysql to control my brew day. It's super simple to control the GPIOs with a little bit of webdev knowledge and a few Node libraries.

There is a twitter api that should not be difficult to integrate. I'm sure there are existing python libraries for it.
 
OP
day_trippr

day_trippr

Covid-19 Vaccine Effectivity Test Subject
Joined
May 31, 2011
Messages
35,832
Reaction score
18,201
Location
Stow, MA
Can you tell me what you googled, or if you have your configs somewhere? My googlefu is not working today apparently, for email/sms that is.
Go here.
Literally within 15 minutes I had the Pi sending email messages from the command line.

Note unexpected consequences: once you have the mechanism to send email messages, Cron will use it. As I'm currently running four different instances of the temperature logger, within five minutes of enabling outgoing email my GMail account was being bombed by the 'Pi as the four Cron jobs completed every five minutes (I thought it was hilarious, actually ;) )

Appending '> /dev/null 2>&1' to each Crontab entry will put a stop to that...

Cheers!
 
OP
day_trippr

day_trippr

Covid-19 Vaccine Effectivity Test Subject
Joined
May 31, 2011
Messages
35,832
Reaction score
18,201
Location
Stow, MA
It was reassuring to be able to keep a remote eye on my keezer while on an island in the Bahamas for two weeks. Had something gone amiss I could have dispatched youngest son to go over to my house and either fix a problem or move the kegs to my brewery fridges.

Anyway...a couple of things to mention.

First, the temperature log file grows linearly, of course, and eventually you can feel the wee 'Pi grinding through thousands of database records outside the scope of the viewing widget (the latest 168 hours/1 week is as far back as I coded for). So I went to school and learned how to selectively delete records from the sqlite3 database (don't laugh - it's like brain surgery to me ;) ) and then wrote a simple python script that runs under cron once a week to purge the database back to the latest 200 hours of records.

This will likely trash the heck out of the formatting that Python is oh-so-picky about, but...


#!/usr/bin/env python

import sqlite3
import os
import time
import glob

#------------------------------------------------------------------------
# global variables
dbname='/var/www/tempdata.db'

#------------------------------------------------------------------------
# purge old entries in the database
def delete_data():

conn=sqlite3.connect(dbname)
curs=conn.cursor()

curs.execute("DELETE FROM temps WHERE timestamp<datetime('now','localtime','-200 hours')")
conn.close()


#------------------------------------------------------------------------
# main function
# This is where the program starts
def main():

# purge the database
delete_data()

# time.sleep(speriod)

if __name__=="__main__":
main()

#-----------------------------------------------------------------------

Note: Change "tempdata.db" to the file name of your database.


Second...A couple of days ago I noticed the cycle time of my keezer's compressor had shortened to a little more than 90 minutes. Investigation showed that the keg I had been using for both the MH1210 controller probe and the 'Pi's "Keg Temperature" probe had been drained below the level of the two probes strapped to the middle of the keg. This pretty much removed the hysteresis provided by the probes "reading" the temperature of a large mass of beer. In essence they were reading just the skin temperature of the keg which "moves" a lot faster than a few gallons of beer.

I relocated the probes to a recently added keg that was nearly full and the effect on the compressor cycle time was pretty dramatic - it went to nearly 3 hours. The average beer temperature didn't change at all but the curves are quite different. So, mass matters. Duh...

Cheers! :)

rpints_temp_cycle_change.jpg
 

rawlus

Well-Known Member
Joined
Mar 2, 2010
Messages
515
Reaction score
58
Location
milford, ma
It was reassuring to be able to keep a remote eye on my keezer while on an island in the Bahamas for two weeks. Had something gone amiss I could have dispatched youngest son to go over to my house and either fix a problem or move the kegs to my brewery fridges.

Anyway...a couple of things to mention.

First, the temperature log file grows linearly, of course, and eventually you can feel the wee 'Pi grinding through thousands of database records outside the scope of the viewing widget (the latest 168 hours/1 week is as far back as I coded for). So I went to school and learned how to selectively delete records from the sqlite3 database (don't laugh - it's like brain surgery to me ;) ) and then wrote a simple python script that runs under cron once a week to purge the database back to the latest 200 hours of records.

This will likely trash the heck out of the formatting that Python is oh-so-picky about, but...


#!/usr/bin/env python

import sqlite3
import os
import time
import glob

#------------------------------------------------------------------------
# global variables
dbname='/var/www/tempdata.db'

#------------------------------------------------------------------------
# purge old entries in the database
def delete_data():

conn=sqlite3.connect(dbname)
curs=conn.cursor()

curs.execute("DELETE FROM temps WHERE timestamp<datetime('now','localtime','-200 hours')")
conn.close()


#------------------------------------------------------------------------
# main function
# This is where the program starts
def main():

# purge the database
delete_data()

# time.sleep(speriod)

if __name__=="__main__":
main()

#-----------------------------------------------------------------------

Note: Change "tempdata.db" to the file name of your database.


Second...A couple of days ago I noticed the cycle time of my keezer's compressor had shortened to a little more than 90 minutes. Investigation showed that the keg I had been using for both the MH1210 controller probe and the 'Pi's "Keg Temperature" probe had been drained below the level of the two probes strapped to the middle of the keg. This pretty much removed the hysteresis provided by the probes "reading" the temperature of a large mass of beer. In essence they were reading just the skin temperature of the keg which "moves" a lot faster than a few gallons of beer.

I relocated the probes to a recently added keg that was nearly full and the effect on the compressor cycle time was pretty dramatic - it went to nearly 3 hours. The average beer temperature didn't change at all but the curves are quite different. So, mass matters. Duh...

Cheers! :)
Great stuff
 
OP
day_trippr

day_trippr

Covid-19 Vaccine Effectivity Test Subject
Joined
May 31, 2011
Messages
35,832
Reaction score
18,201
Location
Stow, MA
I'm tellin' ya, the darned 'Pi is addictive. While waiting for V2 of the 'Pints code to hit the streets I'm finding plenty of stuff to keep occupied. I'm definitely going to add a couple more probes, one to monitor my tower temperature and one for ambient temperature, just to see what's up. And I want to see if I can hook some lights to the 'Pi and have them come up gradually when the PIR sensor fires. And I'm thinking it might be interesting to use the PID code from Brew Pi or similar "controller" packages to run my keezer and one or both of my fridges.

With that and a lot more on my mind I decided I needed a development 'Pi - a complete clone of my first 'Pi complete with another AlaMode - so I don't have to drag the prime 'Pi away from the keezer down stairs when I want to play with something that might require physical intervention. Ordered it Thursday night, Amazon says the whole kit will be here tomorrow (gotta love Prime!)

Between play-off hockey, a two batch Big Brew Day and new toys arriving this should be a fine weekend in spite of iffy weather!

Cheers! :ban:
 

ratsathome

Well-Known Member
Joined
May 20, 2012
Messages
109
Reaction score
11
Location
Meath
Installed yesterday the probe and the software.When I run the "$ python test_sensors.py" it shows the temp.
My problem is the web part if I click on the icon it takes me to another web page as it should but said "No data found"
Any idea where I went wrong?
Thanks in advance.
 
OP
day_trippr

day_trippr

Covid-19 Vaccine Effectivity Test Subject
Joined
May 31, 2011
Messages
35,832
Reaction score
18,201
Location
Stow, MA
You'll get that message from webguin.php if there are no database entries with a time-stamp within the default (24 hour) window.
First suspicion is that the monitor script is either never executing or it can't open the database for writes.

You can try manually running the sensor polling script to stick an entry in the database:

sudo python /usr/lib/cgi-bin/monitor_1sensor.py (or monitor_2sensors.py)

If you don't get a permissions issue with writing the database, try the web page again. If you get the graph this time, check that you actually added the crontab entry for www-data to run the script:

sudo crontab -u www-data -e

There should be an entry that looks like this:

*/5 * * * * /usr/lib/cgi-bin/monitor_1sensor.py (for one sensor), OR
*/5 * * * * /usr/lib/cgi-bin/monitor_2sensors.py (for two sensors)

If you still get the no data message go back through the procedure and especially check files are in the right places and permissions have been set. If manually running the polling script causes file open errors with the database, fix that first :)

Cheers!
 

ratsathome

Well-Known Member
Joined
May 20, 2012
Messages
109
Reaction score
11
Location
Meath
You'll get that message from webguin.php if there are no database entries with a time-stamp within the default (24 hour) window.
First suspicion is that the monitor script is either never executing or it can't open the database for writes.

You can try manually running the sensor polling script to stick an entry in the database:

sudo python /usr/lib/cgi-bin/monitor_1sensor.py (or monitor_2sensors.py)

If you don't get a permissions issue with writing the database, try the web page again. If you get the graph this time, check that you actually added the crontab entry for www-data to run the script:

sudo crontab -u www-data -e

There should be an entry that looks like this:

*/5 * * * * /usr/lib/cgi-bin/monitor_1sensor.py (for one sensor), OR
*/5 * * * * /usr/lib/cgi-bin/monitor_2sensors.py (for two sensors)

If you still get the no data message go back through the procedure and especially check files are in the right places and permissions have been set. If manually running the polling script causes file open errors with the database, fix that first :)

Cheers!
Tx that sorted it. :rockin:
Now just to make it read °C for me. ;)
 

ratsathome

Well-Known Member
Joined
May 20, 2012
Messages
109
Reaction score
11
Location
Meath
It was reassuring to be able to keep a remote eye on my keezer while on an island in the Bahamas for two weeks. Had something gone amiss I could have dispatched youngest son to go over to my house and either fix a problem or move the kegs to my brewery fridges.

Anyway...a couple of things to mention.

First, the temperature log file grows linearly, of course, and eventually you can feel the wee 'Pi grinding through thousands of database records outside the scope of the viewing widget (the latest 168 hours/1 week is as far back as I coded for). So I went to school and learned how to selectively delete records from the sqlite3 database (don't laugh - it's like brain surgery to me ;) ) and then wrote a simple python script that runs under cron once a week to purge the database back to the latest 200 hours of records.

This will likely trash the heck out of the formatting that Python is oh-so-picky about, but...


#!/usr/bin/env python

import sqlite3
import os
import time
import glob

#------------------------------------------------------------------------
# global variables
dbname='/var/www/tempdata.db'

#------------------------------------------------------------------------
# purge old entries in the database
def delete_data():

conn=sqlite3.connect(dbname)
curs=conn.cursor()

curs.execute("DELETE FROM temps WHERE timestamp<datetime('now','localtime','-200 hours')")
conn.close()


#------------------------------------------------------------------------
# main function
# This is where the program starts
def main():

# purge the database
delete_data()

# time.sleep(speriod)

if __name__=="__main__":
main()

#-----------------------------------------------------------------------

Note: Change "tempdata.db" to the file name of your database.


Second...A couple of days ago I noticed the cycle time of my keezer's compressor had shortened to a little more than 90 minutes. Investigation showed that the keg I had been using for both the MH1210 controller probe and the 'Pi's "Keg Temperature" probe had been drained below the level of the two probes strapped to the middle of the keg. This pretty much removed the hysteresis provided by the probes "reading" the temperature of a large mass of beer. In essence they were reading just the skin temperature of the keg which "moves" a lot faster than a few gallons of beer.

I relocated the probes to a recently added keg that was nearly full and the effect on the compressor cycle time was pretty dramatic - it went to nearly 3 hours. The average beer temperature didn't change at all but the curves are quite different. So, mass matters. Duh...

Cheers! :)
:drunk: In which file do you put this info in?
Sorry for all the stupid questions,I'm learning as I go with this :eek:
 
OP
day_trippr

day_trippr

Covid-19 Vaccine Effectivity Test Subject
Joined
May 31, 2011
Messages
35,832
Reaction score
18,201
Location
Stow, MA
The "purge database" Python script is its own file.
You can create it in /home/pi and call it anything you like.

You can then manually run it once a week or put an entry in cron to run it weekly. It does require root privs so preface the command line entry with sudo...

Cheers!
 

ratsathome

Well-Known Member
Joined
May 20, 2012
Messages
109
Reaction score
11
Location
Meath
The "purge database" Python script is its own file.
You can create it in /home/pi and call it anything you like.

You can then manually run it once a week or put an entry in cron to run it weekly. It does require root privs so preface the command line entry with sudo...

Cheers!
Tx how do I know if it did the job?
When I run it manually it return to the $, is that right?
Do I have to open the temp_data.py file to see if it worked?
Sorry for all the questions still learning as I go.
Got all the temps to °C though :D
 
OP
day_trippr

day_trippr

Covid-19 Vaccine Effectivity Test Subject
Joined
May 31, 2011
Messages
35,832
Reaction score
18,201
Location
Stow, MA
- I suppose you don't actually know for sure. But you can read the code, and if the program doesn't bomb and the file pointers are correct, something must have happened ;)
- Yes, there isn't any informative output, it just runs to completion and exits.
- Nah. Read the code, trust the code.
- That's ok - ask whatever, whenever, I don't have a problem with that.
The more folks that get into R'Pi's and Arduinos and the lot the better for everyone, and if this little project helps then it was worth doing :)

Cheers!
 
OP
day_trippr

day_trippr

Covid-19 Vaccine Effectivity Test Subject
Joined
May 31, 2011
Messages
35,832
Reaction score
18,201
Location
Stow, MA
Had a bit of "excitement" this morning when I discovered that both the 'Pi that runs and monitors my keezer and the development system in my office had both disappeared from the network. Checked my LAN infrastructure and all seemed well, rebooted the dev system with no change in status, then switched it from wifi to hardwired nic with no joy.

Had to switch to "making the money money" as my oldest grandson says, so I left things alone 'til I could break for lunch. At that point daybreak had dawned over Marblehead and I remembered that all my browser shortcuts on my workstation and my phones and tablet use my external IP to access the various agents throughout the house, and a quick check of my gateway revealed that for the first time since Verizon lit up my fiber drop over two years ago, they finally assigned me a new ip address!

The bastids! :cross:

Soooo...the 'Pi running and monitoring my keezer is still supporting the two example temperature loggers linked in Post #1, but the ip address has changed.
For some reason I can no longer edit the original post.

single channel monitor: http://96.252.83.39:84/cgi-bin/webgui1.py

two channel monitor: http://96.252.83.39:84/cgi-bin/webgui2.py

Not sure how much longer I'll keep those pages active, but so far they haven't caused any issues, so I'll defer to inertia for now...

Cheers!

(ps: yeah, I could use a DDNS service, but ain't nobody got time for that! ;) )
(pps: I'm running a full five channel monitor script on my dev system. When I deploy that setup to the keezer I'll be monitoring beer temperature, keezer air temp, tower air temp, room temp, with the fifth probe available for experiments - like sticking a thermowell in a gallon jug of water to see what that looks like)...
 

ratsathome

Well-Known Member
Joined
May 20, 2012
Messages
109
Reaction score
11
Location
Meath
Been getting "500 Internal Server Error" for the last week. Uninstalled everything and re-installed it again with no help.
Any ideas?
 
OP
day_trippr

day_trippr

Covid-19 Vaccine Effectivity Test Subject
Joined
May 31, 2011
Messages
35,832
Reaction score
18,201
Location
Stow, MA
No, I haven't run into anything similar, and the 500 code is so generic I wouldn't know what specifically to even look for. Any chance you have a backup image from a working configuration to restore?

Cheers!
 
OP
day_trippr

day_trippr

Covid-19 Vaccine Effectivity Test Subject
Joined
May 31, 2011
Messages
35,832
Reaction score
18,201
Location
Stow, MA
Gah! So I left one consideration off the list a few posts back: add "if you don't actually commit your database modifications, they don't take" :D

Ratsathome, your intuition must've been kicking in, because I found a bug in that "purge database" script.

One missing line: conn commit() [just before conn close()] kept the script from actually removing the selected row.
I didn't notice it until a few minutes ago even though it's a glaring omission ;)

The updated script is below.

Cheers!


#!/usr/bin/env python

import sqlite3
import os
import time
import glob

#------------------------------------------------------------------------
# global variables
dbname='/var/www/tempdata.db'

#------------------------------------------------------------------------
# purge old entries in the database
def delete_data():

conn=sqlite3.connect(dbname)
curs=conn.cursor()

curs.execute("DELETE FROM temps WHERE timestamp<datetime('now','-200 hours')")
conn.commit()
conn.close()


#------------------------------------------------------------------------
# main function
# This is where the program starts
def main():

# purge the database
delete_data()

# time.sleep(speriod)

if __name__=="__main__":
main()

#-----------------------------------------------------------------------


change the tempdata.db pointer if needed...
 

JonW

Well-Known Member
Lifetime Supporter
Joined
Dec 9, 2009
Messages
2,100
Reaction score
310
Location
Huntington Beach, CA
Great stuff here! :mug: If you have the Pi, might as well find more uses for it.

This got me thinking... I need to figure out how to write a script to pull in my temps from the BCS and display it on the RaspberryPints screen.
 

AngryMonk

Well-Known Member
Joined
Sep 20, 2013
Messages
78
Reaction score
16
In the same idea, I have build a controller for my fermentation chamber. Now, it is monitoring my kegerator, the first gauge being my garage temperature.
I use a raspberry pi, a few DS18B20 sensors, a relay board to control fridge compressor, fan, heater...
I log temperature in a MySQL database and plot data using highcharts.
I am hoping to be able to do a write up and share my work someday...

Ferm.jpg
 
OP
day_trippr

day_trippr

Covid-19 Vaccine Effectivity Test Subject
Joined
May 31, 2011
Messages
35,832
Reaction score
18,201
Location
Stow, MA
Very nice work there! I may have to look into the charting routine.

Meanwhile...We've been in a prolonged heat and humidity wave here over the last week.

I call this image "Capitulation"...

Cheers! ;)

capitulation.jpg
 
OP
day_trippr

day_trippr

Covid-19 Vaccine Effectivity Test Subject
Joined
May 31, 2011
Messages
35,832
Reaction score
18,201
Location
Stow, MA
Upgraded my keezer 'Pi to five channel logging.

It has provided some insight: the tower cooler is making about 25°F differential vs room temperature, good enough to cause condensation puddles around the column base but not as good as I hoped (although I don't have first-pour problems at all); the fan that keeps the interior air mixed up works really well (to the point that I just switched the "upper" and "lower" probes for a sanity check); the heat generated by the keezer when running is non-trivial; and I might be able to relax the differential a bit during the summer.

Once I get some benchmarks established I'm going to stick one of the probes in a thermowell and stick it in a 3 gallon water jug to see what that looks like.

Wintertime project will be to migrate to a better plotting package. I really like the one BrewPi grabbed (zoomable is cool) but I'll need to do some "learnin'" to pull that off...

Cheers!

5_channel_plot.jpg
 
OP
day_trippr

day_trippr

Covid-19 Vaccine Effectivity Test Subject
Joined
May 31, 2011
Messages
35,832
Reaction score
18,201
Location
Stow, MA
Made an adjustment on the tower cooler that dropped the temperature up there by a good ten+ degrees. Now it's only ~8 degrees above the keezer air temperature. Progress!

Cheers!

better_tower_air_02.jpg
 
OP
day_trippr

day_trippr

Covid-19 Vaccine Effectivity Test Subject
Joined
May 31, 2011
Messages
35,832
Reaction score
18,201
Location
Stow, MA
Received another batch of 3 meter probes, wired them up to connectors, hooked them up to my dev system, and for the first time found a significant difference between the probe readings. One pair of probes was reading a good 1.5°F higher than the rest - which correlated within a tenth of the rest of my probe population.

Decided it was time to make a modification of my monitor script (monitor5.py, in this case) to provide a handy place to adjust probe readings. I created a set of variables that then get used to correct the pulled data before it gets stored in the database. Turns out to be dead simple to do.

.
.
.

#------------------------------------------------------
# global variables
speriod=(15*60)-1
#speriod=(5*60)-1
dbname='/var/www/tempdata5.db'

# added values for adjusting probes
adjch0=0
adjch1=0
adjch2=0
adjch3=-1.5
adjch4=-1.5
.
.

#Example of where the adjustment values get used - two places per probe fetch

# while True:

# get the first temperature from the first device file
temperature0 = get_temp(w1devicefile0)+adjch0
if temperature0 != None:
print "temperature0="+str(temperature0)
else:
# Sometimes reads fail on the first attempt
# so we need to retry
temperature0 = get_temp(w1devicefile0)+adjch0
print "temperature0="+str(temperature0)

.
.
.


With those changes I have all five probes reading within a two tenths spread at the current temperature. Now I can do some testing to see how well they track each other with changing temperature. If the two outliers don't stick close to the others I'll be able to send the data to the supplier to get those probes replaced...

Cheers!

probe_correlation.jpg
 

Dolomieu

Well-Known Member
Lifetime Supporter
Joined
Jan 4, 2012
Messages
1,055
Reaction score
121
Location
Columbus
I'm going to be trying this out soon. I have the pi wired up to 5 sensors already. Just need to learn a little about permissions as after i downloaded and extracted your zip file it won't let me move it from /home/pi
 
OP
day_trippr

day_trippr

Covid-19 Vaccine Effectivity Test Subject
Joined
May 31, 2011
Messages
35,832
Reaction score
18,201
Location
Stow, MA
You can do darned near anything if you prefix a command with "sudo" - which grants root privs for that instance.

So

$ mv monitor5.py /var/www

becomes

$ sudo mv monitor5.py /var/www

As well, once you're logged into a terminal session as a lowly user, if you execute the command "sudo su" the session will be elevated to root privs, and from there anything you do will have superuser rights. To get the session back to the original user, use the "exit" command.

Of course, you still need to fix any ownership/access rights once the file is resident in its "home".

fwiw, if you have a Windows peecee, WinSCP is a fantastic tool for remote file management on the 'Pi. Pushing/pulling files to/from the 'Pi or moving them around is easy, and visualizing and fixing ownership and access flag issues are a piece of cake. Between WinSCP and Putty I almost never use local access to my 'Pi systems...

Cheers!
 

IanJ

Well-Known Member
Joined
Feb 8, 2011
Messages
249
Reaction score
33
Location
Brooklyn
Thanks for sharing, pretty much exactly what I needed :)



My Arduino is still in a box, and the connectors aren't even ordered, so this should work out well.
 

Dolomieu

Well-Known Member
Lifetime Supporter
Joined
Jan 4, 2012
Messages
1,055
Reaction score
121
Location
Columbus
i swear i tried sudo a dozen times, but it worked. thanks. So how much more was it to add the other three sensors form your original two sensor setup? 3 more monitor_#sensor.py files? and 3 additional webgui#.py files?

sorry if this is a blatantly dense question.
 
OP
day_trippr

day_trippr

Covid-19 Vaccine Effectivity Test Subject
Joined
May 31, 2011
Messages
35,832
Reaction score
18,201
Location
Stow, MA
Trust me, while I have a healthy patent portfolio after 40+ years in computing hardware design, and I'm pretty good at creating behavioral, structural and analog simulation models and test cases in a range of very expensive test environments, my practical "fun/not work related" coding skills are effin' appalling ;) EVERYTHING is "dense" to me. See my "How do I center this darned image!" post earlier today :D

Anyway, aside from a Wal-Mart full of html space characters, it was just extending the monitor.py file to stuff more channel data into the database, and the html side to pull more entries out. One of these days I'll stick my toes into html tables, I'm sure that's the answer to my ridiculous formatting.

I'll try to add the two files to the Drive share tonight. The monitor file will also have the adjustment mechanism (I'll set the values to 0) to allow probe correction...

Cheers!
 
OP
day_trippr

day_trippr

Covid-19 Vaccine Effectivity Test Subject
Joined
May 31, 2011
Messages
35,832
Reaction score
18,201
Location
Stow, MA
Ok, I've updated the kit contents on the Google Drive share here adding the monitoring script and the webgui files for the 5 channel setup, along with updated instructions - and refreshing the monitoring scripts for the 1 and 2 channel setups.

The probe channel adjustment function is in all three probe monitoring scripts with the values set to 0. You can use this function to adjust your probes to each other, or to a standard. Just change the values declared at the top of the monitor script, the rest is automagic.

Any problems please let me know!

Cheers!
 

Dolomieu

Well-Known Member
Lifetime Supporter
Joined
Jan 4, 2012
Messages
1,055
Reaction score
121
Location
Columbus
that would be great. i like the probe correction factor addition as well. i've gotten all the way through testing the probes tonight but the ipaddress/cgi-bin/webgui2.py page is drawing blank. thanks for all the help!
 

Latest posts

Top