From 28bc51b07d3752db588e0fe5b579cda3f60b5937 Mon Sep 17 00:00:00 2001 From: Lasse Nielsen Date: Wed, 19 Aug 2015 19:10:41 +0200 Subject: [PATCH 01/62] not tested, but updated --- monitor.py | 69 +++++++++++++++++++----------------------------------- 1 file changed, 24 insertions(+), 45 deletions(-) diff --git a/monitor.py b/monitor.py index b20a80e..ebbfd70 100755 --- a/monitor.py +++ b/monitor.py @@ -1,45 +1,37 @@ #!/usr/bin/env python import sqlite3 - import os -import time import glob +import commands # global variables speriod=(15*60)-1 -dbname='/var/www/templog.db' +dbname='/var/www/tmplog/tempdb2.db' # store the temperature in the database -def log_temperature(temp): - +def log_temperature(iD, temp): conn=sqlite3.connect(dbname) curs=conn.cursor() - - curs.execute("INSERT INTO temps values(datetime('now'), (?))", (temp,)) - + insertDataQuery = "INSERT INTO sensor_data (sensor_id,value) VALUES('"+str(iD)+"','"+str(temp)+"');" + curs.execute(insertDataQuery); # commit the changes conn.commit() - conn.close() - # display the contents of the database -def display_data(): - +def display_data(iD): conn=sqlite3.connect(dbname) curs=conn.cursor() - - for row in curs.execute("SELECT * FROM temps"): + getSensorDataQuery = "SELECT * FROM sensor_data WHERE sensor_id =?" + for row in curs.execute(getSensorDataQuery, iD): print str(row[0])+" "+str(row[1]) conn.close() - - -# get temerature +# get temperature # returns None on error, or the temperature as a float def get_temp(devicefile): @@ -75,38 +67,25 @@ def main(): os.system('sudo modprobe w1-therm') # search for a device file that starts with 28 - devicelist = glob.glob('/sys/bus/w1/devices/28*') + deviceDir = '/sys/bus/w1/devices/' + devicelist = glob.glob(deviceDir + '28*') + if devicelist=='': + # no devices return None else: # append /w1slave to the device file - w1devicefile = devicelist[0] + '/w1_slave' - - -# while True: - - # get the temperature from the device file - temperature = get_temp(w1devicefile) - if temperature != None: - print "temperature="+str(temperature) - else: - # Sometimes reads fail on the first attempt - # so we need to retry - temperature = get_temp(w1devicefile) - print "temperature="+str(temperature) - - # Store the temperature in the database - log_temperature(temperature) - - # display the contents of the database -# display_data() - -# time.sleep(speriod) - + for w1devicefile in devicelist: + w1devicefile = w1devicefile + '/w1_slave' + # get the temperature from the device file + temperature = get_temp(w1devicefile) + while temperature == None: + temperature = get_temp(w1devicefile) + + deviceid = w1devicefile.split("/")[5] + print "Device ID ("+deviceid+") ; Temperature ("+str(temperature)+")" + # Store the temperature in the database + log_temperature(deviceid, temperature) if __name__=="__main__": main() - - - - From 759fee8b7310396eec6a2b9514f3a1d34748274a Mon Sep 17 00:00:00 2001 From: Lasse Nielsen Date: Wed, 19 Aug 2015 19:11:09 +0200 Subject: [PATCH 02/62] dummy data, new database, new test db and ignore file --- .gitignore | 1 + createDatabase.sql | 6 ++++++ dummyData.sql | 37 +++++++++++++++++++++++++++++++++++++ tempdb2.db | Bin 0 -> 4096 bytes 4 files changed, 44 insertions(+) create mode 100644 .gitignore create mode 100644 createDatabase.sql create mode 100644 dummyData.sql create mode 100644 tempdb2.db diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1377554 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.swp diff --git a/createDatabase.sql b/createDatabase.sql new file mode 100644 index 0000000..3119da3 --- /dev/null +++ b/createDatabase.sql @@ -0,0 +1,6 @@ +CREATE TABLE sensor_data( id integer primary key autoincrement not null + , timestamp datetime default current_timestamp not null + , sensor_id integer not null + , value real not null); +CREATE TABLE sensors( sensor_id integer primary key + , sensor_name text not null); \ No newline at end of file diff --git a/dummyData.sql b/dummyData.sql new file mode 100644 index 0000000..c3c9911 --- /dev/null +++ b/dummyData.sql @@ -0,0 +1,37 @@ + +INSERT INTO sensors (sensor_id, sensor_name) VALUES(1, "sensor1"); +INSERT INTO sensors (sensor_id, sensor_name) VALUES(2, "sensor2"); +INSERT INTO sensors (sensor_id, sensor_name) VALUES(3, "sensor3"); +INSERT INTO sensors (sensor_id, sensor_name) VALUES(4, "sensor4"); +INSERT INTO sensors (sensor_id, sensor_name) VALUES(5, "sensor5"); + +INSERT INTO sensor_data (sensor_id,value) VALUES (1,1); +INSERT INTO sensor_data (sensor_id,value) VALUES (1,10); +INSERT INTO sensor_data (sensor_id,value) VALUES (1,20); +INSERT INTO sensor_data (sensor_id,value) VALUES (1,15); +INSERT INTO sensor_data (sensor_id,value) VALUES (1,20); +INSERT INTO sensor_data (sensor_id,value) VALUES (1,25); +INSERT INTO sensor_data (sensor_id,value) VALUES (2,1); +INSERT INTO sensor_data (sensor_id,value) VALUES (2,10); +INSERT INTO sensor_data (sensor_id,value) VALUES (2,20); +INSERT INTO sensor_data (sensor_id,value) VALUES (2,15); +INSERT INTO sensor_data (sensor_id,value) VALUES (2,20); +INSERT INTO sensor_data (sensor_id,value) VALUES (2,25); +INSERT INTO sensor_data (sensor_id,value) VALUES (3,1); +INSERT INTO sensor_data (sensor_id,value) VALUES (3,10); +INSERT INTO sensor_data (sensor_id,value) VALUES (3,20); +INSERT INTO sensor_data (sensor_id,value) VALUES (3,15); +INSERT INTO sensor_data (sensor_id,value) VALUES (3,20); +INSERT INTO sensor_data (sensor_id,value) VALUES (3,25); +INSERT INTO sensor_data (sensor_id,value) VALUES (4,1); +INSERT INTO sensor_data (sensor_id,value) VALUES (4,10); +INSERT INTO sensor_data (sensor_id,value) VALUES (4,20); +INSERT INTO sensor_data (sensor_id,value) VALUES (4,15); +INSERT INTO sensor_data (sensor_id,value) VALUES (4,20); +INSERT INTO sensor_data (sensor_id,value) VALUES (4,25); +INSERT INTO sensor_data (sensor_id,value) VALUES (5,1); +INSERT INTO sensor_data (sensor_id,value) VALUES (5,10); +INSERT INTO sensor_data (sensor_id,value) VALUES (5,20); +INSERT INTO sensor_data (sensor_id,value) VALUES (5,15); +INSERT INTO sensor_data (sensor_id,value) VALUES (5,20); +INSERT INTO sensor_data (sensor_id,value) VALUES (5,25); \ No newline at end of file diff --git a/tempdb2.db b/tempdb2.db new file mode 100644 index 0000000000000000000000000000000000000000..e07cfdb12872512d6a31f0dd37271b9fc73b28d4 GIT binary patch literal 4096 zcmeH}zi-n(6vyvJ(vWM5DHzhbKsm^gs)^Jjgdd$KkO8R@zq&9*Cb=Sm?XB&@pK~|>`}hPX?vh!#0K+|i-lJ{lVmp8ibf$4Clg+}88(Q}q z5eP46`9a?$uHLS#uGjeb>Xo$`@88V#gSy@1eY3q#+!sFI^ljJjclblGLk4Wz7Y3=G z<%%8%#iNjWEjikbvv?CtWtNuU-JX^$M}C6!Ky0;z*AT(v6i;fKgn9LVg3MfeQiZ8Z zE(f2M#_Fp#tRt=i7&zAjCdRhk}{~~YOa@zg(z_~9hXY?l2*<1i` z0p7(Q@GJZrKgM-@4d?L;`i?%K*XRZ6Ac3xCzIE zozyauWwp#;Ov_A0wT#et#iC>;SVotIDLbKMCOfWW1~awHWXH6O(4&e)$;50?ot7va^=(p0bjYM>9Wv-49WrT3hsgYtLQx9U`G@!$ zkXLMR2jUL=-yJX@&cU%iqMSPaN&F7rA9xRc!5?K9Tik)T1OHG5ND_l=?@(7sVi=zz Pco Date: Wed, 19 Aug 2015 19:38:41 +0200 Subject: [PATCH 03/62] database edit --- webgui.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/webgui.py b/webgui.py index a139980..0761cb2 100755 --- a/webgui.py +++ b/webgui.py @@ -8,7 +8,7 @@ # global variables speriod=(15*60)-1 -dbname='/var/www/templog.db' +dbname='/var/www/tmplog/tempdb2.db' @@ -16,8 +16,6 @@ def printHTTPheader(): print "Content-type: text/html\n\n" - - # print the HTML head section # arguments are the page title and the table for the chart def printHTMLHead(title, table): @@ -25,7 +23,7 @@ def printHTMLHead(title, table): print " " print title print " " - + print_graph_script(table) print "" @@ -40,10 +38,9 @@ def get_data(interval): curs=conn.cursor() if interval == None: - curs.execute("SELECT * FROM temps") + curs.execute("SELECT * FROM sensor_data") else: -# curs.execute("SELECT * FROM temps WHERE timestamp>datetime('now','-%s hours')" % interval) - curs.execute("SELECT * FROM temps WHERE timestamp>datetime('2013-09-19 21:30:02','-%s hours') AND timestamp<=datetime('2013-09-19 21:31:02')" % interval) + curs.execute("SELECT * FROM sensor_data WHERE timestamp>datetime('now','-%s hours')" % interval) rows=curs.fetchall() From 88525630d9687dd27cf4c70863c43b795339d751 Mon Sep 17 00:00:00 2001 From: Lasse Nielsen Date: Wed, 19 Aug 2015 19:47:32 +0200 Subject: [PATCH 04/62] updated install script, + 1 sql in webgui --- install.sh | 22 ++++++++++++++++++++++ webgui.py | 3 --- 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 install.sh diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..7aade00 --- /dev/null +++ b/install.sh @@ -0,0 +1,22 @@ +!#/usr/bin/env bash + +sudo apt-get update +sudo apt-get intsall apache2 +sudo apt-get install sqlite3 -y +sudo mkdir /var/www/tmplog +sudo a2enmod mpm_prefork cgi + +#--Add:/etc/apache2/sites-enabled/000-default +# +# AddHandler cgi-script .py +# DocumentRoot /var/www/tmplog + +sudo cp tempdb2.db /var/www/tmplog +sudo chown www-data:www-data /var/www/tmplog/tempdb2.db +git clone https://github.com/poohzrn/rpi_temp_logger +sudo ln -s ~/rpi_temp_logger/monitor.py /usr/lib/cgi-bin/ +sudo chown www-data:www-data /usr/lib/cgi-bin/monitor.py +sudo ln -s ~/rpi_temp_logger/webgui.py /var/www/tmplog/index.py diff --git a/webgui.py b/webgui.py index 0761cb2..f322499 100755 --- a/webgui.py +++ b/webgui.py @@ -153,9 +153,6 @@ def show_stats(option): conn.close() - - - def print_time_selector(option): print """
From 291b4624c12a3e6cb43c8c1f0f14710effef42c4 Mon Sep 17 00:00:00 2001 From: Lasse Nielsen Date: Sat, 22 Aug 2015 09:40:08 +0200 Subject: [PATCH 05/62] reading --- install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/install.sh b/install.sh index 7aade00..05df8eb 100644 --- a/install.sh +++ b/install.sh @@ -20,3 +20,4 @@ git clone https://github.com/poohzrn/rpi_temp_logger sudo ln -s ~/rpi_temp_logger/monitor.py /usr/lib/cgi-bin/ sudo chown www-data:www-data /usr/lib/cgi-bin/monitor.py sudo ln -s ~/rpi_temp_logger/webgui.py /var/www/tmplog/index.py +#/boot/config.txt -> dtoverlay=w1-gpio From bb382f6c33978c0cd48d6eb6898bbd7522408253 Mon Sep 17 00:00:00 2001 From: pi Date: Sat, 22 Aug 2015 08:38:47 +0000 Subject: [PATCH 06/62] updated to new database --- monitor.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/monitor.py b/monitor.py index ebbfd70..401ea77 100755 --- a/monitor.py +++ b/monitor.py @@ -26,8 +26,8 @@ def display_data(iD): conn=sqlite3.connect(dbname) curs=conn.cursor() getSensorDataQuery = "SELECT * FROM sensor_data WHERE sensor_id =?" - for row in curs.execute(getSensorDataQuery, iD): - print str(row[0])+" "+str(row[1]) + for row in curs.execute(getSensorDataQuery, [iD]): + print str(row[1])+" "+str(row[3]) conn.close() @@ -56,8 +56,6 @@ def get_temp(devicefile): print "There was an error." return None - - # main function # This is where the program starts def main(): @@ -83,7 +81,6 @@ def main(): temperature = get_temp(w1devicefile) deviceid = w1devicefile.split("/")[5] - print "Device ID ("+deviceid+") ; Temperature ("+str(temperature)+")" # Store the temperature in the database log_temperature(deviceid, temperature) From 8a57ee94817065dc2d4399a86c5ed2dbfeb9f895 Mon Sep 17 00:00:00 2001 From: pi Date: Sat, 22 Aug 2015 08:45:08 +0000 Subject: [PATCH 07/62] Dropper sensor tabellen for nu --- createDatabase.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/createDatabase.sql b/createDatabase.sql index 3119da3..042716f 100644 --- a/createDatabase.sql +++ b/createDatabase.sql @@ -2,5 +2,7 @@ CREATE TABLE sensor_data( id integer primary key autoincrement not nul , timestamp datetime default current_timestamp not null , sensor_id integer not null , value real not null); +/* CREATE TABLE sensors( sensor_id integer primary key - , sensor_name text not null); \ No newline at end of file + , sensor_name text not null); +*/ From 568d6903ae1ef00e360dc71aa3e20aa7e634c5db Mon Sep 17 00:00:00 2001 From: pi Date: Sat, 22 Aug 2015 08:52:50 +0000 Subject: [PATCH 08/62] refactor option -> interval --- webgui.py | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/webgui.py b/webgui.py index f322499..5219557 100755 --- a/webgui.py +++ b/webgui.py @@ -33,7 +33,6 @@ def printHTMLHead(title, table): # if an interval is passed, # return a list of records from the database def get_data(interval): - conn=sqlite3.connect(dbname) curs=conn.cursor() @@ -43,12 +42,9 @@ def get_data(interval): curs.execute("SELECT * FROM sensor_data WHERE timestamp>datetime('now','-%s hours')" % interval) rows=curs.fetchall() - conn.close() - return rows - # convert rows from database into a javascript table def create_table(rows): chart_table="" @@ -202,7 +198,7 @@ def validate_input(option_str): #return the option passed to the script -def get_option(): +def getTimeInterval(): form=cgi.FieldStorage() if "timeinterval" in form: option = form["timeinterval"].value @@ -220,13 +216,13 @@ def main(): cgitb.enable() # get options that may have been passed to this script - option=get_option() + interval=getTimeInterval() - if option is None: - option = str(24) + if not interval: + interval= str(24) #24 hour std interval # get data from the database - records=get_data(option) + records=get_data(interval) # print the HTTP header printHTTPheader() @@ -246,11 +242,11 @@ def main(): # print the page body print "" - print "

