powerguru-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Powerguru-commit] [SCM] powerguru branch, master, updated. 152640d997f9


From: Rob Savoye
Subject: [Powerguru-commit] [SCM] powerguru branch, master, updated. 152640d997f9a5086826cbd645811b38b8356945
Date: Sun, 6 Jan 2019 16:12:17 -0500 (EST)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "powerguru".

The branch, master has been updated
       via  152640d997f9a5086826cbd645811b38b8356945 (commit)
       via  92677ee2947cc661f606a5e3012ea1eb08f03c79 (commit)
      from  8f64eaba7d80e6353fb37c479ba61534841bd131 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=152640d997f9a5086826cbd645811b38b8356945


commit 152640d997f9a5086826cbd645811b38b8356945
Author: Rob Savoye <address@hidden>
Date:   Sun Jan 6 14:12:06 2019 -0700

    Add documentation to code

diff --git a/python/onewire.py b/python/onewire.py
new file mode 100755
index 0000000..fd23b03
--- /dev/null
+++ b/python/onewire.py
@@ -0,0 +1,97 @@
+#!/usr/bin/python3
+
+# 
+#   Copyright (C) 2019   Free Software Foundation, Inc.
+# 
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+# 
+
+import epdb
+import logging
+
+
+# class Onewire
+
+def onewire_handler(arg):
+    print("Start onewire")
+
+_family = dict();
+#_family['A2'] = {"description"="AC Voltage", "chips"="mCM001", 
"type"="ACVOLTAGE"};
+
+_family["A2"] = {"description":"AC Voltage", "chips":"mCM001", 
"type":"ACVOLTAGE"};
+_family["82"] = {"description":"Authorization", "chips":"DS1425", 
"type":"AUTH"};
+_family["30"] = {"description":"Battery", "chips":"DS2760", "type":"BATTERY"};
+_family["32"] = {"description":"Battery", "chips":"DS2780", "type":"BATTERY"};
+_family["35"] = {"description":"Battery", "chips":"DS2755", "type":"BATTERY"};
+_family["2E"] = {"description":"Battery", "chips":"DS2770", "type":"BATTERY"};
+_family["3D"] = {"description":"Battery", "chips":"DS2781", "type":"BATTERY"};
+_family["31"] = {"description":"Battery ID", "chips":"DS2720", 
"type":"BATTERY"};
+_family["26"] = {"description":"Battery monitor", "chips":"DS2438", 
"type":"BATTERY"};
+_family["51"] = {"description":"Battery monitor", "chips":"DS2751", 
"type":"BATTERY"};
+_family["1B"] = {"description":"Battery monitor", "chips":"DS2436", 
"type":"BATTERY"};
+_family["1E"] = {"description":"Battery monitor", "chips":"DS2437", 
"type":"BATTERY"};
+_family["24"] = {"description":"Clock", "chips":"DS2415", "type":"CLOCK"};
+_family["27"] = {"description":"Clock + interrupt", "chips":"DS2417", 
"type":"CLOCK"};
+_family["36"] = {"description":"Coulomb counter", "chips":"DS2740", 
"type":"UNSUPPORTED"};
+_family["1D"] = {"description":"Counter", "chips":"DS2423", 
"type":"UNSUPPORTED"};
+_family["16"] = {"description":"crypto-ibutton", "chips":"DS1954 DS1957", 
"type":"UNSUPPORTED"};
+_family["B2"] = {"description":"DC Current or Voltage", "chips":"mAM001", 
"type":"BATTERY"};
+_family["04"] = {"description":"EconoRam Time chi", "chips":"DS2404", 
"type":"UNSUPPORTED"};
+_family["7E"] = {"description":"Envoronmental Monitors", "chips":"EDS00xx", 
"type":"UNSUPPORTED"};
+_family["41"] = {"description":"Hygrocron", "chips":"DS1923", 
"type":"UNSUPPORTED"};
+_family["81"] = {"description":"ID found in DS2490R and DS2490B USB adapters", 
"chips":"USB id", "type":"UNSUPPORTED"};
+_family["01"] = {"description":"ID-only", "chips":"DS2401 DS2411 DS1990R 
DS2490A", "type":"UNSUPPORTED"};
+_family["A6"] = {"description":"IR Temperature", "chips":"mTS017", 
"type":"UNSUPPORTED"};
+_family["06"] = {"description":"Memory", "chips":"DS1993", 
"type":"UNSUPPORTED"};
+_family["08"] = {"description":"Memory", "chips":"DS1992", 
"type":"UNSUPPORTED"};
+_family["09"] = {"description":"Memory", "chips":"DS2502 DS2703 DS2704", 
"type":"UNSUPPORTED"};
+_family["14"] = {"description":"Memory", "chips":"DS2430A", 
"type":"UNSUPPORTED"};
+_family["23"] = {"description":"Memory", "chips":"DS2433 DS1973", 
"type":"UNSUPPORTED"};
+_family["43"] = {"description":"Memory", "chips":"DS28EC20", 
"type":"UNSUPPORTED"};
+_family["0B"] = {"description":"Memory", "chips":"DS2505", 
"type":"UNSUPPORTED"};
+_family["0F"] = {"description":"Memory", "chips":"DS2506", 
"type":"UNSUPPORTED"};
+_family["2D"] = {"description":"Memory", "chips":"DS2431 DS1972", 
"type":"UNSUPPORTED"};
+_family["1F"] = {"description":"Microhub", "chips":"DS2409", 
"type":"UNSUPPORTED"};
+_family["EF"] = {"description":"Moisture meter.4 Channel Hub 1A", 
"chips":"DS1963L Monetary iButton", "type":"UNSUPPORTED"};
+_family["02"] = {"description":"Multikey", "chips":"DS1991", 
"type":"UNSUPPORTED"};
+_family["37"] = {"description":"password EEPROM", "chips":"DS1977", 
"type":"UNSUPPORTED"};
+_family["FC"] = {"description":"Moisture Hub", "chips":"BAE0910 BAE0911", 
"type":"UNSUPPORTED"};
+_family["00"] = {"description":"Provide location information", "chips":"Link 
locator", "type":"UNSUPPORTED"};
+_family["A0"] = {"description":"Rotation Sensor", "chips":"mRS001", 
"type":"UNSUPPORTED"};
+_family["18"] = {"description":"SHA iButton", "chips":"DS1963S DS1962", 
"type":"UNSUPPORTED"};
+_family["44"] = {"description":"SHA-1 Authenticator", "chips":"DS28E10", 
"type":"UNSUPPORTED"};
+_family["34"] = {"description":"SHA-1 Battery", "chips":"DS2703", 
"type":"UNSUPPORTED"};
+_family["33"] = {"description":"SHA-1 ibutton", "chips":"DS1961s DS2432", 
"type":"UNSUPPORTED"};
+_family["FF"] = {"description":"Swart LCD", "chips":"LCD", 
"type":"UNSUPPORTED"};
+_family["05"] = {"description":"Switch", "chips":"Ds2405", 
"type":"UNSUPPORTED"};
+_family["12"] = {"description":"Switch", "chips":"DS2406", 
"type":"UNSUPPORTED"};
+_family["29"] = {"description":"Switch", "chips":"DS2408", 
"type":"UNSUPPORTED"};
+_family["1C"] = {"description":"Switch", "chips":"DS28E04-100", 
"type":"UNSUPPORTED"};
+_family["3A"] = {"description":"Switch", "chips":"DS2413", 
"type":"UNSUPPORTED"};
+_family["10"] = {"description":"Temperature", "chips":"DS18S20", 
"type":"TEMPERATURE"};
+_family["22"] = {"description":"Temperature", "chips":"DS1922", 
"type":"TEMPERATURE"};
+_family["28"] = {"description":"Temperature", "chips":"DS18B20", 
"type":"TEMPERATURE"};
+_family["3B"] = {"description":"Temperature/memory", "chips":"DS1825 X31826", 
"type":"UNSUPPORTED"};
+_family["42"] = {"description":"Temperature/IO", "chips":"DS28EA00", 
"type":"UNSUPPORTED"};
+_family["B1"] = {"description":"Thermocouple Converter", "chips":"mTC001", 
"type":"UNSUPPORTED"};  
+_family["B3"] = {"description":"Thermocouple Converter", "chips":"mTC002", 
"type":"UNSUPPORTED"};
+_family["21"] = {"description":"Thermocron", "chips":"DS1921", 
"type":"UNSUPPORTED"};
+_family["EE"] = {"description":"Ultra Violet Index", "chips":"UVI", 
"type":"UNSUPPORTED"};
+_family["89"] = {"description":"Uniqueware", "chips":"DS1982U", 
"type":"UNSUPPORTED"};
+_family["8B"] = {"description":"Uniqueware", "chips":"DS1985U", 
"type":"UNSUPPORTED"};
+_family["8F"] = {"description":"Uniqueware", "chips":"DS1986U", 
"type":"UNSUPPORTED"};
+_family["2C"] = {"description":"Varible Resitor", "chips":"DS2890", 
"type":"UNSUPPORTED"};
+_family["A1"] = {"description":"Vibratio", "chips":"mVM001", 
"type":"UNSUPPORTED"};
+_family["20"] = {"description":"Voltage", "chips":"DS2450", 
"type":"UNSUPPORTED"};
+
diff --git a/python/ownet.py b/python/ownet.py
index a95e1a2..fa6faf3 100755
--- a/python/ownet.py
+++ b/python/ownet.py
@@ -1,7 +1,7 @@
 #!/usr/bin/python3
 
 # 
-#   Copyright (C) 2019   Free Software Foundation, Inc.
+#   Copyright (C) 2019 Free Software Foundation, Inc.
 # 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -17,7 +17,7 @@
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 # 
 
-# https://pyownet.readthedocs.io/en/latest/
+# API documentation at: https://pyownet.readthedocs.io/en/latest/
 
 import epdb
 import logging
@@ -29,6 +29,7 @@ import psycopg2
 def ownet_handler(args):
     logging.debug("Start ownet %r" % args)
 
+    # Connect to a postgresql database
     try:
         dbname = "powerguru"
         connect = "dbname=" + dbname
@@ -42,54 +43,87 @@ def ownet_handler(args):
                 logging.info("Opened cursor in %r" % dbname)
                 
     except Exception as e:
-        logging.error("Couldn't connect to database: %r" % e)
+        logging.warning("Couldn't connect to database: %r" % e)
         
 
     _sensors = list()
 
-    options = dict()
-    options['owserver'] = "pi"
+    # It turns out that the network connection occcsasionally times out
+    # reading data, which is ok to ignore most of the time. However,
+    # it's possible there is a server error, so kill the thread if
+    # we exceed a threashold of pain.
+    errors = 0
+    error_threshold = 0
+    
     # Connecting to the OW server over the network often fails due to a
     # short timeout, so try a few times before giving up
     retries = 3
     while retries > 0:
         retries -= 1
+        # Get a list of all directories on the server
         try:
-            owproxy = protocol.proxy(host="pi", port=4304)
-            logging.error("Connected to OW server: %r" % options['owserver'])
+            owproxy = protocol.proxy(host=args['owserver'], port=4304)
+            logging.error("Connected to OW server: %r" % args['owserver'])
             owproxy.dir()
+            break
         except Exception as e:
             logging.error("Couldn't connect to OW server: %r" % e)
 
-    interval = 100
+    interval = int(args['interval'])
     while interval > 0:
         for dir in owproxy.dir():
-            logging.info("Checking directory: " + dir)
+            logging.info("Reading data from: %s:%s"
+                         % (args['owserver'], dir))
             sensor = dict()
-            family = owproxy.read(dir + 'family').decode("utf-8")
-            sensor['family'] = family
-            id = owproxy.read(dir + 'id').decode("utf-8")
-            sensor['id'] = id;
-            sensor['alias'] = owproxy.read(dir + 'alias')
-            sensor['type'] = onewire._family[family]['type']
-            sensor['chips'] = owproxy.read(dir + 'type')
-            #logging.debug("%r" % sensor)
+            # Note that all the strings returned are wide strings, and
+            # not ASCII. Because the 'b' qualifier for these strings
+            # messes up comparisions with normal text strings. they
+            # get decoded.
+            try:
+                family = owproxy.read(dir + 'family').decode("utf-8")
+                sensor['family'] = family
+                id = owproxy.read(dir + 'id').decode("utf-8")
+                sensor['id'] = id;
+                sensor['alias'] = owproxy.read(dir + 'alias').decode("utf-8")
+                sensor['type'] = onewire._family[family]['type']
+                sensor['chips'] = owproxy.read(dir + 'type').decode("utf-8")
+            except Exception as e:
+                logging.warning("Couldn't read from OW server: %r" % e)
+                errors += 1
+                time.sleep(1)   # give the server a second to recover
+                continue
+
+            logging.debug("%r" % sensor)
             _sensors.append(sensor)
+            # FIXME: format query and write to database
+            # dbcursor.execute(query)
             # family | id | alias | type | timestamp
 
             if sensor['type'] == 'TEMPERATURE':
-                logging.info("Found a temperature sensor: " + family + '.' + 
id)
+                #logging.info("Found a temperature sensor: " + family + '.' + 
id)
                 temp = dict()
-                temp['temperature'] = owproxy.read(dir + 
'temperature').lstrip().decode("utf-8")
-                temp['lowtemp'] = owproxy.read(dir + 
'templow').lstrip().decode("utf-8")
-                temp['hightemp'] = owproxy.read(dir + 
'temphigh').lstrip().decode("utf-8")
-                logging.debug("Temperature data: %r" % temp)
+                try:
+                    temp['temperature'] = owproxy.read(dir + 
'temperature').lstrip().decode("utf-8")
+                    temp['lowtemp'] = owproxy.read(dir + 
'templow').lstrip().decode("utf-8")
+                    temp['hightemp'] = owproxy.read(dir + 
'temphigh').lstrip().decode("utf-8")
+                    logging.debug("Temperature data: %r" % temp)
+                except Exception as e:
+                    logging.warning("Couldn't read from OW server: %r" % e)
+                    errors += 1
+                    time.sleep(1)   # give the server a second to recover
+                    continue
+                # By default, all temperature readings are in 'C' (Celcius)
+                # we convert to 'F' (Farenheit) if need be
+                if (args['scale'] == 'F'):
+                    temp['temperature'] = (float(temp['temperature']) * 1.8) + 
32.0;
+                    temp['lowtemp'] =  (float(temp['lowtemp']) * 1.8) + 32.0;
+                    temp['hightemp'] =  (float(temp['hightemp']) * 1.8) + 32.0;
                 query = "INSERT INTO temperature VALUES("
                 query += "'" + id + "'"
-                query += ", " + temp['temperature']
-                query += ", " + temp['lowtemp']
-                query += ", " + temp['hightemp']
-                query += ", " + "'F'"
+                query += ", " + str(temp['temperature'])
+                query += ", " + str(temp['lowtemp'])
+                query += ", " + str(temp['hightemp'])
+                query += ", " + "'" + args['scale'] + "'"
                 query += ", '" + time.strftime("%Y-%m-%d %H:%M:%S") + "'"
                 query += ");"
                 logging.debug(query)
@@ -97,11 +131,18 @@ def ownet_handler(args):
                 # id | temperature | temphigh | templow | scale | timestamp
  
             if sensor['type'] == 'BATTERY':
-                logging.info("Found a power monitor sensor: " + family + '.' + 
id)
+                # logging.info("Found a power monitor sensor: " + family + '.' 
+ id)
                 batt = dict()
