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.
Sorry for the late reply. Holidays and whatnot. Anyway, typing in sudo python /usr/lib/cgi-bin/monitor_3sensors.py returns with this:

7375

7.375
45.275
45.3
temperature0=45.3
17000

17.0
62.6
62.6
temperature1=62.6
13437

13.437
56.1866
56.2
temperature2=56.2
Traceback (most recent call last):
File "/usr/lib/cgi-bin/monitor_3sensors.py", line 146, in <module>
main()
File "/usr/lib/cgi-bin/monitor_3sensors.py", line 137, in main
log_temperature(temperature0,temperature1,temperature2)
File "/usr/lib/cgi-bin/monitor_3sensors.py", line 32, in log_temperature
curs.execute("INSERT INTO temps values(datetime('now','localtime'), (?), (?), (?))", (temp0,temp1,temp2))
sqlite3.OperationalError: table temps has 3 columns but 4 values were supplied


I don't understand the 4 values part, I only have 3 sensors hooked up...
 
Ok, we can solve this.

When you created the database it should have had four values, three probe readings and the time. It appears you only created a three column database, hence the errors.

Delete that table and make a new one with the proper number of entries...

Cheers!
 
Well it's getting there but still not 100% just yet. The table has now been created and everything seems normal in terminal, even so far that it's showing the /var/www/html/ directory. Now I'm back to the original issue that it's still showing me the "not found" message when I try to access it through the browser...
 
So that's a pretty straightforward error message.
Assuming there actually is a file named webgui3.py in /usr/lib/cgi-bin/, make sure the ownership and access rights have been set:

Code:
$ sudo chown www-data:www-data /usr/lib/cgi-bin/webguiN.py
$ sudo chmod +x /usr/lib/cgi-bin/webguiN.py

Otherwise, look at the apache2 log file at /var/log/apache2/access.log, right after trying to access the logger page.
Here's what I see when I look at one of my systems just seconds after loading the logger gui:

Code:
96.252.xxx.xx - - [01/Jan/2016:23:29:23 -0500] "GET /cgi-bin/webgui_new.py HTTP/1.1" 200 4465 "http://96.252.xxx.xx:85/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
96.252.xxx.xx - - [01/Jan/2016:23:29:25 -0500] "GET /favicon.ico HTTP/1.1" 200 17266 "http://96.252.xxx.xx:85/cgi-bin/webgui_new.py" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"

Note that I'm accessing the logger from outside my LAN so the IP address includes the port to get through my gateway.

Then look at /var/log/apache2/error.log to see what it has to say.
Here's what a failed access to an errant url yields:

Code:
[Fri Jan 01 23:45:30 2016] [error] [client 96.252.xxx.xx] script not found or unable to stat: /usr/lib/cgi-bin/webgui_new[B]x[/B].py

It might be illuminating to see what those files show after a failed access attempt.

Then again, the whole Jessie release seems to be an epic pain in the @ss - it's caused all kinds of aggravation from what I'm seeing.
I don't mind troubleshooting this to the gruesome end, but you might consider going back to Wheezy, where everything worked.

[editorial comment] To me, these things are essentially appliances - glorified toasters, not desktop workstations. Wheezy is mature and everything I've tried just plain works.
Indeed, I see no reason to update any of my four RPi boxes to Jessie. They're doing what they're supposed to do just fine.

If there's some compelling future reason to consider updating literally anything on these li'l machines I'll be open to it, but that hasn't happened yet...

Cheers!
 
When all six kegs in my keezer are full the compressor cycles roughly once ever 5 hours and runs for about 45 minutes. Recently the keezer was down to around 6 gallons total and the cycle time had whittled down to 2 hours with a 20 minute run time.

My logger captured the transition after I loaded four fresh kegs, bring the total volume back up to around 24 gallons. After the banging and crashing from the swapping settled down the cycle time was back up to 4+ hours...

keezer_temp_log_48b_10jan2016.jpg

Cheers!
 
Then again, the whole Jessie release seems to be an epic pain in the @ss - it's caused all kinds of aggravation from what I'm seeing.
I don't mind troubleshooting this to the gruesome end, but you might consider going back to Wheezy, where everything worked.

Couldn't agree more. After way too long of trying to troubleshoot with very limited success(Not just here, but with any of my installs) I've had enough with Jessie and I'm going back. I'll be spending the evening setting everything back up so once I can get to a point to install the temp logger, I'll post results.
 
Hello guys,

My name is Sander and I am from the netherlands.

I found this very nice thread about temperature logging with a raspberry pi.

