Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
28bc51b
not tested, but updated
Aug 19, 2015
759fee8
dummy data, new database, new test db and ignore file
Aug 19, 2015
2776a65
database edit
Aug 19, 2015
8852563
updated install script, + 1 sql in webgui
Aug 19, 2015
291b462
reading
Aug 22, 2015
bb382f6
updated to new database
Aug 22, 2015
8a57ee9
Dropper sensor tabellen for nu
Aug 22, 2015
568d690
refactor option -> interval
Aug 22, 2015
c060c18
updated rows
Aug 22, 2015
9418856
u
Aug 22, 2015
1259229
update
Aug 22, 2015
e965777
morgen
Aug 23, 2015
cfdad24
update
Aug 23, 2015
9111821
fixed some bugs
Aug 23, 2015
d571a91
remove unused data
Aug 23, 2015
a832859
remove debug print
Aug 23, 2015
327abad
remove unused code
Aug 23, 2015
015a777
minimum added
Aug 23, 2015
e7bf4f9
last hour added
Aug 23, 2015
a46ff08
added device to last hour
Aug 23, 2015
836d4e3
refac
Aug 23, 2015
8bd8900
remove unused files
Aug 23, 2015
a64c87f
empty database
Aug 23, 2015
a946f23
curvetype: function
Aug 23, 2015
bc997cf
1 week option
Aug 23, 2015
146f90f
install notes
Aug 23, 2015
b3351c1
installation
Aug 23, 2015
9af632b
cronjob
Aug 23, 2015
1940af6
empty database bug removed
Aug 24, 2015
2e39256
Local time in database
Aug 24, 2015
68714ae
SensorName instead of sensorname
Aug 24, 2015
a647ff0
Add sensorname to the table instead of static 'sensorName'
Aug 26, 2015
95150ef
fix for actually post a request for a specific temperature interval
Aug 26, 2015
f0688f6
Merge branch 'master' of https://github.com/poohzrn/rpi_temp_logger
Sep 4, 2015
ecff13c
Updated to 3 sensors
Sep 4, 2015
263e950
Commented js-arry-convert method
Sep 4, 2015
6d2b3ff
unused variable
Sep 4, 2015
905e6ce
locale time add for new database)
Sep 9, 2015
e173b7d
updated timezone
Sep 10, 2015
32a91fe
added locale time
Sep 10, 2015
934d449
dev version of monitor - does not require sensors
Sep 10, 2015
171f731
dynamic getMultitable
Sep 10, 2015
6b32d21
its not a string, lol
Sep 10, 2015
ebe2fe0
minor changes
Sep 10, 2015
e3eb0bb
minor changes
Sep 10, 2015
7aafa1e
Update README
poohzrn Sep 10, 2015
7515687
jkkkjjjk
Sep 11, 2015
fd266b5
Update README
poohzrn Sep 13, 2015
0ea0a80
Update README
poohzrn Sep 13, 2015
f661d57
Update README
poohzrn Sep 13, 2015
fff90fa
Update README
poohzrn Sep 13, 2015
dcd0b40
updated install script - creating a backup of a da
Sep 17, 2015
03507eb
Configuration for tmplog virtual host
Sep 17, 2015
b1a1457
Add the vertual host
Sep 17, 2015
4008451
Readme
Sep 17, 2015
7b90545
Added crontab and enable gpio
Sep 17, 2015
f24cfd4
Update
Sep 17, 2015
ce690cf
reboot to enable GPIO
Sep 17, 2015
64948d2
Syntax
Sep 17, 2015
ae4a03a
Syntax
Sep 17, 2015
00a85cc
Creted by install script
Sep 17, 2015
d277da7
path fix
Sep 18, 2015
dc563a8
crontab
Sep 18, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.swp
7 changes: 0 additions & 7 deletions README

This file was deleted.

8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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_temp_logger && ./install.sh
```
10 changes: 10 additions & 0 deletions createDatabase.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE sensor_data (
sensor_id TEXT NOT NULL,
timestamp datetime NOT NULL DEFAULT (DATETIME(CURRENT_TIMESTAMP, 'LOCALTIME')),
value real NOT NULL
);
CREATE TABLE sensor (
sensor_id TEXT NOT NULL UNIQUE,
sensor_name TEXT NOT NULL DEFAULT 'SensorName',
PRIMARY KEY(sensor_id)
);
38 changes: 38 additions & 0 deletions devmonitor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python

import sqlite3
import glob
import random
import commands

# global variables
dbname='/var/www/tmplog/tempdb2.db'

# store the temperature in the database
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
conn.commit()
conn.close()

# main function
# This is where the program starts
def main():
devicelist = ['device1','device2',"device321"]
if devicelist=='':
# no devices
return None
else:
for device in devicelist:
temperature = random.uniform(0.0,45.0)
deviceid = device
print temperature
print deviceid
log_temperature(deviceid, temperature)
if __name__=="__main__":
main()
28 changes: 28 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
!#/usr/bin/env bash
#Sudo access
sudo -v
sudo apt-get update
sudo apt-get intsall apache2 -y
sudo apt-get install sqlite3 -y
sudo a2enmod mpm_prefork cgi
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 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

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 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
#restart to enable GPIO
sudo reboot now
82 changes: 30 additions & 52 deletions monitor.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,39 @@
#!/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,))

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
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"):
print str(row[0])+" "+str(row[1])

getDevices = "SELECT * FROM sensor"
getSensorDataQuery = "SELECT * FROM sensor_data WHERE sensor_id =?"
for row in curs.execute(getSensorDataQuery, [iD]):
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 temerature
# get temperature
# returns None on error, or the temperature as a float
def get_temp(devicefile):

Expand All @@ -64,8 +58,6 @@ def get_temp(devicefile):
print "There was an error."
return None



# main function
# This is where the program starts
def main():
Expand All @@ -75,38 +67,24 @@ 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*')
print devicelist
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]
# Store the temperature in the database
log_temperature(deviceid, temperature)
#display_data(deviceid)
if __name__=="__main__":
main()




Binary file removed templog.db
Binary file not shown.
11 changes: 11 additions & 0 deletions tmplog.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
NameVirtualHost *:80
<VirtualHost *:80>
<Directory /var/www/tmplog>
Options +ExecCGI
DirectoryIndex index.py
</Directory>
AddHandler cgi-script
DocumentRoot /var/www/tmplog
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Loading