-                batt['current'] = owproxy.read(dir + 
'current').lstrip().decode("utf-8")
-                batt['voltage'] = owproxy.read(dir + 
'volts').lstrip().decode("utf-8")
-                logging.debug("Battery data: %r" % batt)
+                try:
+                    batt['current'] = owproxy.read(dir + 
'current').lstrip().decode("utf-8")
+                    batt['voltage'] = owproxy.read(dir + 
'volts').lstrip().decode("utf-8")
+                    logging.debug("Battery data: %r" % batt)
+                except Exception as e:
+                    logging.warning("Couldn't read from OW server: %r" % e)
+                    errors += 1
+                    time.sleep(1)   # give the server a second to recover
+                    continue
+
                 query = "INSERT INTO battery VALUES("
                 query += "'" + id + "'"
                 query += ", " + batt['current']
@@ -113,5 +154,8 @@ def ownet_handler(args):
                 dbcursor.execute(query)
                 # id | current | volts | type | timestamp
 
-                # Don't eat up all the cpu cycles!
-                time.sleep(interval)
+        # Don't eat up all the cpu cycles!
+        time.sleep(interval)
+
+        if errors > error_threshold:
+            return
diff --git a/python/pgd.py b/python/pgd.py
index 2ee8527..ff92bec 100755
--- a/python/pgd.py
+++ b/python/pgd.py
@@ -1,7 +1,7 @@
 #!/usr/bin/python3
 
 # 
