Web-Accessible Temperature Logger for Raspberry Pi

Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum

Help Support Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.
[...]Couple of quick questions,
1. What version of python are you using?
2. Are you using mod_cgi or mod_wsgi or mod_python?
3. Did you follow the server setup in raspberrywebserver.com?
Thanks again for being available to ask questions.

1. 2.7.3
2. As best as I can tell I've never enabled/installed any of those.
3. Nope. I just installed sqlite3, Apache was already resident and serving pages because of the prior RaspberryPints installation.

Note that I have only ever run this on Wheezy and using Python 2.7.3.
I have no idea if it'll work without some massaging when run on Jessie or using Python 3.x...

Cheers!
 
1. 2.7.3
2. As best as I can tell I've never enabled/installed any of those.
3. Nope. I just installed sqlite3, Apache was already resident and serving pages because of the prior RaspberryPints installation.

Note that I have only ever run this on Wheezy and using Python 2.7.3.
I have no idea if it'll work without some massaging when run on Jessie or using Python 3.x...

Cheers!
First I want to thank you for not only your time spent on putting this together but also trying to help persons like me get it running. Now for the good news I got it running! Turns out there was a space on the first line before the shebang! I must have looked over the script a dozen time and finally saw it. Thanks again and as I play with this some more if I come up with any upgrades I will make sure to post them here.
 
fwiw, I have my logger running on Raspbian Jessie with the latest/greatest Apache2.
I followed my "instructable" to make sure it still worked, and found I needed to run the following command to get Apache2 to actually execute Python instead of displaying it as text:

Code:
$ sudo a2enmod cgi

Once I ran that everything worked same as "The Good Ol' Days" with Wheezy.

So, add that to the end of the instructions and you'll be good to go...

Cheers! :mug:
 
Hi Guys,

I'm trying to pimp up the webpage a little bit.
I want to add some gauges on the mainpage which so represent the actual temperatures measurd.

I've tried adding some from google. But with no success. :(

Has some one already tried to do this? Or maybe some one can help me check up my added code?
 
Hi,

Can someone help me I'm almost done. I'm trying to put a clock on the page. I put the code <?php echo date ("h:I"); ?> At the top of the temp_insert. Php file but when I do it puts the time above the thermometer in the right corner and pushes the temp icon into the poured/remaining text. I have no idea what I'm doing and if where it should go any help would be great. Thank you.

image.jpg
 
I think you're going to need to use relative positioning for that, but honest to gawd html is My Weakest Link, so I'm not going to be hella useful.

But if you get it figured out please post the code here :)

Cheers!
 
Thank you day tripper. I'm not good at html . I'm lucky I got the flow meters working and the temps logging. Only because you gave very good instructions. Thanks for all your hard work.
 
Hey day_tripper
Can you help me with the purge_dbase.py I don't think it's working I'm sure I did something wrong. I did this sudo crontab -e -u www-data and put this code at the bottom 00 00 * * 0 /home/pi/purge_dbase.py can you help me out? Does it matter if it doesn't get purged. Is there a manual way to purge it or delete it?

Thank you.
 
Just checked and it appears I ended up using the root account for the cron task.
And that was so long ago I can't remember why, but for sure it would have had something to do with permissions that I likely could have fixed another way ;)

Anyway...

If you never purge the database back it'll continue to grow and eventually you'll notice the added latency in plotting the graph.

Code:
$ sudo crontab -e

0 0 * * * /home/pi/purge_dbase.py > /dev/null 2>&1

Save it and you should be good. Don't forget to get rid of whatever other purge task you have set up in cron.

You can run the same python script from a terminal:

Code:
$ sudo python purge_dbase.py

Cheers!
 
After being absent for awhile I installed everything new and having a problem with the logger. It show on the web page but does not automaticaly plot the time. I have to run the "python script" manualy for it to work.
I did the cron job in both "www-data" and "root" and it is set for 5 min.
Any help would be gr8.

And the graph is gone to
 
Ok got it working:D
Another question: if you are on the "webgui" web page the temp log is shown for "the last 24 hours" as default. What do I change to have it say "last 6 or 1 hour" as default in the webgui.py folder.
tx
 
In webgui(x).py, look for two instances of these two lines:

if option is None:
option = str(24)

You can change the value of str to 1, 6, 24, 48, 168, or 240, to have the graph and table display the corresponding number of hours of data by default...

Cheers!
 
What browser are you using? And have you tried others?

When you click on the thermometer the log graph and tables are displayed correctly?
The only thing missing is the "scrolling" display?

The fact that the thermometer appears at all says you have an entry in the RaspberryPints index.php pointing to the temp_insert.php correctly, so I expect if there's a problem it's with your edit of the latter...

Cheers!
 
No I've only tried Chromium.

Nothing happens when I click on the thermometer as well. I put the code in for the graphic as per the instructions.

I'm thinking I've missed something in the coding to put the scrolling temps in.