Raspberry Pi Temperature Logger

" + print "

Raspberry Temperature Logger

" print "
" - print_time_selector(option) + print_time_selector(interval) show_graph() - show_stats(option) + show_stats(interval) print "" print "" @@ -258,7 +254,3 @@ def main(): if __name__=="__main__": main() - - - - From c060c186a8c47f746db283ebe78ba056b9974cb8 Mon Sep 17 00:00:00 2001 From: pi Date: Sat, 22 Aug 2015 09:16:35 +0000 Subject: [PATCH 09/62] updated rows --- webgui.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/webgui.py b/webgui.py index 5219557..b0fcab5 100755 --- a/webgui.py +++ b/webgui.py @@ -96,35 +96,29 @@ def show_graph(): print '
' - # connect to the db and show some stats # argument option is the number of hours -def show_stats(option): +def show_stats(interval): conn=sqlite3.connect(dbname) curs=conn.cursor() - if option is None: - option = str(24) + if not interval: + interval = str(24) -# curs.execute("SELECT timestamp,max(temp) FROM temps WHERE timestamp>datetime('now','-%s hour') AND timestamp<=datetime('now')" % option) - curs.execute("SELECT timestamp,max(temp) FROM temps WHERE timestamp>datetime('2013-09-19 21:30:02','-%s hour') AND timestamp<=datetime('2013-09-19 21:31:02')" % option) + curs.execute("SELECT timestamp,max(value) FROM sensor_data WHERE timestamp>datetime('now','-%s hour') AND timestamp<=datetime('now')" % interval) rowmax=curs.fetchone() rowstrmax="{0}   {1}C".format(str(rowmax[0]),str(rowmax[1])) -# curs.execute("SELECT timestamp,min(temp) FROM temps WHERE timestamp>datetime('now','-%s hour') AND timestamp<=datetime('now')" % option) - curs.execute("SELECT timestamp,min(temp) FROM temps WHERE timestamp>datetime('2013-09-19 21:30:02','-%s hour') AND timestamp<=datetime('2013-09-19 21:31:02')" % option) + curs.execute("SELECT timestamp,min(value) FROM sensor_data WHERE timestamp>datetime('2013-09-19 21:30:02','-%s hour') AND timestamp<=datetime('2013-09-19 21:31:02')" % interval) rowmin=curs.fetchone() rowstrmin="{0}   {1}C".format(str(rowmin[0]),str(rowmin[1])) -# curs.execute("SELECT avg(temp) FROM temps WHERE timestamp>datetime('now','-%s hour') AND timestamp<=datetime('now')" % option) - curs.execute("SELECT avg(temp) FROM temps WHERE timestamp>datetime('2013-09-19 21:30:02','-%s hour') AND timestamp<=datetime('2013-09-19 21:31:02')" % option) + curs.execute("SELECT avg(value) FROM sensor_data WHERE timestamp>datetime('now','-%s hour') AND timestamp<=datetime('now')" % interval) rowavg=curs.fetchone() print "
" - - print "