Sorry that I barge in on the topic but I hope to find some help with this cause I am also trying to do some simulair temperature logging.

Altho it is not for brewing purpose but it is for monitoring my aquarium temperature :D

If you guys dont feel for helping me because it has nothing to do with the main purpose of this forum I can understand it and will stop posten :D
 
Thx !

I tried setting up the site and the python script. But when I access my webapge I get the following errors in the apache error log:

Code:
[Sat Jan 09 22:48:21.417017 2016] [cgi:error] [pid 1161] [client 83.87.15.237:53260] AH01215: File "/usr/lib/cgi-bin/webgui.py", line 2
[Sat Jan 09 22:48:21.417503 2016] [cgi:error] [pid 1161] [client 83.87.15.237:53260] AH01215: import sqlite3 import sys import cgi import cgitb
[Sat Jan 09 22:48:21.417729 2016] [cgi:error] [pid 1161] [client 83.87.15.237:53260] AH01215: ^
[Sat Jan 09 22:48:21.417831 2016] [cgi:error] [pid 1161] [client 83.87.15.237:53260] AH01215: SyntaxError: invalid syntax
[Sat Jan 09 22:48:21.428454 2016] [cgi:error] [pid 1161] [client 83.87.15.237:53260] End of script output before headers: webgui.py
 
The second line in that python file tries to import the sqlite3 interface.
So did you install sqlite3 and create the database as instructed?

Cheers!
 
Well for my own situation, I went back to wheezy and I'm back on the right track...sort of. Now I'm faced with the same error my buddy had several months ago with the "No data found" Page when I access the webgui. Unfortunately, I sort have lost contact with that friend and I don't know when I'll be able to speak to him again. Google tells me that Webgui may be out of date. I have no idea what that means as I didn't know it was something that could be updated, assuming that's even my issue. All three sensors are recognized, and their data is showing up when I run the test script. I thought maybe it was a permissions issue, but I'm sure I did all that properly. Do you have any suggestions, Day_trippr?

(I should have heeded your warning about proper backups. Lesson learned too late...)
 
The second line in that python file tries to import the sqlite3 interface.
So did you install sqlite3 and create the database as instructed?

Cheers!

I am getting closer now :D I tried it agian still not a 100% succes. I now get the following

When I wanna check the website it says "No data found", I think this text is coded generated from one of the py scripts.

So I checked running the monitor.py in my raspberry cmd window and got the following:
Code:
25562

25.562
78.0116
78.0
temperature0=78.0
16125

16.125
61.025
61.0
temperature1=61.0
Traceback (most recent call last):
  File "/usr/lib/cgi-bin/monitor_2sensors.py", line 133, in <module>
    main()
  File "/usr/lib/cgi-bin/monitor_2sensors.py", line 124, in main
    log_temperature(temperature0,temperature1)
  File "/usr/lib/cgi-bin/monitor_2sensors.py", line 30, in log_temperature
    curs.execute("INSERT INTO temps values(datetime('now','localtime'), (?), (?))", (temp0,temp1))
sqlite3.OperationalError: attempt to write a readonly database

I guess this is because I am running it from /home/pi and it doesnt have rights on /var/www ?

Or maybe the cronjob is not being done by the raspberry?

So I think I'm close to finishing it but I cant find out the last part..
 
I am getting closer now :D I tried it agian still not a 100% succes. I now get the following

When I wanna check the website it says "No data found", I think this text is coded generated from one of the py scripts.

So I checked running the monitor.py in my raspberry cmd window and got the following:
Code:
25562

25.562
78.0116
78.0
temperature0=78.0
16125

16.125
61.025
61.0
temperature1=61.0
Traceback (most recent call last):
  File "/usr/lib/cgi-bin/monitor_2sensors.py", line 133, in <module>
    main()
  File "/usr/lib/cgi-bin/monitor_2sensors.py", line 124, in main
    log_temperature(temperature0,temperature1)
  File "/usr/lib/cgi-bin/monitor_2sensors.py", line 30, in log_temperature
    curs.execute("INSERT INTO temps values(datetime('now','localtime'), (?), (?))", (temp0,temp1))
sqlite3.OperationalError: attempt to write a readonly database

I guess this is because I am running it from /home/pi and it doesnt have rights on /var/www ?

Or maybe the cronjob is not being done by the raspberry?

So I think I'm close to finishing it but I cant find out the last part..

Looks like you didn't chmod the database file.
 
Great. How did you get past your first blockade?



I agree...

Cheers!