When I go to the localhost/cgi-bin/webgui2.py I get the page with the temp logs but no graph. I think that might be an issue with the browser. I can't get to most websites on my Pi with Chromium due to bad certificates. Not sure what is going on with that as well.

Thanks.
 
Got it. Post 118 for the header right I was missing the code to get to the temp sensors. Every time I tried it last night it would cut the taps out of the screen. I think I had it going to the wrong file.

Works now and I have my flow meters working as well. Just have to install it in my beer frig as I've been bench testing everything before install

Thanks for all the info between the threads I've been able to get this all working!

View attachment ImageUploadedByHome Brew1497837103.887476.jpg
 
Hello guys!

So in another thread I mentioned a great idea of adding temp displays to the raspberrypints screen. Awesome "original" thought....

you guys beat me to it by a LONG shot. I have a different approach though. decouple the uno and the pi. I abandoned the Uno for the ESP series MCUs. mainly for their form factor and built in Wifi/BT. I want to implement what we have here, but dont want to have a USB between the pi and the ESP.

that could lend itself to scalability as you can have multiple ESPs (keezers, ferm chambers, fridges, brewday, whatever) and 1 pi. Ive mentioned before that I dont know python or php, but I do know html sql, and c/c++/c#. also a network engineer by trade. I will eventually ask some questions regarding how all this actually work, but I have more reading to do first. my goal is to convert it to take readings from wifi instead of serial.
 
I just found others that have done similar in other threads... I should stop posting until i read through it all lol...
 
Somewhere I posted an RPints python file showing how to use an AlaMode on the RPi serial port per the original scheme, or an Uno connected via USB, Bluetooth (using an HC-05) or Wi-Fi (using an esp8266)...

Cheers!
 
Whoops!
Someone forget to re-enable the keezer compressor control after swapping kegs and pulling the Eva-Drys for a drying cycle last night.
I can testify that a +14°F warm-up definitely affects pours :drunk:

keezer_plot_17oct2017.jpg

Stupid brewer trick, and almost enough to get me to add some alarms to this project...

Cheers!
 
HI Thank you for the project,

Is there any way to change the date format that displays on webgui2.py to DD-MM-YYYY??
 
For each recorded temperature reading monitor_(n)sensor.py writes a database row with datetime('now','localtime'), then webgui(n).py extracts the first value of each record as 'Time' with no evident formatting.
You'd have to insert a conversion in webgui(n).py to convert datetime into the format you desire, and then hope the Google graphing API doesn't puke on it...

Cheers!
 
For each recorded temperature reading monitor_(n)sensor.py writes a database row with datetime('now','localtime'), then webgui(n).py extracts the first value of each record as 'Time' with no evident formatting.
You'd have to insert a conversion in webgui(n).py to convert datetime into the format you desire, and then hope the Google graphing API doesn't puke on it...

Cheers!
HI sorry to bother you how would I do that ??
 
Hi Day_trippr
just wondering if you would have an example on how to change

curs.execute("SELECT * FROM temps WHERE timestamp>datetime('now','localtime','-%s hours')" % interval)

to display date and time in day-month-year hour:min

thankyou in advance

Greg
 
Hi Day_trippr
just wondering if you would have an example on how to change

curs.execute("SELECT * FROM temps WHERE timestamp>datetime('now','localtime','-%s hours')" % interval)

to display date and time in day-month-year hour:min

thankyou in advance

Greg

That line only grabs the time from the database.

The line that prints the time is:

Code:
 rowstr="<tr><td>{0}&emsp;&emsp;</td><td>{1}F&emsp;&emsp;</td><td>{2}F</td></tr>".format(str(row[0]),str(row[1]),str(row[2]))
        print rowstr

and the line that puts the time into the database is from monitor_2sensors.py here:

Code:
curs.execute("INSERT INTO temps values(datetime('now','localtime'), (?), (?))", (temp0,temp1))

That would be the first two places to start.
 
I cobbled this package together from open source chunks found in various locations on the web, and while most of the pieces I understood well enough to modify, the big exception is the Google graphing API. I have literally zero knowledge about what it will accept for input, so while clearly it graphs correctly using the string generated from the Raspbian datetime value, I don't know that it will work at all if one were to use a different time format.

As the package does what it claims and I'm busy up to my eyeballs these days, I have no time and pretty near zero motivation to get into it deep enough to understand what changes are possible, never mind execute same. I'll leave that option to anyone who wants to take it on for their own requirements...
 
Hi,

I try to do this:

$ python test_sensors.py


But didn't work. Return this:

bash: python test_sensors.py: comando não encontrado


If I running directly to the home/pi, return this:

File "/home/pi/python/test_sensors.py", line 36
print 'Read Sensor',
^
SyntaxError: Missing parentheses in call to 'print'



What's wrong, please.

I'm sorry I'm noob in linux.
 
Try running as root. Here's an example run:

