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. 8f64eaba7d80


From: Rob Savoye
Subject: [Powerguru-commit] [SCM] powerguru branch, master, updated. 8f64eaba7d80e6353fb37c479ba61534841bd131
Date: Sun, 6 Jan 2019 13:48:15 -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  8f64eaba7d80e6353fb37c479ba61534841bd131 (commit)
       via  12bd1a84dbc2087edc0805a894531c3b95178633 (commit)
       via  ec628f3574ebc1908eb2fd132331bedea476b60d (commit)
       via  57270c1dc721579a7279cec298c78f78ce9da3ae (commit)
       via  696dde1d63b81a9affb62fc919e97ea9c69eaa83 (commit)
       via  ffea8a32acfe3b58b7c3fe0267833a804fccb6d5 (commit)
      from  8237d0bc050edb3eae6fb8956ca04b1e72d2942b (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=8f64eaba7d80e6353fb37c479ba61534841bd131


commit 8f64eaba7d80e6353fb37c479ba61534841bd131
Author: Rob Savoye <address@hidden>
Date:   Sun Jan 6 11:47:39 2019 -0700

    Add battery data to DB

diff --git a/python/ownet.py b/python/ownet.py
new file mode 100755
index 0000000..00f5faf
--- /dev/null
+++ b/python/ownet.py
@@ -0,0 +1,103 @@
+#!/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
+# 
+
+# https://pyownet.readthedocs.io/en/latest/
+
+import epdb
+import logging
+import time
+from pyownet import protocol
+import onewire
+import psycopg2
+
+def ownet_handler(args):
+    logging.debug("Start ownet %r" % args)
+
+    try:
+        dbname = "powerguru"
+        connect = "dbname=" + dbname
+        dbshell = psycopg2.connect(connect)
+        if dbshell.closed == 0:
+            dbshell.autocommit = True
+            logging.info("Opened connection to %r" % dbname)
+            
+            dbcursor = dbshell.cursor()
+            if dbcursor.closed == 0:
+                logging.info("Opened cursor in %r" % dbname)
+                
+    except Exception as e:
+        logging.error("Couldn't connect to database: %r" % e)
+        
+
+    _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
+ 
+        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

http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=12bd1a84dbc2087edc0805a894531c3b95178633


commit 12bd1a84dbc2087edc0805a894531c3b95178633
Author: Rob Savoye <address@hidden>
Date:   Sun Jan 6 11:46:28 2019 -0700

    Add ownet and owfs modules

diff --git a/python/requirements.txt b/python/requirements.txt
index 49793d3..658fa3b 100644
--- a/python/requirements.txt
+++ b/python/requirements.txt
@@ -2,3 +2,5 @@ subprocess
 psycopg2
 logging
 glob
+pyownet
+pyowfs

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


commit ec628f3574ebc1908eb2fd132331bedea476b60d
Author: Rob Savoye <address@hidden>
Date:   Sun Jan 6 11:25:11 2019 -0700

    Change console format for different levels

diff --git a/python/pgd.py b/python/pgd.py
index aa48871..2ee8527 100755
--- a/python/pgd.py
+++ b/python/pgd.py
@@ -65,9 +65,9 @@ logging.basicConfig(
 # By default, print nothing to the console
 root = logging.getLogger()
 ch = logging.StreamHandler(sys.stdout)
+ch.setLevel(logging.CRITICAL)
 formatter = logging.Formatter('%(message)s')
 #formatter = logging.Formatter('{%(filename)s:%(lineno)d} - %(message)s')
-ch.setLevel(logging.CRITICAL)
 ch.setFormatter(formatter)
 root.addHandler(ch)
 verbosity = logging.CRITICAL
@@ -81,6 +81,8 @@ for (opt, val) in opts:
     elif opt == "--verbose" or opt == '-v':
         if verbosity == logging.INFO:
             verbosity = logging.DEBUG
+            formatter = logging.Formatter('{%(filename)s:%(lineno)d} 
%(levelname)s - %(message)s')
+            ch.setFormatter(formatter)
         if verbosity == logging.CRITICAL:
             verbosity = logging.INFO
 

http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=57270c1dc721579a7279cec298c78f78ce9da3ae


commit 57270c1dc721579a7279cec298c78f78ce9da3ae
Author: Rob Savoye <address@hidden>
Date:   Sun Jan 6 11:17:08 2019 -0700

    Support multiple levels of verbosity to the console

diff --git a/python/pgd.py b/python/pgd.py
index a4d86ac..aa48871 100755
--- a/python/pgd.py
+++ b/python/pgd.py
@@ -58,10 +58,19 @@ options['dbserver'] = val
 logging.basicConfig(
     filename='pgdpy.log',
     filemode='w',
-    level=logging.INFO,
+    level=logging.DEBUG,
     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
+root = logging.getLogger()
+ch = logging.StreamHandler(sys.stdout)
+formatter = logging.Formatter('%(message)s')
+#formatter = logging.Formatter('{%(filename)s:%(lineno)d} - %(message)s')
+ch.setLevel(logging.CRITICAL)
+ch.setFormatter(formatter)
+root.addHandler(ch)
+verbosity = logging.CRITICAL
 for (opt, val) in opts:
     if opt == '--help' or opt == '-h':
         usage(argv)
@@ -70,15 +79,12 @@ for (opt, val) in opts:
     elif opt == "--dbserver" or opt == '-d':
         options['dbserver'] = val
     elif opt == "--verbose" or opt == '-v':
-        root = logging.getLogger()
-        root.setLevel(logging.DEBUG)
-
-        ch = logging.StreamHandler(sys.stdout)
-        ch.setLevel(logging.DEBUG)
-        formatter = logging.Formatter('{%(filename)s:%(lineno)d} - 
%(levelname)s - %(message)s')
-        ch.setFormatter(formatter)
-        root.addHandler(ch)
+        if verbosity == logging.INFO:
+            verbosity = logging.DEBUG
+        if verbosity == logging.CRITICAL:
+            verbosity = logging.INFO
 
+ch.setLevel(verbosity)
 #
 # Start the I/O threads
 #

http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=696dde1d63b81a9affb62fc919e97ea9c69eaa83


commit 696dde1d63b81a9affb62fc919e97ea9c69eaa83
Author: Rob Savoye <address@hidden>
Date:   Sun Jan 6 10:16:06 2019 -0700

    Add getopt, add logging

diff --git a/python/pgd.py b/python/pgd.py
new file mode 100755
index 0000000..a4d86ac
--- /dev/null
+++ b/python/pgd.py
@@ -0,0 +1,98 @@
+#!/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
+import getopt
+import sys
+import ownet
+import onewire
+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]))
+
+
+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
+        """)
+    quit()
+
+try:
+    (opts, val) = getopt.getopt(argv[1:], "h,w:,d:,v,",
+           ["help", "owserver", "dbserver", "verbose"])
+except getopt.GetoptError as e:
+    logging.error('%r' % e)
+    self.usage(argv)
+    quit()
+
+# Store command line options
+options = dict()
+options['owserver'] = val
+options['dbserver'] = val
+logging.basicConfig(
+    filename='pgdpy.log',
+    filemode='w',
+    level=logging.INFO,
+    format= '[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s - 
%(message)s',
+     datefmt='%Y-%m-%d %H:%M:%S'
+)
+for (opt, val) in opts:
+    if opt == '--help' or opt == '-h':
+        usage(argv)
+    elif opt == "--owserver" or opt == '-w':
+        options['owserver'] = val
+    elif opt == "--dbserver" or opt == '-d':
+        options['dbserver'] = val
+    elif opt == "--verbose" or opt == '-v':
+        root = logging.getLogger()
+        root.setLevel(logging.DEBUG)
+
+        ch = logging.StreamHandler(sys.stdout)
+        ch.setLevel(logging.DEBUG)
+        formatter = logging.Formatter('{%(filename)s:%(lineno)d} - 
%(levelname)s - %(message)s')
+        ch.setFormatter(formatter)
+        root.addHandler(ch)
+
+#
+# Start the I/O threads
+#
+ownet_thread = Thread(target = ownet.ownet_handler, args = 
(options['owserver'], ))
+ownet_thread.start()
+onewire_thread = Thread(target = onewire.onewire_handler, args = (10, ))
+onewire_thread.start()
+
+#
+# Join the I/O threads as we're done.
+#
+ownet_thread.join()
+print("ownet_thread finished...exiting")
+
+onewire_thread.join()
+print("onewire_thread finished...exiting")
+

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


commit ffea8a32acfe3b58b7c3fe0267833a804fccb6d5
Author: Rob Savoye <address@hidden>
Date:   Sat Jan 5 14:43:22 2019 -0700

    Rename file

diff --git a/python/pgdb.py b/python/postgresql.py
old mode 100644
new mode 100755
similarity index 71%
rename from python/pgdb.py
rename to python/postgresql.py
index 4a8c3d6..1738599
--- a/python/pgdb.py
+++ b/python/postgresql.py
@@ -21,23 +21,19 @@ import pdb
 import glob
 import psycopg2
 import subprocess
-import config
 import logging
 
-## \class pgdb
-# A class to work with a postgresql database
-class pgdb(object):
-    """PostgreSQL database class."""
-    def __init__(self, config):
-        self.config = config
+
+class postgresql(object):
+    """A class to work with a postgresql database"""
+    def __init__(self):
         self.dbname = ""
         self.result = ""
-        # self.config.dump()
 
     def connect(self, dbname):
-        '''Connect to a postgresql server'''
+        """Connect to a postgresql server"""
         logging.debug("plotcalls.connect(" + dbname + ")")
-        self.config.set('dbname', dbname)
+        self.dbname = "";
         connect = " dbname=" + dbname
         
         try:
@@ -54,8 +50,8 @@ class pgdb(object):
             print("Couldn't connect to database: %r" % e)
 
     def query(self, query, nores=""):
-        '''Query a postgresql database'''
-        logging.debug("plotcalls.query(" + query + ")")
+        """Query a postgresql database"""
+        logging.debug("pgdb.query(" + query + ")")
         try:
             self.dbcursor.execute(query)
             self.result = self.dbcursor.fetchall()
@@ -65,22 +61,6 @@ class pgdb(object):
         nores = self.result
         return self.result
 
-    def shell(self, cmd):
-        cmdline = list()
-        cmdline.append("psql")
-        if len(self.config.get('dbname')) > 0:
-            cmdline.append("--dbname=" + str(self.config.get('dbname')))
-        cmdline.append("--command=" + cmd)
-        self.verbose.log(cmdline)
-        try:
-            subprocess.call(cmdline, stdout=subprocess.DEVNULL)
-            out = True
-        except:
-            self.verbose.warning("Couldn't list function: %r" % func)
-            out = False
-            
-        return out
-
     def dump(self):
         print("Dumping data from pgdb class")
         self.list_functions()

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

Summary of changes:
 python/ownet.py                   | 103 ++++++++++++++++++++++++++++++++++++
 python/pgd.py                     | 106 ++++++++++++++++++++++++++++++++++++++
 python/{pgdb.py => postgresql.py} |  36 +++----------
 python/requirements.txt           |   2 +
 4 files changed, 219 insertions(+), 28 deletions(-)
 create mode 100755 python/ownet.py
 create mode 100755 python/pgd.py
 rename python/{pgdb.py => postgresql.py} (71%)
 mode change 100644 => 100755


hooks/post-receive
-- 
powerguru



reply via email to

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