I really dont know what I did wrong the first time... I must have missed something..

I just started fresh over again this morning. But the chmod command is only to make it executable right? Or does the +x means someting else?

When I check WinSCP I can see the rights of temp_data2.db is like this rwxr-xr-x

I did change the owner of folder /usr/lib/"cgi-bin" to an account I created
 
I really dont know what I did wrong the first time... I must have missed something..

I expect that is true.

I just started fresh over again this morning. But the chmod command is only to make it executable right? Or does the +x means someting else?

When I check WinSCP I can see the rights of temp_data2.db is like this rwxr-xr-x

I did change the owner of folder /usr/lib/"cgi-bin" to an account I created

chmod sets access rights for owner, group and world.
In this case we need to enable rights for the group...

Cheers!
 
I expect that is true.



chmod sets access rights for owner, group and world.
In this case we need to enable rights for the group...

Cheers!

So I tried again after reinstalling my raspberry completly.
Still got the same messages when running the python script.

I just check the crontab if it is working and that one works. I have put my email in it and I receive an email every 5 min.

The email also contains the attempt to run the python script.

Next step I did was changing the owner of /var/www/ to www-data. This resulting in an other problem.
Code:
26.375
79.475
79.5
temperature0=79.5
16312

16.312
61.3616
61.4
temperature1=61.4
Traceback (most recent call last):
File "/usr/lib/cgi-bin/monitor_2sensors.py", line 133, in <module>
main()
File "/usr/lib/cgi-bin/monitor_2sensors.py", line 124, in main
log_temperature(temperature0,temperature1)
File "/usr/lib/cgi-bin/monitor_2sensors.py", line 27, in log_temperature
conn=sqlite3.connect(dbname)
sqlite3.OperationalError: unable to open database file
 
It has be something with the rights to certain folders and files....

I just tried sudo /usr/lib/cgi-bin/mon...py and voila it worked fully ..... :D

but still doesnt work automated :(
 
so i got everything working and when i go to the web page it says "no data" and i set the crontab to 1 minute... wtf. i'm sure i'm doing something wrong. if i Force the python script it works but again... crontab is AFU. i'm pretty sure you need a shell script to execute the python and put that in the home folder and crontab THAT but i'm not 100%
 
I did! there are two things missing out of the main install directions if you're just doing temp data logging, i'm holding one of the twins right now but as soon as i get some time i'll pm or post my findings. nut seriously, th crontab command doesn't work as stated in directions.
 
First, this work is awesome. I did a barebones temp data logger and it&#8217;s not nearly as neat as this. The only thing I would like to see in the future is potentially a method for exporting portions of the database either as XML or ASCII. I&#8217;ve started looking into the &#8220;dump&#8221; command within SQLite3 to this end. Reason for this feature would be to archive brewday temps. My implementation for the temp data logger is in my brew process so I have 1 probe in my HLT, one in the outlet of my RIMS, one in my BK and one in my Chiller inlet and outlet. I will also be looking at a second setup to monitor Fermentation temps across 5 fermenters. I hope that provides enough background for this next portion. I am very interested in RASPINTS but would do a totally separate installation for this in the future, not now. So; this is JUST when setting up your magnificent software on a RASPI for the sole purpose of logging temps. I&#8217;m sorry to belabor the point.


The only things I would add to your install (also very clearly written, thank you) are as follows.

At step 6:

When enabling W1 bus support I found that I couldn&#8217;t read my sensors unless I did the following;

Modify config.txt to have sensors recognized:

sudo nano /boot/config.txt

at the bottom of the page add the following line

dtoverlay=w1-gpio,gpiopin=4

then save the file (CTRL + X, Y, RETURN)

Reboot

sudo reboot

At this point if you couldn&#8217;t see sensors using the test_sensors.py (which I could not) before, this should fix your problem.

Second thing I did and would recommend to anyone is adding the crontab event to the root crontab (step 12), not www-data. This is where I had an &#8220;AHA&#8221; moment. so; I would do the following:

sudo crontab -u root -e

then at the bottom of the crontab file I would add the following:

*/1 * * * * sudo python /usr/lib/cgi-bin/monitor_5sensors.py

Or whatever number of sensors you are running.

then save the file (CTRL + X, Y, RETURN)

I have set the crontab to run every minute as I want a pretty high resolution on changes from minute to minute in my mash/boil/chilling and also want to track temp rise in my HLT (based on power in etc.)

then reboot

Again, this is what worked for me, it may not work for everyone but it certainly fixed some hangups that I was having along the way.

Again, thank you to day_trippr for the kick ass implementation.

Cheers!

I think the crontab portion alone may help aussies
 
Thanks for the feedback - and I suspect if running the cron job as root worked for you it'll work for @aussies. It does seem you were both stuck at the same point.

As for the W1 support thing, I ran into this last summer and covered it here, but you'd have to have read the whole thread to come across it.

The problem is we lose the ability to edit our own posts after 30 days, so I can't go back and edit the original post.

Anyway, thanks for the kind words and the likely help for aussies, and glad you find this useful. Have fun with it!

Cheers!

[edit] fwiw, you can use phpliteadmin to dump anything you want from the database into a CSV file...
 
Yeah, I glazed over the parts that talked about going to Jessie or whatever as I had done mine in Jessie and had to jump through hoops so I just did a wheezy install and as I read the entire thread I ignored anything to do with rpints and jessie (independently). Anyway, this thing is kick ass, really appreciate your work on it. Do you have any insight on how to export to ascii or xml? Either a segment of the DB or the whole thing. This would typically only run when I'm brewing so the DB file wouldn't be huge.
 
I was too slow with my edit: look at phpliteadmin. Very similar to phpmyadmin for MySQL, but for SQLite. It can definitely do what you want to do...

Cheers!
 
Awesome, the other thing I did with my original design was add two LEDS to show data being recorded, and a shutdown button. If there is any interest I can show you how I put those together
 
You are certainly welcome to post stuff like that here. While I may not see a good fit for my needs, others may well see a benefit...

Cheers!
 
Second thing I did and would recommend to anyone is adding the crontab event to the root crontab (step 12), not www-data. This is where I had an “AHA” moment. so; I would do the following:

sudo crontab -u root -e

then at the bottom of the crontab file I would add the following:

*/1 * * * * sudo python /usr/lib/cgi-bin/monitor_5sensors.py

Or whatever number of sensors you are running.

then save the file (CTRL + X, Y, RETURN)

That did the trick for me. Now everything is operating as it's supposed to. Thank you!
 
I dont know what really happend at my side. I had some struggle with owners of the scripts and /var/html I geuss?

Also purged apache and reinstalled it again

But since monday it's also operational :D ! Thank you very much.
Now rebuilding it to fit my europe needs :D no Fahrenheit ;) ;)
 