Code:
pi@rpints ~ $ sudo python test_sensors.py
Looking for W1_Slave Temperature Sensor Devices...

Number of W1_Slave Devices found: 5

Sensor 0 ID: /sys/bus/w1/devices/28-00000689f325
Sensor 1 ID: /sys/bus/w1/devices/28-0000068a2030
Sensor 2 ID: /sys/bus/w1/devices/28-0000068a3443
Sensor 3 ID: /sys/bus/w1/devices/28-0000068a0cee
Sensor 4 ID: /sys/bus/w1/devices/28-0000068a8e2b

Read Sensor 0
Raw Data =  22062
22.062 Degrees C
71.7116 Degrees F
71.7 Rounded
Sensor 0 Temperature = 71.7 F

Read Sensor 1
Raw Data =  21562
21.562 Degrees C
70.8116 Degrees F
70.8 Rounded
Sensor 1 Temperature = 70.8 F

Read Sensor 2
Raw Data =  21750
21.75 Degrees C
71.15 Degrees F
71.2 Rounded
Sensor 2 Temperature = 71.2 F

Read Sensor 3
Raw Data =  22187
22.187 Degrees C
71.9366 Degrees F
71.9 Rounded
Sensor 3 Temperature = 71.9 F

Read Sensor 4
Raw Data =  22250
22.25 Degrees C
72.05 Degrees F
72.0 Rounded
Sensor 4 Temperature = 72.0 F

0
Compressor Off
45
pi@rpints ~ $

Cheers!
 
fwiw, I needed to correlate a bunch of probes so I ginned up versions of the logger and web gui files for 6, 7, 8 and 9 sensors, and generated a new zip file with them. The archive is on my Google Drive, location provided in the first post...

Cheers!

[7 of 9 read within .1°F, the other two have a -.1°F offset but otherwise track with the rest]

9_sensor_plot.jpg
 
Thanks for the work on this. I just set up a Raspberry pi 3B+ with one of these sensors, started with a new Raspbian image, copied over the files, and ran the test_sensors.py. The latest Raspbian has Python 3, and I had to put parentheses around all of the print statements. But now it is stating that "xrange" is not defined. I am new to Python and Linux, but have been a software developer for decades, so i am confident I can depug and upgrade the script. Was wondering if there is a later Python 3 version already done? Is there a newer version of this project that I should instead try?
Thanks
 
It now runs with Python 3

1) Put all Print lines in parentheses:
print (" ")

2) find the two mentions of "xrange" function and rename to "range"

Cheers
 
Last edited:
So, I edited all the python files and put parentheses around all the print statements. The thing that is not working is the chron job. It has to do with permissions but I am unsure what to do about it.

This fails from Bash with error "sqlite3.OperationalError: attempt to write a readonly database"
python /usr/lib/cgi-bin/monitor_1sensor.py

This works perfectly fine
sudo python /usr/lib/cgi-bin/monitor_1sensor.py

When I put this line:
*/2 * * * * /usr/bin/python /usr/lib/cgi-bin/monitor_1sensor.py > /tmp/listener.log 2>&1

And look at the log "sudo nano /tmp/listener.log" after 2 minutes,

The error returned is
sqlite3.OperationalError: attempt to write a readonly database

This
ls -la /var/www/temp_data.db
shows the following permissions:
-rwxr-xr-x 1 www-data www-data 8192 temp_data.db

This appears to give the www-data user rwx permissions on the file. Documentation appears to indicate that I need to make the www-dad user the owner of the folder that the .db file resides in. But I think this will cause other issues with the web site etc.

Any thoughts on how to get the chron job to log the temperature successfully?
Thanks
 
I guess this was an issue with the newer versions of Raspbian, and/or sqlLight. Indeed, the www-data user must have write permissions to the folder that contains the database file. I did the following, and the chron job works perfect now. I am not sure if this is the best method security wise.

# Add the www-data user to the group for the folder where the database file resides
sudo chgrp www-data /var/www

# Make sure the group has write access to the folder where the database file resides.
sudo chmod 775 /var/www/

Thanks for any advice on security of this configuration.
 
I have modified the code and would be happy to contribute it back to the original author or others if desired? I have modified it so that it will automatically deal with 1 to 8 temperature sensors with relatively minor changes to the code. Plug another sensor in and you only need to add the sensor ID to the monitor code for it to start logging and add a user friendly name to the webui code for it to display it (it will display immediately, but without a user-friendly name). I also tidied up the tabular data HTML at the bottom, using style sheets instead of the nbsp padding. Example of the table data is in the image attached. If you add a new sensor, it will automatically display in a new column to the right of the three columns n that screen shot.

I changed it to Celcius, but you only need to set a variable in the monitor code file, and the webui code to change between Fahrenheit and Celcius.

I just did it today so the code is not super polished and tested yet.
 

Attachments

  • Temperature Logger.png
    Temperature Logger.png
    154.8 KB · Views: 0
Back
Top