Minumum temperature 

" print rowstrmin print "

Maximum temperature

" @@ -138,8 +132,7 @@ def show_stats(option): print "" print "" -# rows=curs.execute("SELECT * FROM temps WHERE timestamp>datetime('new','-1 hour') AND timestamp<=datetime('new')") - rows=curs.execute("SELECT * FROM temps WHERE timestamp>datetime('2013-09-19 21:30:02','-1 hour') AND timestamp<=datetime('2013-09-19 21:31:02')") + rows=curs.execute("SELECT * FROM sensor_data WHERE timestamp>datetime('new','-1 hour') AND timestamp<=datetime('new')") for row in rows: rowstr="".format(str(row[0]),str(row[1])) print rowstr @@ -242,7 +235,7 @@ def main(): # print the page body print "" - print "

Raspberry Temperature Logger

" + print "

Raspberry Pi Temperature Logger

" print "
" print_time_selector(interval) show_graph() From 941885672928f7f456078e510265ce989c2f86a8 Mon Sep 17 00:00:00 2001 From: pi Date: Sat, 22 Aug 2015 09:18:06 +0000 Subject: [PATCH 10/62] u --- monitor.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/monitor.py b/monitor.py index 401ea77..89701cc 100755 --- a/monitor.py +++ b/monitor.py @@ -9,8 +9,6 @@ speriod=(15*60)-1 dbname='/var/www/tmplog/tempdb2.db' - - # store the temperature in the database def log_temperature(iD, temp): conn=sqlite3.connect(dbname) From 12592293d20f5a7f82f0bf6a83222bf04c5c003e Mon Sep 17 00:00:00 2001 From: pi Date: Sat, 22 Aug 2015 11:53:40 +0000 Subject: [PATCH 11/62] update --- createDatabase.sql | 18 ++++++++++-------- monitor.py | 12 ++++++++---- webgui.py | 17 +++++------------ 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/createDatabase.sql b/createDatabase.sql index 042716f..2fef2c4 100644 --- a/createDatabase.sql +++ b/createDatabase.sql @@ -1,8 +1,10 @@ -CREATE TABLE sensor_data( id integer primary key autoincrement not null - , timestamp datetime default current_timestamp not null - , sensor_id integer not null - , value real not null); -/* -CREATE TABLE sensors( sensor_id integer primary key - , sensor_name text not null); -*/ +CREATE TABLE sensor_data ( + sensor_id TEXT NOT NULL, + timestamp datetime NOT NULL DEFAULT current_timestamp, + value real NOT NULL +); +CREATE TABLE sensor ( + sensor_id TEXT NOT NULL UNIQUE, + sensor_name TEXT NOT NULL DEFAULT 'SensorName', + PRIMARY KEY(sensor_id) +); diff --git a/monitor.py b/monitor.py index 89701cc..f28b9e4 100755 --- a/monitor.py +++ b/monitor.py @@ -13,6 +13,8 @@ def log_temperature(iD, temp): conn=sqlite3.connect(dbname) curs=conn.cursor() + insertDeviceQuery = "INSERT OR IGNORE INTO sensor (sensor_id) VALUES('"+str(iD)+"');" + curs.execute(insertDeviceQuery); insertDataQuery = "INSERT INTO sensor_data (sensor_id,value) VALUES('"+str(iD)+"','"+str(temp)+"');" curs.execute(insertDataQuery); # commit the changes @@ -23,10 +25,12 @@ def log_temperature(iD, temp): def display_data(iD): conn=sqlite3.connect(dbname) curs=conn.cursor() + getDevices = "SELECT * FROM sensor" getSensorDataQuery = "SELECT * FROM sensor_data WHERE sensor_id =?" for row in curs.execute(getSensorDataQuery, [iD]): - print str(row[1])+" "+str(row[3]) - + print str(row[0])+" "+str(row[1])+" "+str(row[2]) + for row in curs.execute(getDevices): + print str(row[0])+" "+str(row[1]) conn.close() # get temperature @@ -65,7 +69,7 @@ def main(): # search for a device file that starts with 28 deviceDir = '/sys/bus/w1/devices/' devicelist = glob.glob(deviceDir + '28*') - + print devicelist if devicelist=='': # no devices return None @@ -81,6 +85,6 @@ def main(): deviceid = w1devicefile.split("/")[5] # Store the temperature in the database log_temperature(deviceid, temperature) - + #display_data(deviceid) if __name__=="__main__": main() diff --git a/webgui.py b/webgui.py index b0fcab5..aac78e4 100755 --- a/webgui.py +++ b/webgui.py @@ -48,15 +48,14 @@ def get_data(interval): # convert rows from database into a javascript table def create_table(rows): chart_table="" - for row in rows[:-1]: - rowstr="['{0}', {1}],\n".format(str(row[0]),str(row[1])) + rowstr="['{0}', {1}],\n".format(str(row[1]),str(row[2])) chart_table+=rowstr row=rows[-1] - rowstr="['{0}', {1}]\n".format(str(row[0]),str(row[1])) + rowstr="['{0}', {1}]\n".format(str(row[1]),str(row[2])) chart_table+=rowstr - + #print chart_table return chart_table @@ -87,9 +86,6 @@ def print_graph_script(table): print chart_code % (table) - - - # print the div that contains the graph def show_graph(): print "