Hey I was just using this in my implementation and thought to myself "wouldn't it be great if you could plot a single item or have sub graphs with 2-5 individual graphs to plot the individual probes"... can that be done? I wish i was well versed enough to make a graph for each individual but i'm not that good.
 
ahahaha! If I had rolled this humble app out with each probe plotted separately, you know the very first reply would be "Hey - wouldn't it be neat if you could combine all of the probe channels into a single graph?" :D

The graphing script is an epic pita and was the very least fun part of cobbling this together.
I don't see the utility justifying me revisiting that nightmare ;) but if someone else wants to go there, vaya con Dios.

At one time I was considering using a whole different graphing mechanism that wouldn't depend on any web access, but this thing has suited my needs well, so I moved on to a bunch of other projects...

Cheers!
 
Stupid newbie question:

I have an Alamode board plugged my Raspberry Pi for the flow sensors. Where the instructions say to connect the sensors to header pin 1 & 7, do I just connect to the corresponding header pin on the alamode?
 
First of all this is has been a great topic and I have enjoyed reading through it. Now on to my question. I set up my raspberry pi with four sensors and have the monitor_4sensors.py script working well (I even added in section to email me if the temps go above a set temp. My problems is with the webgui4.py script, it seems to run well from a command line but if I try to run it from a browser it get a 500 internal server error with the following from the error.log:
cgi:error pid 1163 (8)Exec format error: exec of /usr/lib/cgi-bin/webgui4.py failed
cgi:error pid 1163 End of script output before headers: webgui4.py

I have done a lot of research as to why these errors are showing up and currently I am stumped. Apache is setup to run python scripts (I used a couple test scripts to make sure they would work), I have the correct file permissions and ownership but still can't get the script to work in the browser. If anyone has some input on this it would be appreciated.
 
Is there more to the error message than that?

About all I can think of is the script has some bs character hiding in it.
Perhaps a fresh copy of that file might be worth a shot?

Cheers!
 
Is there more to the error message than that?

About all I can think of is the script has some bs character hiding in it.
Perhaps a fresh copy of that file might be worth a shot?

Cheers!

Tried a fresh copy of the file and even checked it with notepad++ and it shows up as UTF-8 format. 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.
 
Back
Top