-#   Copyright (C) 2019   Free Software Foundation, Inc.
+#   Copyright (C) 2019 Free Software Foundation, Inc.
 # 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -28,33 +28,39 @@ from threading import Thread
 from time import sleep
 from sys import argv
 
-# Get the path to this script
-#import os
-#import sys
-#sys.path.append(os.path.dirname(argv[0]))
-
+# Setup default command line options
+options = dict()
+options['interval'] = "300"  # time interval to delay when polling for data
+options['owserver'] = "localhost"  # hostname of the owserver
+options['dbserver'] = "localhost"  # hostname of the database
+options['scale'] = "F"             # The scale, 'C' or 'F'
 
+# menu for --help
 def usage(argv):
     print(argv[0] + ": options: ")
     print("""\t--help(-h)   Help
-\t--owserver(-w)        OW server
-\t--dbserver(-d)        Database server
-\t--verbose(-v)         Enable verbosity
-        """)
+    \t--owserver(-w)    OW server [host[:port]], default '%s'
+    \t--dbserver(-d)    Database server [host]:port]], default '%s'
+    \t--interval(-i)    Set the time interval for device polling, default '%s'
+    \t--verbose(-v)     Enable verbosity
+    \t--scale(-s)       Set the temperature scale, 'F' or 'C', default '%s'
+    """ % (options['owserver'],
+           options['dbserver'],
+           options['interval'],
+           options['scale']))
     quit()
 
+# Check command line arguments
 try:
-    (opts, val) = getopt.getopt(argv[1:], "h,w:,d:,v,",
-           ["help", "owserver", "dbserver", "verbose"])
+    (opts, val) = getopt.getopt(argv[1:], "h,w:,d:,s:,i:v,",
+           ["help", "owserver", "dbserver", "scale", "interval", "verbose"])
 except getopt.GetoptError as e:
     logging.error('%r' % e)
-    self.usage(argv)
+    usage(argv)
     quit()
 
-# Store command line options
-options = dict()
-options['owserver'] = val
-options['dbserver'] = val
+# Setup a disk space log filemode. By default, everything
+# gets logged to the disk file
 logging.basicConfig(
     filename='pgdpy.log',
     filemode='w',
@@ -62,7 +68,11 @@ logging.basicConfig(
     format= '[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s - 
%(message)s',
      datefmt='%Y-%m-%d %H:%M:%S'
 )
-# By default, print nothing to the console
+
+# Setup console logging, useful for debugging
+# By default, print nothing to the console. There
+# re two versosity levels, the first just informational
+# messages, the second all debugging messages as well.
 root = logging.getLogger()
 ch = logging.StreamHandler(sys.stdout)
 ch.setLevel(logging.CRITICAL)
@@ -70,12 +80,17 @@ formatter = logging.Formatter('%(message)s')
 #formatter = logging.Formatter('{%(filename)s:%(lineno)d} - %(message)s')
 ch.setFormatter(formatter)
 root.addHandler(ch)
+terminator = ch.terminator
 verbosity = logging.CRITICAL
+
+# process command line arguments, will override the defaults
 for (opt, val) in opts:
     if opt == '--help' or opt == '-h':
         usage(argv)
     elif opt == "--owserver" or opt == '-w':
         options['owserver'] = val
+    elif opt == "--interval" or opt == '-i':
+        options['interval'] = val
     elif opt == "--dbserver" or opt == '-d':
         options['dbserver'] = val
     elif opt == "--verbose" or opt == '-v':
@@ -87,11 +102,16 @@ for (opt, val) in opts:
             verbosity = logging.INFO
 
 ch.setLevel(verbosity)
+
 #
 # Start the I/O threads
 #
-ownet_thread = Thread(target = ownet.ownet_handler, args = 
(options['owserver'], ))
+
+# OWFS network protocol
+ownet_thread = Thread(target=ownet.ownet_handler, args=(options, ))
 ownet_thread.start()
+
+# OWFS filesystem
 onewire_thread = Thread(target = onewire.onewire_handler, args = (10, ))
 onewire_thread.start()
 
diff --git a/python/setup.py b/python/setup.py
old mode 100644
new mode 100755

http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=92677ee2947cc661f606a5e3012ea1eb08f03c79


commit 92677ee2947cc661f606a5e3012ea1eb08f03c79
Author: Rob Savoye <address@hidden>
Date:   Sun Jan 6 12:05:21 2019 -0700

    Try several times to connect to the oserver, loop and read data while 
connected

diff --git a/python/ownet.py b/python/ownet.py
index 00f5faf..a95e1a2 100755
--- a/python/ownet.py
+++ b/python/ownet.py
@@ -46,58 +46,72 @@ def ownet_handler(args):
         
 
     _sensors = list()
-    try:
-        owproxy = protocol.proxy(host="pi", port=4304)
-        owproxy.dir()
-    except Exception as e:
-        logging.error("Couldn't connect to OW server: %r" % e)
-        
-    for dir in owproxy.dir():
-        logging.info("Checking directory: " + dir)
-        sensor = dict()
-        family = owproxy.read(dir + 'family').decode("utf-8")
-        sensor['family'] = family
-        id = owproxy.read(dir + 'id').decode("utf-8")
-        sensor['id'] = id;
-        sensor['alias'] = owproxy.read(dir + 'alias')
-        sensor['type'] = onewire._family[family]['type']
-        sensor['chips'] = owproxy.read(dir + 'type')
-        #logging.debug("%r" % sensor)
-        _sensors.append(sensor)
-        # family | id | alias | type | timestamp
 
-        if sensor['type'] == 'TEMPERATURE':
-            logging.info("Found a temperature sensor: " + family + '.' + id)
-            temp = dict()
-            temp['temperature'] = owproxy.read(dir + 
'temperature').lstrip().decode("utf-8")
-            temp['lowtemp'] = owproxy.read(dir + 
'templow').lstrip().decode("utf-8")
-            temp['hightemp'] = owproxy.read(dir + 
'temphigh').lstrip().decode("utf-8")
-            logging.debug("Temperature data: %r" % temp)
-            query = "INSERT INTO temperature VALUES("
-            query += "'" + id + "'"
-            query += ", " + temp['temperature']
-            query += ", " + temp['lowtemp']
-            query += ", " + temp['hightemp']
-            query += ", " + "'F'"
-            query += ", '" + time.strftime("%Y-%m-%d %H:%M:%S") + "'"
-            query += ");"
-            logging.debug(query)
-            dbcursor.execute(query)
-            # id | temperature | temphigh | templow | scale | timestamp
+    options = dict()
+    options['owserver'] = "pi"
+    # Connecting to the OW server over the network often fails due to a
+    # short timeout, so try a few times before giving up
+    retries = 3
+    while retries > 0:
+        retries -= 1
+        try:
+            owproxy = protocol.proxy(host="pi", port=4304)
+            logging.error("Connected to OW server: %r" % options['owserver'])
+            owproxy.dir()
+        except Exception as e:
+            logging.error("Couldn't connect to OW server: %r" % e)
+
+    interval = 100
+    while interval > 0:
+        for dir in owproxy.dir():
+            logging.info("Checking directory: " + dir)
+            sensor = dict()
+            family = owproxy.read(dir + 'family').decode("utf-8")
+            sensor['family'] = family
+            id = owproxy.read(dir + 'id').decode("utf-8")
+            sensor['id'] = id;
+            sensor['alias'] = owproxy.read(dir + 'alias')
+            sensor['type'] = onewire._family[family]['type']
+            sensor['chips'] = owproxy.read(dir + 'type')
+            #logging.debug("%r" % sensor)
+            _sensors.append(sensor)
+            # family | id | alias | type | timestamp
+
+            if sensor['type'] == 'TEMPERATURE':
+                logging.info("Found a temperature sensor: " + family + '.' + 
id)
+                temp = dict()
+                temp['temperature'] = owproxy.read(dir + 
'temperature').lstrip().decode("utf-8")
+                temp['lowtemp'] = owproxy.read(dir + 
'templow').lstrip().decode("utf-8")
+                temp['hightemp'] = owproxy.read(dir + 
'temphigh').lstrip().decode("utf-8")
+                logging.debug("Temperature data: %r" % temp)
+                query = "INSERT INTO temperature VALUES("
+                query += "'" + id + "'"
+                query += ", " + temp['temperature']
+                query += ", " + temp['lowtemp']
+                query += ", " + temp['hightemp']
+                query += ", " + "'F'"
+                query += ", '" + time.strftime("%Y-%m-%d %H:%M:%S") + "'"
+                query += ");"
+                logging.debug(query)
+                dbcursor.execute(query)
+                # id | temperature | temphigh | templow | scale | timestamp
  
-        if sensor['type'] == 'BATTERY':
-            logging.info("Found a power monitor sensor: " + family + '.' + id)
-            batt = dict()
-            batt['current'] = owproxy.read(dir + 
'current').lstrip().decode("utf-8")
-            batt['voltage'] = owproxy.read(dir + 
'volts').lstrip().decode("utf-8")
-            logging.debug("Battery data: %r" % batt)
-            query = "INSERT INTO battery VALUES("
-            query += "'" + id + "'"
-            query += ", " + batt['current']
-            query += ", " + batt['voltage']
-            query += ", 'DC'"
-            query += ", '" + time.strftime("%Y-%m-%d %H:%M:%S") + "'"
-            query += ");"
-            logging.debug(query)
-            dbcursor.execute(query)
-            # id | current | volts | type | timestamp
+            if sensor['type'] == 'BATTERY':
+                logging.info("Found a power monitor sensor: " + family + '.' + 
id)
+                batt = dict()
+                batt['current'] = owproxy.read(dir + 
'current').lstrip().decode("utf-8")
+                batt['voltage'] = owproxy.read(dir + 
'volts').lstrip().decode("utf-8")
+                logging.debug("Battery data: %r" % batt)
+                query = "INSERT INTO battery VALUES("
+                query += "'" + id + "'"
+                query += ", " + batt['current']
+                query += ", " + batt['voltage']
+                query += ", 'DC'"
+                query += ", '" + time.strftime("%Y-%m-%d %H:%M:%S") + "'"
+                query += ");"
+                logging.debug(query)
+                dbcursor.execute(query)
+                # id | current | volts | type | timestamp
+
+                # Don't eat up all the cpu cycles!
+                time.sleep(interval)

-----------------------------------------------------------------------

Summary of changes:
 python/onewire.py |  97 +++++++++++++++++++++++++++++++
 python/ownet.py   | 170 ++++++++++++++++++++++++++++++++++++------------------
 python/pgd.py     |  58 +++++++++++++------
 python/setup.py   |   0
 4 files changed, 250 insertions(+), 75 deletions(-)
 create mode 100755 python/onewire.py
 mode change 100644 => 100755 python/setup.py


hooks/post-receive
-- 
powerguru



reply via email to

[Prev in Thread] Current Thread [Next in Thread]