Skip to content
This repository was archived by the owner on Dec 9, 2022. It is now read-only.

Commit 8186d93

Browse files
committed
first commit
0 parents  commit 8186d93

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

getTemp.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import serial
2+
3+
def getTemp():
4+
ser = serial.Serial(port="/dev/ttyUSB0", baudrate=9600, timeout=10)
5+
ser.open()
6+
ser.flushInput()
7+
value = ser.read(51)
8+
ser.flush()
9+
ser.close()
10+
#conversation done acording to maxim-ic documentation for DS18S20
11+
TEMP_LSB = int(value.split(' ')[9], 16)
12+
TEMP_MSB = int(value.split(' ')[10], 16)
13+
COUNT_REMAIN = int(value.split(' ')[15], 16)
14+
if (TEMP_MSB == 0):
15+
#positve temerature
16+
TEMP_READ = TEMP_LSB*0.5
17+
else:
18+
#negative temperature
19+
TEMP_READ = (TEMP_LSB-256)*0.5
20+
#get extended temperature
21+
TEMPERATURE = TEMP_READ - 0.25 * ((16.0 - COUNT_REMAIN)/ 16.0)
22+
return round(TEMPERATURE, 1)
23+
24+
def main():
25+
print getTemp(), "C"
26+
27+
if __name__ == "__main__":
28+
main()

temp.plot

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env gnuplot
2+
set title "Temperature"
3+
set xlabel "Datetime"
4+
set ylabel "Celcius"
5+
6+
set terminal png
7+
set output "temp.png"
8+
set datafile separator "|"
9+
set style data linespoint
10+
set xdata time
11+
set timefmt "%y-%m-%d %H:%M"
12+
set xrange ["2008-07-12 00:00":"2009-07-13 00:00"]
13+
set format x "%y-%m-%d %H:%M"
14+
#set timefmt "%y-%m-%d"
15+
plot "< sqlite3 temp.db 'select date, temp from temp'" using 1:2 title "test"

updateTemp.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import sqlite3, sys, datetime
2+
import getTemp
3+
4+
try:
5+
temp = getTemp.getTemp()
6+
except:
7+
print "not able to get temp"
8+
sys.exit()
9+
10+
conn = sqlite3.connect("/home/simon/tempLog/temp.db")
11+
c = conn.cursor()
12+
date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
13+
sensor = "test"
14+
c.execute("insert into temp values(?, ?, ?)",[date, temp, sensor])
15+
conn.commit();
16+
c.close()

0 commit comments

Comments
 (0)