Temperature Chart

" @@ -99,7 +95,6 @@ def show_graph(): # connect to the db and show some stats # argument option is the number of hours def show_stats(interval): - conn=sqlite3.connect(dbname) curs=conn.cursor() @@ -136,6 +131,7 @@ def show_stats(interval): for row in rows: rowstr="
".format(str(row[0]),str(row[1])) print rowstr + print "hest" print "
Date/TimeTemperature
{0}  {1}C
{0}  {1}C
" print "
" @@ -144,7 +140,7 @@ def show_stats(interval): def print_time_selector(option): - print """ + print """ Show the temperature logs for """ - if option is not None: + if option == "1": + print "" + else: + print "" if option == "6": print "" else: @@ -198,7 +200,8 @@ def print_time_selector(option): print "" else: - print """ + print """ + """ @@ -243,15 +246,12 @@ def main(): interval= str(24) #24 hour std interval # get data from the database - records=get_data(interval) + table=createMultiTable(interval) # print the HTTP header printHTTPheader() - if len(records) != 0: - # convert the data into a table - table=createMultiTable(interval) - else: + if len(table) is 0: print "No data found" return From e7bf4f91d82d9b24a1dcf5b0ccb0efe5a909d1d1 Mon Sep 17 00:00:00 2001 From: pi Date: Sun, 23 Aug 2015 14:30:53 +0000 Subject: [PATCH 19/62] last hour added --- webgui.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/webgui.py b/webgui.py index 5f07571..a018c22 100755 --- a/webgui.py +++ b/webgui.py @@ -162,11 +162,10 @@ def show_stats(interval): print "" print "" - rows=curs.execute("SELECT * FROM sensor_data WHERE timestamp>datetime('new','-1 hour') AND timestamp<=datetime('new')") + rows=curs.execute("SELECT timestamp,value FROM sensor_data WHERE timestamp>datetime('now','-1 hour') AND timestamp<=datetime('now')") for row in rows: rowstr="".format(str(row[0]),str(row[1])) print rowstr - print "hest" print "
Date/TimeTemperature
{0}  {1}C
" print "
" From a46ff08d7024e0e04ec7447ad30322fa3a8431c6 Mon Sep 17 00:00:00 2001 From: pi Date: Sun, 23 Aug 2015 14:40:18 +0000 Subject: [PATCH 20/62] added device to last hour --- webgui.py | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/webgui.py b/webgui.py index a018c22..505b42d 100755 --- a/webgui.py +++ b/webgui.py @@ -5,13 +5,10 @@ import cgi import cgitb - # global variables speriod=(15*60)-1 dbname='/var/www/tmplog/tempdb2.db' - - # print the HTTP header def printHTTPheader(): print "Content-type: text/html\n\n" @@ -23,9 +20,7 @@ def printHTMLHead(title, table): print " " print title print " " - print_graph_script(table) - print "" #Get the number of sensors @@ -75,7 +70,9 @@ def getBaseTable(sensorCount): baseTable += rowstr baseTable+="'Sensor{0}'],\n".format(str(sensor+2)) return baseTable - +# TODO - Make this thing dynamic. +# To more sensors added, add them in in line 83+84+85 +# convert rows from database into a javascript table def createMultiTable(interval): sensorCount = getSensorCount() basetable=getBaseTable(sensorCount) @@ -85,16 +82,8 @@ def createMultiTable(interval): for d1, d2 in zip(devicedata[0],devicedata[1]): basetable+="['{0}',{1},{2}],\n".format(str(d1[0]),str(d1[1]),str(d2[1])) - basetable+="['{0}',{1},{2}]\n".format(str(d1[0]),str(d1[1]),str(d2[1])) return basetable -# convert rows from database into a javascript table -def create_table(rows): - chart_table="" - for row in rows[:-1]: - rowstr="['{0}', {1}],\n".format(str(row[1]),str(row[2])) - chart_table+=rowstr - return chart_table # print the javascript to generate the chart # pass the table generated from the database info @@ -124,8 +113,7 @@ def print_graph_script(table): # print the div that contains the graph def show_graph(): print "

Temperature Chart

" - print '
' - + print '
' # connect to the db and show some stats # argument option is the number of hours @@ -160,16 +148,14 @@ def show_stats(interval): print "

In the last hour:

" print "" - print "" + print "" - rows=curs.execute("SELECT timestamp,value FROM sensor_data WHERE timestamp>datetime('now','-1 hour') AND timestamp<=datetime('now')") + rows=curs.execute("SELECT timestamp,value,sensor_id FROM sensor_data WHERE timestamp>datetime('now','-1 hour') AND timestamp<=datetime('now')") for row in rows: - rowstr="".format(str(row[0]),str(row[1])) + rowstr="".format(str(row[0]),str(row[1]),str(row[2])) print rowstr print "
Date/TimeTemperature
Date/TimeTemperatureDevice
{0}  {1}C
{0}  {1}C{2}
" - print "
" - conn.close() def print_time_selector(option): @@ -235,25 +221,18 @@ def getTimeInterval(): # main function # This is where the program starts def main(): - cgitb.enable() - # get options that may have been passed to this script interval=getTimeInterval() - if not interval: interval= str(24) #24 hour std interval - # get data from the database table=createMultiTable(interval) - # print the HTTP header printHTTPheader() - if len(table) is 0: print "No data found" return - # start printing the page print "" # print the head section including the table @@ -270,7 +249,6 @@ def main(): show_stats(interval) print "" print "" - sys.stdout.flush() if __name__=="__main__": From 836d4e336835a3521bcf7acefd893816a970ac8a Mon Sep 17 00:00:00 2001 From: pi Date: Sun, 23 Aug 2015 14:41:53 +0000 Subject: [PATCH 21/62] refac --- webgui.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/webgui.py b/webgui.py index 505b42d..763d424 100755 --- a/webgui.py +++ b/webgui.py @@ -164,7 +164,6 @@ def print_time_selector(option): @@ -202,7 +206,7 @@ def validate_input(option_str): # check that the option string represents a number if option_str.isalnum(): # check that the option is within a specific range - if int(option_str) > 0 and int(option_str) <= 24: + if int(option_str) > 0 and int(option_str) <= 168: return option_str else: return None From 146f90f59cc662e69babdd5967118874135c7e20 Mon Sep 17 00:00:00 2001 From: pi Date: Sun, 23 Aug 2015 15:34:45 +0000 Subject: [PATCH 26/62] install notes --- README | 15 +++++++++++++++ install.sh | 13 +------------ 2 files changed, 16 insertions(+), 12 deletions(-) mode change 100644 => 100755 install.sh diff --git a/README b/README index 5b59f85..967443a 100644 --- a/README +++ b/README @@ -1,3 +1,18 @@ +Installation: +git clone https://github.com/poohzrn/rpi_temp_logger ~/rpi_temp_logger +chmod +x install.sh +./install.sh + +Add the following to the file : /etc/apache2/sites-enabled/000-default + + AddHandler cgi-script .py + DocumentRoot /var/www/tmplog +Add the following to the file /boot/config.txt +dtoverlay=w1-gpio + Raspberry Pi Temperature Logger =============================== diff --git a/install.sh b/install.sh old mode 100644 new mode 100755 index 155069a..9638419 --- a/install.sh +++ b/install.sh @@ -4,19 +4,8 @@ sudo apt-get intsall apache2 sudo apt-get install sqlite3 -y sudo mkdir /var/www/tmplog sudo a2enmod mpm_prefork cgi - -#--Add:/etc/apache2/sites-enabled/000-default -# -# AddHandler cgi-script .py -# DocumentRoot /var/www/tmplog - -sudo cp tempdb2.db /var/www/tmplog +sudo cp ~/rpi_temp_logger/tempdb2.db /var/www/tmplog sudo chown www-data:www-data /var/www/tmplog/tempdb2.db -git clone https://github.com/poohzrn/rpi_temp_logger sudo ln -s ~/rpi_temp_logger/monitor.py /usr/lib/cgi-bin/ sudo chown www-data:www-data /usr/lib/cgi-bin/monitor.py sudo ln -s ~/rpi_temp_logger/webgui.py /var/www/tmplog/index.py -#/boot/config.txt -> dtoverlay=w1-gpio From b3351c11fec171efd07df6089575c93c6f133c35 Mon Sep 17 00:00:00 2001 From: pi Date: Sun, 23 Aug 2015 15:36:51 +0000 Subject: [PATCH 27/62] installation --- README | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README b/README index 967443a..69abb81 100644 --- a/README +++ b/README @@ -1,16 +1,18 @@ Installation: git clone https://github.com/poohzrn/rpi_temp_logger ~/rpi_temp_logger +cd ~/rpi_temp_logger chmod +x install.sh ./install.sh -Add the following to the file : /etc/apache2/sites-enabled/000-default +Add the following to the file: /etc/apache2/sites-enabled/000-default AddHandler cgi-script .py DocumentRoot /var/www/tmplog -Add the following to the file /boot/config.txt + +Add the following to the file: /boot/config.txt dtoverlay=w1-gpio Raspberry Pi Temperature Logger From 9af632b20675bcc56dd83305cc25c0922007bea7 Mon Sep 17 00:00:00 2001 From: pi Date: Sun, 23 Aug 2015 15:39:44 +0000 Subject: [PATCH 28/62] cronjob --- README | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README b/README index 69abb81..298f463 100644 --- a/README +++ b/README @@ -14,6 +14,8 @@ Add the following to the file: /etc/apache2/sites-enabled/000-default Add the following to the file: /boot/config.txt dtoverlay=w1-gpio +Cron job: +* * * * * /usr/lib/cgi-bin/monitor.py Raspberry Pi Temperature Logger =============================== From 1940af60b7dcc6e8d96df62538cdb8d68873151e Mon Sep 17 00:00:00 2001 From: Lasse Date: Mon, 24 Aug 2015 08:53:45 +0000 Subject: [PATCH 29/62] empty database bug removed --- webgui.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/webgui.py b/webgui.py index 7fa636c..845a7bf 100755 --- a/webgui.py +++ b/webgui.py @@ -231,12 +231,13 @@ def main(): if not interval: interval= str(24) #24 hour std interval # get data from the database - table=createMultiTable(interval) - # print the HTTP header printHTTPheader() - if len(table) is 0: + if getSensorCount() is 0: print "No data found" return + else: + table=createMultiTable(interval) + # print the HTTP header # start printing the page print "" # print the head section including the table From 2e3925623178ed2a214e12efaef2763613c4ac53 Mon Sep 17 00:00:00 2001 From: Lasse Date: Mon, 24 Aug 2015 13:10:39 +0200 Subject: [PATCH 30/62] Local time in database --- createDatabase.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/createDatabase.sql b/createDatabase.sql index 2fef2c4..f4d9bf9 100644 --- a/createDatabase.sql +++ b/createDatabase.sql @@ -1,6 +1,6 @@ CREATE TABLE sensor_data ( sensor_id TEXT NOT NULL, - timestamp datetime NOT NULL DEFAULT current_timestamp, + timestamp datetime NOT NULL DEFAULT (DATETIME(CURRENT_TIMESTAMP, 'LOCALTIME')), value real NOT NULL ); CREATE TABLE sensor ( From 68714ae7e0f1eae36d7b3ed65caf826187176e56 Mon Sep 17 00:00:00 2001 From: Lasse Date: Mon, 24 Aug 2015 14:31:13 +0200 Subject: [PATCH 31/62] SensorName instead of sensorname --- webgui.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/webgui.py b/webgui.py index 845a7bf..170bfd0 100755 --- a/webgui.py +++ b/webgui.py @@ -54,21 +54,23 @@ def getSensorData(deviceId, interval): def getSensorIds(): conn=sqlite3.connect(dbname) curs=conn.cursor() - sensorIdRow=curs.execute("select DISTINCT sensor.sensor_id from sensor;") + sensorIdRow=curs.execute("select DISTINCT sensor.sensor_id, sensor.sensor_name from sensor;") rows=curs.fetchall() conn.close() table =[] for device in rows: table.append(format(str(device[0]))) + table.append(format(str(device[1]))) return table #Creates the first item in data array based on #sensors def getBaseTable(sensorCount): baseTable = "['Time'," - for sensor in range(0,sensorCount-1): - rowstr="'Sensor{0}',".format(str(sensor+1)) + sensorids = getSensorIds() + for sensor in sensorids[:-1] + rowstr="'{0}',".format(str(sensor[1])) baseTable += rowstr - baseTable+="'Sensor{0}'],\n".format(str(sensor+2)) + baseTable+="'{0}'],\n".format(str(sensorids[-1][1])) return baseTable # TODO - Make this thing dynamic. # To more sensors added, add them in in line 83+84+85 From a647ff098b9b326040b9bcca5aec13d4753b860f Mon Sep 17 00:00:00 2001 From: poohzrn Date: Wed, 26 Aug 2015 16:02:03 +0200 Subject: [PATCH 32/62] Add sensorname to the table instead of static 'sensorName' --- webgui.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/webgui.py b/webgui.py index 170bfd0..1b0abfb 100755 --- a/webgui.py +++ b/webgui.py @@ -57,33 +57,36 @@ def getSensorIds(): sensorIdRow=curs.execute("select DISTINCT sensor.sensor_id, sensor.sensor_name from sensor;") rows=curs.fetchall() conn.close() - table =[] - for device in rows: - table.append(format(str(device[0]))) - table.append(format(str(device[1]))) - return table + devicedata =[] + for row in rows: + rowdata =[] + rowdata.append(str(row[0])) + rowdata.append(str(row[1])) + devicedata.append(rowdata) + return devicedata #Creates the first item in data array based on #sensors -def getBaseTable(sensorCount): +def getBaseTable(): baseTable = "['Time'," sensorids = getSensorIds() - for sensor in sensorids[:-1] + for sensor in sensorids[:-1]:#every sensor except last sensor rowstr="'{0}',".format(str(sensor[1])) baseTable += rowstr - baseTable+="'{0}'],\n".format(str(sensorids[-1][1])) + baseTable+="'{0}'],\n".format(str(sensorids[-1][1]))#last sensor (-1) #sensorname[1] return baseTable # TODO - Make this thing dynamic. # To more sensors added, add them in in line 83+84+85 # convert rows from database into a javascript table def createMultiTable(interval): sensorCount = getSensorCount() - basetable=getBaseTable(sensorCount) + basetable=getBaseTable() devicedata = [] for device in getSensorIds(): - devicedata.append(getSensorData(device,interval)) + devicedata.append(getSensorData(device[0],interval)) for d1, d2 in zip(devicedata[0],devicedata[1]): basetable+="['{0}',{1},{2}],\n".format(str(d1[0]),str(d1[1]),str(d2[1])) + basetable+="['{0}',{1},{2}]\n".format(str(d1[0]),str(d1[1]),str(d2[1])) return basetable From 95150ef2827e370685ceb1148d140176f2960b9a Mon Sep 17 00:00:00 2001 From: poohzrn Date: Wed, 26 Aug 2015 16:05:56 +0200 Subject: [PATCH 33/62] fix for actually post a request for a specific temperature interval --- webgui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webgui.py b/webgui.py index 1b0abfb..c38dbfd 100755 --- a/webgui.py +++ b/webgui.py @@ -166,7 +166,7 @@ def show_stats(interval): conn.close() def print_time_selector(option): - print """ + print """ Show the temperature logs for + print """ """ @@ -255,7 +221,7 @@ def main(): print "
" print_time_selector(interval) show_graph() - #show_stats(interval) + show_stats(interval) print "" print "" sys.stdout.flush() From e3eb0bb6f3e2098e5466dabf790623cb2a346b20 Mon Sep 17 00:00:00 2001 From: poohzrn Date: Thu, 10 Sep 2015 23:41:55 +0200 Subject: [PATCH 44/62] minor changes --- webgui.py | 1 - 1 file changed, 1 deletion(-) diff --git a/webgui.py b/webgui.py index f3d1f85..a4d5981 100755 --- a/webgui.py +++ b/webgui.py @@ -56,7 +56,6 @@ def createMultiTable(interval): dataTable+="'{0}',".format(sensorData[name].name) dataTable+="'{0}'],\n".format(sensorData[-1].name)#last sensor (-1) #sensorname[1] dataTable+="['{0}',{1},".format(sensorData[0].timestamp[:-3],sensorData[0].temperature) - counter = 1 for data in sensorData[1:-1]: if counter % sensorCount is 0: From 7aafa1eb4b0bb5b0b8c91c6460b97abe818b659a Mon Sep 17 00:00:00 2001 From: poohzrn Date: Fri, 11 Sep 2015 00:02:17 +0200 Subject: [PATCH 45/62] Update README --- README | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/README b/README index 298f463..e0961be 100644 --- a/README +++ b/README @@ -1,11 +1,11 @@ -Installation: +#Installation: git clone https://github.com/poohzrn/rpi_temp_logger ~/rpi_temp_logger cd ~/rpi_temp_logger chmod +x install.sh ./install.sh Add the following to the file: /etc/apache2/sites-enabled/000-default - Options +ExecCGI DirectoryIndex index.py @@ -13,14 +13,28 @@ Add the following to the file: /etc/apache2/sites-enabled/000-default DocumentRoot /var/www/tmplog Add the following to the file: /boot/config.txt + dtoverlay=w1-gpio Cron job: * * * * * /usr/lib/cgi-bin/monitor.py +sudo echo ' + + Options +ExecCGI + DirectoryIndex index.py + + AddHandler cgi-script .py + ServerAdmin webmaster@localhost + DocumentRoot /var/www/tmplog + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + ' >> /etc/apache2/sites-enabled/tmplog.conf + + + Raspberry Pi Temperature Logger =============================== -This repo contains code for a Raspberry Pi temperature logger which uses SQLite to store data read from a DS18B20 sensor. You can see more details here: +This repo contains code for a Raspberry Pi temperature logger which uses SQLite to store data read from a DS18B20 sensor. +You can see more details here: http://raspberrywebserver.com/cgiscripting/rpi-temperature-logger/building-an-sqlite-temperature-logger.html - -In webgui.py, there are several lines that contain hardcoded dates so that you can use the script with the sample database provided. There is an equivalent version of each of these lines that uses 'now' instead of a hardcoded timestamp. If you want to view data you've collected yourself, you should uncomment the lines that use 'now', and comment out the lines that have a hardocded date. See webgui.py, lines 45, 117, 122, 127 and 148. From 75156877993b7595d922a8aebf69ae136d68fd59 Mon Sep 17 00:00:00 2001 From: poohzrn Date: Fri, 11 Sep 2015 18:16:53 +0200 Subject: [PATCH 46/62] jkkkjjjk --- webgui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webgui.py b/webgui.py index a4d5981..71ada5a 100755 --- a/webgui.py +++ b/webgui.py @@ -94,7 +94,7 @@ def print_graph_script(table): # print the div that contains the graph def show_graph(): print "

Temperature Chart

" - print '
' + print '
' # connect to the db and show some stats # argument option is the number of hours From fd266b5fe6adf916f286f4390879034884b46ebd Mon Sep 17 00:00:00 2001 From: poohzrn Date: Sun, 13 Sep 2015 20:10:12 +0200 Subject: [PATCH 47/62] Update README --- README | 1 + 1 file changed, 1 insertion(+) diff --git a/README b/README index e0961be..a0632a5 100644 --- a/README +++ b/README @@ -1,3 +1,4 @@ +![Screenshot](http://i.imgur.com/DJL9V2J.png) #Installation: git clone https://github.com/poohzrn/rpi_temp_logger ~/rpi_temp_logger cd ~/rpi_temp_logger From 0ea0a8085af11d190ebf463e0836a4fa7ee9fb7c Mon Sep 17 00:00:00 2001 From: poohzrn Date: Sun, 13 Sep 2015 20:10:44 +0200 Subject: [PATCH 48/62] Update README --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index a0632a5..97e8b37 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -![Screenshot](http://i.imgur.com/DJL9V2J.png) +![Screenshot](http://i.imgur.com/DJL9V2J.png "screenshot") #Installation: git clone https://github.com/poohzrn/rpi_temp_logger ~/rpi_temp_logger cd ~/rpi_temp_logger From f661d57f714c53d0e8d9c49cc6793b85f59cb08b Mon Sep 17 00:00:00 2001 From: poohzrn Date: Sun, 13 Sep 2015 20:12:30 +0200 Subject: [PATCH 49/62] Update README --- README | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README b/README index 97e8b37..3ad638d 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -![Screenshot](http://i.imgur.com/DJL9V2J.png "screenshot") + #Installation: git clone https://github.com/poohzrn/rpi_temp_logger ~/rpi_temp_logger cd ~/rpi_temp_logger @@ -30,7 +30,7 @@ sudo echo ' ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined ' >> /etc/apache2/sites-enabled/tmplog.conf - +[![Data representation](http://i.imgur.com/DJL9V2J.png )](#features) Raspberry Pi Temperature Logger From fff90fa48db34793675dd481e05f748ca6d2c7f5 Mon Sep 17 00:00:00 2001 From: poohzrn Date: Sun, 13 Sep 2015 20:14:27 +0200 Subject: [PATCH 50/62] Update README --- README | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README b/README index 3ad638d..7933f4b 100644 --- a/README +++ b/README @@ -1,5 +1,4 @@ - -#Installation: +##Installation: git clone https://github.com/poohzrn/rpi_temp_logger ~/rpi_temp_logger cd ~/rpi_temp_logger chmod +x install.sh @@ -30,7 +29,6 @@ sudo echo ' ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined ' >> /etc/apache2/sites-enabled/tmplog.conf -[![Data representation](http://i.imgur.com/DJL9V2J.png )](#features) Raspberry Pi Temperature Logger From dcd0b40d2076453eab90cdda5ca880d5fd100afc Mon Sep 17 00:00:00 2001 From: Lasse Nielsen Date: Thu, 17 Sep 2015 23:40:12 +0200 Subject: [PATCH 51/62] updated install script - creating a backup of a da base if it exits --- install.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/install.sh b/install.sh index 9638419..ffc7f04 100755 --- a/install.sh +++ b/install.sh @@ -1,11 +1,19 @@ !#/usr/bin/env bash +#Sudo access +sudo -v sudo apt-get update -sudo apt-get intsall apache2 +sudo apt-get intsall apache2 -y sudo apt-get install sqlite3 -y -sudo mkdir /var/www/tmplog sudo a2enmod mpm_prefork cgi -sudo cp ~/rpi_temp_logger/tempdb2.db /var/www/tmplog -sudo chown www-data:www-data /var/www/tmplog/tempdb2.db +sudo mkdir -p /var/www/tmplog +cat ~/rpi_temp_logger/createDatabase.sql | sqlite3 tempdb2.db + +if [ -e /var/www/tmplog/tempdb2.db ]; then + sudo mv /var/www/tmplog ~/tempdb2.bak +fi +sudo mv ~/rpi_temp_logger/tempdb2.db /var/www/tmplog sudo ln -s ~/rpi_temp_logger/monitor.py /usr/lib/cgi-bin/ -sudo chown www-data:www-data /usr/lib/cgi-bin/monitor.py sudo ln -s ~/rpi_temp_logger/webgui.py /var/www/tmplog/index.py + +sudo chown www-data:www-data /usr/lib/cgi-bin/monitor.py +sudo chown www-data:www-data /var/www/tmplog/tempdb2.db From 03507ebcff14f9d4219203eac8d789aa5b0e4235 Mon Sep 17 00:00:00 2001 From: Lasse Nielsen Date: Thu, 17 Sep 2015 23:42:55 +0200 Subject: [PATCH 52/62] Configuration for tmplog virtual host --- tmplog.conf | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tmplog.conf diff --git a/tmplog.conf b/tmplog.conf new file mode 100644 index 0000000..8c4bb5e --- /dev/null +++ b/tmplog.conf @@ -0,0 +1,11 @@ +NameVirtualHost *:80 + + + Options +ExecCGI + DirectoryIndex index.py + + AddHandler cgi-script + DocumentRoot /var/www/tmplog + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + From b1a14576d117a6757e217b693ca217151becb2e4 Mon Sep 17 00:00:00 2001 From: Lasse Nielsen Date: Thu, 17 Sep 2015 23:46:49 +0200 Subject: [PATCH 53/62] Add the vertual host --- install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/install.sh b/install.sh index ffc7f04..7147c8d 100755 --- a/install.sh +++ b/install.sh @@ -11,6 +11,7 @@ cat ~/rpi_temp_logger/createDatabase.sql | sqlite3 tempdb2.db if [ -e /var/www/tmplog/tempdb2.db ]; then sudo mv /var/www/tmplog ~/tempdb2.bak fi +sudo cp ~/rpi_temp_logger/tmplog.conf /etc/apache2/sites-enabled sudo mv ~/rpi_temp_logger/tempdb2.db /var/www/tmplog sudo ln -s ~/rpi_temp_logger/monitor.py /usr/lib/cgi-bin/ sudo ln -s ~/rpi_temp_logger/webgui.py /var/www/tmplog/index.py From 4008451533f9dc99cc44ced8c4b616e4a66408ce Mon Sep 17 00:00:00 2001 From: Lasse Nielsen Date: Thu, 17 Sep 2015 23:49:37 +0200 Subject: [PATCH 54/62] Readme --- README | 39 --------------------------------------- install.sh | 1 + 2 files changed, 1 insertion(+), 39 deletions(-) delete mode 100644 README diff --git a/README b/README deleted file mode 100644 index 7933f4b..0000000 --- a/README +++ /dev/null @@ -1,39 +0,0 @@ -##Installation: -git clone https://github.com/poohzrn/rpi_temp_logger ~/rpi_temp_logger -cd ~/rpi_temp_logger -chmod +x install.sh -./install.sh - -Add the following to the file: /etc/apache2/sites-enabled/000-default - - Options +ExecCGI - DirectoryIndex index.py - - AddHandler cgi-script .py - DocumentRoot /var/www/tmplog - -Add the following to the file: /boot/config.txt - -dtoverlay=w1-gpio -Cron job: -* * * * * /usr/lib/cgi-bin/monitor.py - -sudo echo ' - - Options +ExecCGI - DirectoryIndex index.py - - AddHandler cgi-script .py - ServerAdmin webmaster@localhost - DocumentRoot /var/www/tmplog - ErrorLog ${APACHE_LOG_DIR}/error.log - CustomLog ${APACHE_LOG_DIR}/access.log combined - ' >> /etc/apache2/sites-enabled/tmplog.conf - - -Raspberry Pi Temperature Logger -=============================== - -This repo contains code for a Raspberry Pi temperature logger which uses SQLite to store data read from a DS18B20 sensor. -You can see more details here: -http://raspberrywebserver.com/cgiscripting/rpi-temperature-logger/building-an-sqlite-temperature-logger.html diff --git a/install.sh b/install.sh index 7147c8d..9a64164 100755 --- a/install.sh +++ b/install.sh @@ -18,3 +18,4 @@ sudo ln -s ~/rpi_temp_logger/webgui.py /var/www/tmplog/index.py sudo chown www-data:www-data /usr/lib/cgi-bin/monitor.py sudo chown www-data:www-data /var/www/tmplog/tempdb2.db +sudo service apache2 restart From 7b90545344e0967f5fdff05651976f028ac0afed Mon Sep 17 00:00:00 2001 From: Lasse Nielsen Date: Fri, 18 Sep 2015 00:00:13 +0200 Subject: [PATCH 55/62] Added crontab and enable gpio --- install.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/install.sh b/install.sh index 9a64164..ffea49b 100755 --- a/install.sh +++ b/install.sh @@ -18,4 +18,11 @@ sudo ln -s ~/rpi_temp_logger/webgui.py /var/www/tmplog/index.py sudo chown www-data:www-data /usr/lib/cgi-bin/monitor.py sudo chown www-data:www-data /var/www/tmplog/tempdb2.db +#Add Crontab to get data from sensors +sudo -l > currentCron +sudo echo "* * * * * /usr/lib/cgi-bin/monitor.py" >> currentCron +sudo crontab currentCron && sudo rm currentCron +#enable GPIO +sudo echo "dtoverlay=w1-gpio" >> /boot/config.txt +#restart Apache sudo service apache2 restart From f24cfd4a0394bee53a3f2b6cce1ced0703d4d616 Mon Sep 17 00:00:00 2001 From: Lasse Nielsen Date: Fri, 18 Sep 2015 00:18:45 +0200 Subject: [PATCH 56/62] Update --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..fadd5dc --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +#Raspberry Pi Temperature Logger +This repo contains code for a Raspberry Pi temperature logger which uses SQLite to store data read from a DS18B20 sensor. +![Screenshot of temperature logger](http://i.imgur.com/nAFKJ4M.png) +##Installation: +***Warning ***: Your Raspberry Pi will reboot after installation to enable GPIO +```bash +cd && git clone https://github.com/poohzrn/rpi_temp_logger && cd ~/rpi_templogger && ./install.sh +``` From ce690cfdef45099162f533f5bc7c820130bc6df6 Mon Sep 17 00:00:00 2001 From: Lasse Nielsen Date: Fri, 18 Sep 2015 00:19:27 +0200 Subject: [PATCH 57/62] reboot to enable GPIO --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index ffea49b..ba377ad 100755 --- a/install.sh +++ b/install.sh @@ -24,5 +24,5 @@ sudo echo "* * * * * /usr/lib/cgi-bin/monitor.py" >> currentCron sudo crontab currentCron && sudo rm currentCron #enable GPIO sudo echo "dtoverlay=w1-gpio" >> /boot/config.txt -#restart Apache -sudo service apache2 restart +#restart to enable GPIO +sudo reboot now From 64948d22f98d46355264d3d427681d1d29f468a8 Mon Sep 17 00:00:00 2001 From: Lasse Nielsen Date: Fri, 18 Sep 2015 00:21:29 +0200 Subject: [PATCH 58/62] Syntax --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fadd5dc..8d87835 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This repo contains code for a Raspberry Pi temperature logger which uses SQLite to store data read from a DS18B20 sensor. ![Screenshot of temperature logger](http://i.imgur.com/nAFKJ4M.png) ##Installation: -***Warning ***: Your Raspberry Pi will reboot after installation to enable GPIO +**Warning:** Your Raspberry Pi will reboot after installation to enable GPIO ```bash cd && git clone https://github.com/poohzrn/rpi_temp_logger && cd ~/rpi_templogger && ./install.sh ``` From ae4a03a69cbbc7e0fa723592585f15d30f88db08 Mon Sep 17 00:00:00 2001 From: Lasse Nielsen Date: Fri, 18 Sep 2015 00:21:49 +0200 Subject: [PATCH 59/62] Syntax --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d87835..ed23551 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ #Raspberry Pi Temperature Logger This repo contains code for a Raspberry Pi temperature logger which uses SQLite to store data read from a DS18B20 sensor. ![Screenshot of temperature logger](http://i.imgur.com/nAFKJ4M.png) -##Installation: +#Installation: **Warning:** Your Raspberry Pi will reboot after installation to enable GPIO ```bash cd && git clone https://github.com/poohzrn/rpi_temp_logger && cd ~/rpi_templogger && ./install.sh From 00a85ccfd8461a29a6abcfa7915db8f077a5eb19 Mon Sep 17 00:00:00 2001 From: Lasse Nielsen Date: Fri, 18 Sep 2015 00:24:18 +0200 Subject: [PATCH 60/62] Creted by install script --- tempdb2.db | Bin 4096 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tempdb2.db diff --git a/tempdb2.db b/tempdb2.db deleted file mode 100644 index d5453ddba021a8099e8da36f6b329064700834dc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4096 zcmeH|&uhXk6vvZRCM$RrZx1}QWgSd*9$Tjwh;7xH!aS7>GbpsW*>3Erf9(E^Ew%od z3^$KT0?!6cAE%RP@l=~Wu_*y+-#Y|~7#JEXTM-DO z5m53-!RrbO90vlg-4BShs~fX~isfoNXl;j)b=q=da2y=`J*X z=WJ=`S(NZJW62AMwRrArh^(?SS^_6+yToV)zE3wN5H2Z}1Wt;8mS-dX|0i{(G8swWzXZMk D^u~!8 From d277da7f494f026e310da8e595e1b06073867afa Mon Sep 17 00:00:00 2001 From: Lasse Nielsen Date: Fri, 18 Sep 2015 13:22:20 +0200 Subject: [PATCH 61/62] path fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ed23551..a8312a5 100644 --- a/README.md +++ b/README.md @@ -4,5 +4,5 @@ This repo contains code for a Raspberry Pi temperature logger which uses SQLite #Installation: **Warning:** Your Raspberry Pi will reboot after installation to enable GPIO ```bash -cd && git clone https://github.com/poohzrn/rpi_temp_logger && cd ~/rpi_templogger && ./install.sh +cd && git clone https://github.com/poohzrn/rpi_temp_logger && cd ~/rpi_temp_logger && ./install.sh ``` From dc563a820262f7423f14655138abf2b37f7d7bfc Mon Sep 17 00:00:00 2001 From: Lasse Nielsen Date: Fri, 18 Sep 2015 13:30:33 +0200 Subject: [PATCH 62/62] crontab --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index ba377ad..a80e202 100755 --- a/install.sh +++ b/install.sh @@ -19,8 +19,8 @@ sudo ln -s ~/rpi_temp_logger/webgui.py /var/www/tmplog/index.py sudo chown www-data:www-data /usr/lib/cgi-bin/monitor.py sudo chown www-data:www-data /var/www/tmplog/tempdb2.db #Add Crontab to get data from sensors -sudo -l > currentCron -sudo echo "* * * * * /usr/lib/cgi-bin/monitor.py" >> currentCron +sudo crontab -l > currentCron +sudo echo "* * * * * /usr/lib/cgi-bin/monitor.py" >> currentCron sudo crontab currentCron && sudo rm currentCron #enable GPIO sudo echo "dtoverlay=w1-gpio" >> /boot/config.txt