~ubuntu-branches/debian/jessie/digitemp/jessie

« back to all changes in this revision

Viewing changes to python/gui/digitemp_gui.py

  • Committer: Bazaar Package Importer
  • Author(s): Jesus Roncero
  • Date: 2004-09-01 01:34:37 UTC
  • Revision ID: james.westby@ubuntu.com-20040901013437-eicsrrd40dr371u0
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
#
 
3
# DigiTemp temperature and 1-wire home weather station graphing
 
4
# Copyright 2003 by Brian C. Lane <bcl@brianlane.com>
 
5
# http://www.digitemp.com
 
6
#
 
7
# Requires DigiTemp v3.1.0 or later for counter support
 
8
 
9
 
 
10
import string, os, sys, time
 
11
 
 
12
timefmt = '%Y-%m-%d %H:%M:%S'
 
13
 
 
14
# 1. Read the output of DigiTemp
 
15
cmd = '/home/brian/temperature/digitemp -c/home/brian/temperature/digitemp.cfg -a -q'
 
16
 
 
17
for outline in os.popen(cmd).readlines():
 
18
   outline = outline[:-1]
 
19
#   print outline
 
20
 
 
21
   if outline[0:1] == 'T':
 
22
      # Parse the temperature sensor line
 
23
      S = string.split(outline, " ")
 
24
#      print S      
 
25
 
 
26
      # Add the reading to the database
 
27
      sql = "INSERT INTO temperature VALUES(NULL, %s, %s, %s)"
 
28
      sqltime = time.strftime( timefmt, time.localtime(int(S[2])))
 
29
      cursor.execute( sql, (S[1], sqltime, S[3]) );
 
30
 
 
31
   if outline[0:1] == 'C':
 
32
      # Parse the counter line
 
33
      S = string.split(outline, " ")
 
34
#      print S
 
35
 
 
36
      # Add the reading to the database
 
37
      sql = "INSERT INTO counter VALUES(NULL, %s, %s, %s, %s)"
 
38
      sqltime = time.strftime( timefmt, time.localtime(int(S[2])))
 
39
      cursor.execute( sql, (S[1], sqltime, S[3], S[4]) );
 
40
 
 
41
# -----------------------------------------------------------------------
 
42
# Do interesting things with the just-logged information
 
43
# =======================================================================
 
44
# Brian's Sensor Map:
 
45
#
 
46
#10E8A00E00000055      Room (grey wire)
 
47
#10B95E05000800AA      Attic
 
48
#10575A050008008F      Desk
 
49
#22B9B20500000049      DS1822
 
50
#286D1D2D000000EA      DS18B20 (kermit)
 
51
#1092B9330008002E      Drink
 
52
#1D9CB900000000B3      Rain Gauge
 
53
#1DFA15010000005F      Wind Speed
 
54
#1009212E0008004B      DT-1A passive sensor
 
55
#
 
56
 
 
57
# Dict of serial numbers and what to name them
 
58
sensors = {'10E8A00E00000055':'Office',
 
59
           '10B95E05000800AA':'Attic',
 
60
           '10575A050008008F':'Desk',
 
61
           '22B9B20500000049':'DS1822',
 
62
           '286D1D2D000000EA':'DS18B20',
 
63
           '1092B9330008002E':'Drink',
 
64
           '1009212E0008004B':'DT1A'
 
65
          }
 
66
 
 
67
counters= {'1D9CB900000000B3':'Rain',
 
68
           '1DFA15010000005F':'Wind'
 
69
          }
 
70
 
 
71
def c2f( c ):
 
72
  f = 32.0 + ((c * 9.0) / 5.0)
 
73
  return f
 
74