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. a4374d1ef0c1


From: Rob Savoye
Subject: [Powerguru-commit] [SCM] powerguru branch, master, updated. a4374d1ef0c1c26b501e2d2d959fdea16fbb920e
Date: Mon, 18 Feb 2019 16:49:07 -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  a4374d1ef0c1c26b501e2d2d959fdea16fbb920e (commit)
       via  559e72085812bf327719e4fb15caedfb1d46c8a3 (commit)
       via  ed8058e2ccfe0527f2c8cc534e6c81c4c9495fa1 (commit)
       via  836cd08c36ad5da19244b3d6289f02e1cff2c79b (commit)
       via  f35983cbed20a3c8f4bfaa95bd49665c1897d6cd (commit)
       via  27f4218e8481500684667b95935dfdbace7db8bb (commit)
       via  553a82f966a01b3a59c89368be69e86bac0db1cf (commit)
       via  8d0a23092aaa1d74de6017952bf04e82558e8bea (commit)
       via  fe0f4a8eba59eb38d93de4cdb2506409ba2868a4 (commit)
       via  b3e6be7febda439e04973e8bc1d9375ab97e2b7d (commit)
       via  ecbb83aaf012e856e556cbb3053301472e849be1 (commit)
       via  5dfa375f931a0b90691a5c0dcb2941616d552d25 (commit)
       via  564571484f199c00c39146c8edec9b54e32b4fa1 (commit)
       via  7d42065236eb63dfa9dba230f36bf12c69ab51aa (commit)
       via  1976be532c08f3c404b215c0d7825a7b6cdfc3e8 (commit)
      from  b9ee84ecf5f346226796ff920112c5d9c25e9a7c (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=a4374d1ef0c1c26b501e2d2d959fdea16fbb920e


commit a4374d1ef0c1c26b501e2d2d959fdea16fbb920e
Author: Rob Savoye <address@hidden>
Date:   Mon Feb 18 14:48:25 2019 -0700

    Use tuple to convert enum formats

diff --git a/python/sensor.py b/python/sensor.py
index 5eb211c..1ac3d68 100755
--- a/python/sensor.py
+++ b/python/sensor.py
@@ -37,6 +37,7 @@ class SensorType(Enum):
     TEMPERATURE = 7
     MOISTURE = 8
     UNSUPPORTED = 9
+sensorStrings= ('UNKNOWN', 'ACVOLTAGE', 'DCVOLTAGE', 'AUTH', 'BATTERY', 
'POWER', 'CLOCK', 'TEMPERATURE', 'MOISTURE', 'UNSUPPORTED' )
 
 class DeviceType(Enum):
     UNKNOWN = 0
@@ -48,6 +49,7 @@ class DeviceType(Enum):
     SERIAL = 6
     GPIO = 7
 
+deviceStrings = ('UNNOWN', 'ONEWIRE', 'OWNET', 'RTL433', 'RTLSDR', 'USB', 
'SERIAL', 'GPIO')
 
 class Sensors(object):
     """Data about all the sensors"""
@@ -90,7 +92,13 @@ class Sensors(object):
                 data['channel'] = channel
             self.sensors[id] = SensorDevice(data)
 
-    def dump(self):
+    def makeXML(self, xml=""):
+        """Create an XML string of all the sensor data"""
+        for id,sensor in self.sensors.items():
+            xml += sensor.makeXML()
+        return xml
+
+    def dump(self, result=""):
         logging.debug("Sensor.dump(%r entries)" % len(self.sensors))
         for id,sensor in self.sensors.items():
             sensor.dump()
@@ -150,89 +158,24 @@ class SensorDevice(object):
         else:
             logging.warning("Key %r doesn't exist in data structure" % index)
 
+    def makeXML(self, xml=""):
+        """Convert data about each sensor into XML for the remote API"""
+        
xml="""<ID>%r</ID><ALIAS>%r</ALIAS><LOCATION>%r</LOCATION><CHANNEL>%r</CHANNEL><DEVICE>%r</DEVICE><SENSOR>%r</SENSOR>"""
 % (self.data['id'], self.data['alias'], self.data['location'], 
self.data['channel'], self.data['device'], self.data['sensor'])
+        return xml
+
     def dump(self):
         """ Dump the data about this sensor"""
         print("ID: %r" % self.data['id'])
         print("\tAlias: %r" % self.data['alias'])
         print("\tLocation: %r" % self.data['location'])
         print("\tChannel: %r" % self.data['channel'])
-        if self.data['device'] ==  DeviceType.UNKNOWN:
-            print("\tDevice: UNKNOWN")
-        elif self.data['device'] ==  DeviceType.ONEWIRE:
-            print("\tDevice: ONEWIRE")
-        elif self.data['device'] ==  DeviceType.OWNET:
-            print("\tDevice: OWNET")
-        elif self.data['device'] ==  DeviceType.RTL433:
-            print("\tDevice: RTL433")
-        elif self.data['device'] ==  DeviceType.RTLSDR:
-            print("\tDevice: RTLSDR")
-        elif self.data['device'] ==  DeviceType.USB:
-            print("\tDtevice: USB")
-        elif self.data['device'] ==  DeviceType.SERIAL:
-            print("\tDevice: SERIAL")
-        elif self.data['device'] ==  DeviceType.GPIO:
-            print("\tDevice: GPIO")
-
-        if self.data['sensor'] ==  SensorType.UNKNOWN:
-            print("\tSensor: UNKNOWN")
-        elif self.data['sensor'] ==  SensorType.ACVOLTAGE:
-            print("\tSensor: ACVOLTAGE")
-        elif self.data['sensor'] ==  SensorType.DCVOLTAGE:
-            print("\tSensor: DCVOLTAGE")
-        elif self.data['sensor'] ==  SensorType.AUTH:
-            print("\tSensor: AUTH")
-        elif self.data['sensor'] ==  SensorType.BATTERY:
-            print("\tSensor: BATTERY")
-        elif self.data['sensor'] ==  SensorType.POWER:
-            print("\tSensor: POWER")
-        elif self.data['sensor'] ==  SensorType.CLOCK:
-            print("\tSensor: CLOCK")
-        elif self.data['sensor'] ==  SensorType.TEMPERATURE:
-            print("\tSensor: TEMPERATURE")
-        elif self.data['sensor'] ==  SensorType.MOISTURE:
-            print("\tSensor: MOISTURE")
-        elif self.data['sensor'] ==  SensorType.UNSUPPORTED:
-            print("\tSensor: UNSUPPORTED")
+        print("\tDevice: %r" % self.data['device'])
+        print("\tSensor: %r" % self.data['sensor'])
 
     def MakeSQL(self):
         """ Format the SQL query to add this sensor"""
-        if self.data['device'] ==  DeviceType.UNKNOWN:
-            device = "UNKNOWN"
-        elif self.data['device'] ==  DeviceType.ONEWIRE:
-            device = "ONEWIRE"
-        elif self.data['device'] ==  DeviceType.OWNET:
-            device = "OWNET"
-        elif self.data['device'] ==  DeviceType.RTL433:
-            device = "RTL433"
-        elif self.data['device'] ==  DeviceType.RTLSDR:
-            device = "RTLSDR"
-        elif self.data['device'] ==  DeviceType.USB:
-            device = "USB"
-        elif self.data['device'] ==  DeviceType.SERIAL:
-            device = "SERIAL"
-        elif self.data['device'] ==  DeviceType.GPIO:
-            device = "GPIO"
-
-        if self.data['sensor'] ==  SensorType.UNKNOWN:
-            sensor = "UNKNOWN"
-        elif self.data['sensor'] ==  SensorType.ACVOLTAGE:
-            sensor = "ACVOLTAGE"
-        elif self.data['sensor'] ==  SensorType.DCVOLTAGE:
-            sensor = "DCVOLTAGE"
-        elif self.data['sensor'] ==  SensorType.AUTH:
-            sensor = "AUTH"
-        elif self.data['sensor'] ==  SensorType.BATTERY:
-            sensor = "BATTERY"
-        elif self.data['sensor'] ==  SensorType.POWER:
-            sensor = "POWER"
-        elif self.data['sensor'] ==  SensorType.CLOCK:
-            sensor = "CLOCK"
-        elif self.data['sensor'] ==  SensorType.TEMPERATURE:
-            sensor = "TEMPERATURE"
-        elif self.data['sensor'] ==  SensorType.MOISTURE:
-            sensor = "MOISTURE"
-        elif self.data['sensor'] ==  SensorType.UNSUPPORTED:
-            sensor = "UNSUPPORTED"
+        device = deviceStrings[self.data['device']]
+        sense = sensorStrings[self.data['sensor']]
 
         if self.data['channel'] is not None:
             channel = self.data['channel']
@@ -254,7 +197,7 @@ class SensorDevice(object):
         else:
             location = ""
 
-        query = """INSERT INTO sensors VALUES (%r, %r, %r, %r, %r, %r) ON 
CONFLICT DO NOTHING;""" % (id, alias, location, device, sensor, channel)
+        query = """INSERT INTO sensors VALUES (%r, %r, %r, %r, %r, %r) ON 
CONFLICT DO NOTHING;""" % (id, alias, location, device, sense, channel)
 
         logging.debug(query)
         return (query)

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


commit 559e72085812bf327719e4fb15caedfb1d46c8a3
Author: Rob Savoye <address@hidden>
Date:   Mon Feb 18 14:45:59 2019 -0700

    Add sensors to handler parameters, use POWER instead of BATTERY

diff --git a/python/ownet.py b/python/ownet.py
index dabedfc..83d5cdb 100755
--- a/python/ownet.py
+++ b/python/ownet.py
@@ -25,8 +25,9 @@ import time
 from pyownet import protocol
 import onewire
 import psycopg2
+import sensor
 
-def ownet_handler(args):
+def ownet_handler(args, sensors):
     logging.debug("Start ownet %r" % args)
 
     # Connect to a postgresql database
@@ -82,6 +83,7 @@ def ownet_handler(args):
                 sensor['family'] = family
                 id = owproxy.read(dir + 'id').decode("utf-8")
                 sensor['id'] = id;
+                #sensor['id'] = id[10:12] + id[8:10] + id[6:8] + id[4:6] + 
id[2:4] + id[0:2]
                 sensor['alias'] = owproxy.read(dir + 'alias').decode("utf-8")
                 sensor['type'] = onewire._family[family]['type']
                 sensor['chips'] = owproxy.read(dir + 'type').decode("utf-8")
@@ -131,7 +133,7 @@ def ownet_handler(args):
                 dbcursor.execute(query)
                 # id | temperature | temphigh | templow | scale | timestamp
  
-            if sensor['type'] == 'BATTERY':
+            if sensor['type'] == 'POWER':
                 # logging.info("Found a power monitor sensor: " + family + '.' 
+ id)
                 batt = dict()
                 try:

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


commit ed8058e2ccfe0527f2c8cc534e6c81c4c9495fa1
Author: Rob Savoye <address@hidden>
Date:   Mon Feb 18 14:44:59 2019 -0700

    drop debug breakpoint

diff --git a/python/chart.py b/python/chart.py
index 3fef65d..bbfa195 100755
--- a/python/chart.py
+++ b/python/chart.py
@@ -123,7 +123,6 @@ ch.setLevel(verbosity)
 delta = 0
 dbname = ""
 connect = ""
-epdb.set_trace()
 if options['dbserver'] is "localhost":
     connect += " dbname='" + options['dbname'] + "'"
 else:

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


commit 836cd08c36ad5da19244b3d6289f02e1cff2c79b
Author: Rob Savoye <address@hidden>
Date:   Mon Feb 18 14:44:19 2019 -0700

    Add remote client API

diff --git a/python/remote.py b/python/remote.py
new file mode 100644
index 0000000..9b5feab
--- /dev/null
+++ b/python/remote.py
@@ -0,0 +1,105 @@
+#!/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 socketserver
+from lxml import etree
+from lxml.etree import tostring
+import sensor
+
+
+class client_handler(socketserver.BaseRequestHandler):
+    """Create Server for client requests"""
+    
+    def handle(self):
+        while True:
+            # self.request is the TCP socket connected to the client
+            self.data = self.request.recv(1024).strip()
+            self.clientip = self.client_address[0]
+            logging.info("{} wrote:".format(self.clientip))
+            #logging.debug(self.data)
+            # If no data, the client dropped the network connection.
+            # Return and this handler will ge restarted for the next
+            # incoming connection.
+            if len(self.data) == 0:
+                return
+            
+            # Data is returned as unicode bytes, so must be decoded
+            # to do string compares.
+            if self.data.decode('utf8')[0] != '<':
+                logging.warning("Not XML data!")
+                continue
+
+            xml = etree.XML(self.data)
+            logging.debug("Got XML: %r" % etree.tostring(xml))
+
+            tag = xml.tag.upper()
+            # These are the allowable top level XML tags
+            if tag == "LIST":
+                logging.debug("LIST: %r" % xml.text)
+                # if no children, default to quering all sensors
+                if len(xml) == 0:
+                    self.list_command(xml.text)
+                else:
+                    if xml[0].tag.upper() == "SENSORS":
+                        self.list_command(xml[0].text)
+            elif tag == "NOP":
+                logging.debug("NOP: %r" % xml.text)
+            elif tag == "HELO":
+                logging.debug("HELO: %r" % xml.text)
+            elif tag == "POLL":
+                logging.debug("POLL: %r" % xml.text)
+            elif tag == "EVENT":
+                logging.debug("EVENT: %r" % xml.text)
+                self.event_command(xml.text)
+            else:
+                logging.error("Tag %r not supported!" % tag)
+                #return
+
+            if len(xml) > 0:
+                logging.debug("Has chidren")
+                for child in xml:
+                    logging.debug("Child tag: %r: %r" % (child.tag, 
child.text))
+                    if child.tag == "StopIteration":
+                        logging.debug("All Done!")
+                    if len(child) > 0:
+                        logging.debug("Has chidren")
+                        for subchild in child:
+                            logging.debug("SubChild tag: %r: %r" % 
(subchild.tag, subchild.text))
+                            if subchild.tag == "StopIteration":
+                                logging.debug("All Done!")
+
+    def list_command(self, text=""):
+        """List all the sensors attached to this daemon"""
+        logging.debug("LIST command: %r" % text)
+        if text is None or text.upper() == "ALL":
+            xmldata = sensor.Sensors().makeXML()
+            logging.debug("XMLDATA: %r" % xmldata)
+        else:
+            if sensor.Sensors().get(text) != None:
+                xmldata = sensor.Sensors().get(text).makeXML()
+            else:
+                logging.error("Bad sensor ID %r!" % text)
+        self.request.sendall(xmldata.encode('utf-8'))
+
+    def event_command(self):
+        logging.debug("EVENT command")
+

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


commit f35983cbed20a3c8f4bfaa95bd49665c1897d6cd
Author: Rob Savoye <address@hidden>
Date:   Mon Feb 18 14:44:01 2019 -0700

    Make gpio and i2c sensors PI only. Start remote client support

diff --git a/python/pgd.py b/python/pgd.py
index f83f257..a9760a5 100755
--- a/python/pgd.py
+++ b/python/pgd.py
@@ -34,6 +34,8 @@ import psycopg2
 import sensor
 import platform
 import i2c
+import remote
+import socketserver
 
 
 # Setup default command line options
@@ -111,6 +113,25 @@ for (opt, val) in opts:
 
 ch.setLevel(verbosity)
 
+#
+# See if we're running on a Raspberry PI, since other platforms
+# don't have GPIO pins.
+#
+try:
+    file = open("/etc/issue", "r")
+except Exception as inst:
+    logging.error("Couldn't open /etc/issue: %r" % inst)
+issue = file.readlines()
+on = issue[0].split(' ')
+if on[0] == "Raspbian":
+    pi = True
+else:
+    pi = False
+logging.info("Running on %r" % on[0])
+
+#
+# Collect the data about the connected sensors
+#
 sensors = sensor.Sensors()
 sensors.dump()
 
@@ -123,8 +144,8 @@ ownet_thread = Thread(target=ownet.ownet_handler, 
args=(options, sensors))
 ownet_thread.start()
 
 # OWFS filesystem
-onewire_thread = Thread(target = onewire.onewire_handler, args = (options, ))
-onewire_thread.start()
+#onewire_thread = Thread(target = onewire.onewire_handler, args = (options, ))
+#onewire_thread.start()
 
 # rtl_433 filesystem
 rtl433_thread = Thread(target = rtl433.rtl433_handler, args = (options, 
sensors,))
@@ -135,19 +156,31 @@ rtlsdr_thread = Thread(target = rtlsdr.rtlsdr_handler, 
args = (options, sensors)
 rtlsdr_thread.start()
 
 # GPIO only works on a Raspberry PI
-#if platform.machine is "armv7l":
-import gpio433
-gpio433_thread = Thread(target = gpio433.gpio433_handler, args = (options, 
sensors))
-gpio433_thread.start()
-
-i2c_thread = Thread(target = i2c.ina219_handler, args = (options, sensors))
-i2c_thread.start()
-
-gpio433_thread.join()
-print("gpio433_thread finished...exiting")
-
-i2c_thread.join()
-print("i2c_thread finished...exiting")
+if pi is True:
+    import gpio433
+    gpio433_thread = Thread(target = gpio433.gpio433_handler, args = (options, 
sensors))
+    gpio433_thread.start()
+
+    i2c_thread = Thread(target = i2c.ina219_handler, args = (options, sensors))
+    i2c_thread.start()
+
+# NOTE that this only handles a single connection at a time
+with socketserver.TCPServer(("0.0.0.0", 7654), remote.client_handler) as 
server:
+    # Activate the server; this will keep running until you
+    # interrupt the program with Ctrl-C
+    server.allow_reuse_address = True
+    try:
+        server.serve_forever()
+    except KeyboardInterrupt:
+        server.shutdown()
+        server.socket.close()
+
+if pi is True:
+    gpio433_thread.join()
+    print("gpio433_thread finished...exiting")
+
+    i2c_thread.join()
+    print("i2c_thread finished...exiting")
 
 #
 # Join the I/O threads as we're done.
@@ -155,8 +188,8 @@ print("i2c_thread finished...exiting")
 ownet_thread.join()
 print("ownet_thread finished...exiting")
 
-onewire_thread.join()
-print("onewire_thread finished...exiting")
+#onewire_thread.join()
+#print("onewire_thread finished...exiting")
 
 rtl433_thread.join()
 print("rtl433_thread finished...exiting")

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


commit 27f4218e8481500684667b95935dfdbace7db8bb
Author: Rob Savoye <address@hidden>
Date:   Wed Feb 13 20:42:17 2019 -0700

    Add new threads under development, gpio, rtlsdr, i2c

diff --git a/python/pgd.py b/python/pgd.py
index ff7211d..f83f257 100755
--- a/python/pgd.py
+++ b/python/pgd.py
@@ -32,6 +32,9 @@ from sys import argv
 import psycopg2
 #from sensor import Sensor
 import sensor
+import platform
+import i2c
+
 
 # Setup default command line options
 options = dict()
@@ -116,21 +119,36 @@ sensors.dump()
 #
 
 # OWFS network protocol
-ownet_thread = Thread(target=ownet.ownet_handler, args=(options, ))
+ownet_thread = Thread(target=ownet.ownet_handler, args=(options, sensors))
 ownet_thread.start()
 
 # OWFS filesystem
-onewire_thread = Thread(target = onewire.onewire_handler, args = (10, ))
+onewire_thread = Thread(target = onewire.onewire_handler, args = (options, ))
 onewire_thread.start()
 
 # rtl_433 filesystem
 rtl433_thread = Thread(target = rtl433.rtl433_handler, args = (options, 
sensors,))
 rtl433_thread.start()
 
-# rtl_sdr filesystem
-rtlsdr_thread = Thread(target = rtlsdr.rtlsdr_handler, args = (options, ))
+# rtl_sdr
+rtlsdr_thread = Thread(target = rtlsdr.rtlsdr_handler, args = (options, 
sensors))
 rtlsdr_thread.start()
 
+# GPIO only works on a Raspberry PI
+#if platform.machine is "armv7l":
+import gpio433
+gpio433_thread = Thread(target = gpio433.gpio433_handler, args = (options, 
sensors))
+gpio433_thread.start()
+
+i2c_thread = Thread(target = i2c.ina219_handler, args = (options, sensors))
+i2c_thread.start()
+
+gpio433_thread.join()
+print("gpio433_thread finished...exiting")
+
+i2c_thread.join()
+print("i2c_thread finished...exiting")
+
 #
 # Join the I/O threads as we're done.
 #

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


commit 553a82f966a01b3a59c89368be69e86bac0db1cf
Author: Rob Savoye <address@hidden>
Date:   Wed Feb 13 20:41:33 2019 -0700

    Read volts and current from an ina219 sensor

diff --git a/python/i2c.py b/python/i2c.py
index e198a70..d0ac980 100644
--- a/python/i2c.py
+++ b/python/i2c.py
@@ -45,21 +45,23 @@ def ina219_handler(options, sensors):
             if dbcursor.closed == 0:
                 logging.info("Opened cursor in %r" % dbname)
                 
-            while True:
-                try:
-                    print('Bus Voltage: {0:0.2f}V'.format(ina.voltage()))
-                    print('Bus Current: {0:0.2f}mA'.format(ina.current()))
-                    print('Power: {0:0.2f}mW'.format(ina.power()))
-                    print('Shunt Voltage: 
{0:0.2f}mV\n'.format(ina.shunt_voltage()))
-                except DeviceRangeError as e:
-                    # Current out of device range with specified shunt resister
-                    print(e)
-
-                id = "XXXXX"
-                query = """INSERT INTO power VALUES( '%s', %s, %s, '%s', '%s' 
)  ON CONFLICT DO NOTHING;; """ % (id, ina.current(), ina.voltage(), 'DC', 
time.strftime("%Y-%m-%d %H:%M:%S"))
-                logging.debug(query)
-                dbcursor.execute(query)
-                time.sleep(10)
     except Exception as e:
         logging.warning("Couldn't connect to database: %r" % e)
-        
+
+    while True:
+        try:
+            print('Bus Voltage: {0:0.2f}V'.format(ina.voltage()))
+            print('Bus Current: {0:0.2f}mA'.format(ina.current()))
+            print('Power: {0:0.2f}mW'.format(ina.power()))
+            print('Shunt Voltage: {0:0.2f}mV\n'.format(ina.shunt_voltage()))
+
+            id = "XXXXX"
+            query = """INSERT INTO power VALUES( '%s', %s, %s, 'DC', '%s' )  
ON CONFLICT DO NOTHING;; """ % (id, ina.current(), ina.voltage(), 
time.strftime("%Y-%m-%d %H:%M:%S"))
+        except DeviceRangeError as e:
+            # Current out of device range with specified shunt resister
+            print(e)
+        logging.debug(query)
+        dbcursor.execute(query)
+        time.sleep(100)
+        #time.sleep(options['interval'])
+

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


commit 8d0a23092aaa1d74de6017952bf04e82558e8bea
Author: Rob Savoye <address@hidden>
Date:   Wed Feb 13 19:17:00 2019 -0700

    Read from ina219 sensor

diff --git a/python/i2c.py b/python/i2c.py
new file mode 100644
index 0000000..e198a70
--- /dev/null
+++ b/python/i2c.py
@@ -0,0 +1,65 @@
+#!/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 psycopg2
+from ina219 import INA219, DeviceRangeError
+import time
+
+def ina219_handler(options, sensors):
+    logging.debug("Start rtl_sdr %r" % options)
+
+    SHUNT_OHMS = 0.1
+    MAX_EXPECTED_AMPS = 2.0
+    ina = INA219(SHUNT_OHMS, MAX_EXPECTED_AMPS)
+    ina.configure(ina.RANGE_16V)
+
+    # Connect to a postgresql database
+    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)
+                
+            while True:
+                try:
+                    print('Bus Voltage: {0:0.2f}V'.format(ina.voltage()))
+                    print('Bus Current: {0:0.2f}mA'.format(ina.current()))
+                    print('Power: {0:0.2f}mW'.format(ina.power()))
+                    print('Shunt Voltage: 
{0:0.2f}mV\n'.format(ina.shunt_voltage()))
+                except DeviceRangeError as e:
+                    # Current out of device range with specified shunt resister
+                    print(e)
+
+                id = "XXXXX"
+                query = """INSERT INTO power VALUES( '%s', %s, %s, '%s', '%s' 
)  ON CONFLICT DO NOTHING;; """ % (id, ina.current(), ina.voltage(), 'DC', 
time.strftime("%Y-%m-%d %H:%M:%S"))
+                logging.debug(query)
+                dbcursor.execute(query)
+                time.sleep(10)
+    except Exception as e:
+        logging.warning("Couldn't connect to database: %r" % e)
+        

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


commit fe0f4a8eba59eb38d93de4cdb2506409ba2868a4
Author: Rob Savoye <address@hidden>
Date:   Wed Feb 13 13:07:41 2019 -0700

    fix handling of -s option, add legend

diff --git a/python/chart.py b/python/chart.py
index 9bbf04f..3fef65d 100755
--- a/python/chart.py
+++ b/python/chart.py
@@ -35,11 +35,12 @@ import numpy as np
 import getopt
 import sys
 from sys import argv
+import sensor
 
 # http://initd.org/psycopg/docs/
 
 options = dict()
-options['dbserver'] = "pi"  # hostname of the database
+options['dbserver'] = "localhost"  # hostname of the database
 options['dbname'] = "powerguru"  # hostname of the database
 options['interval'] = 100        # interval in seconds between data updates
 options['starttime'] = ""
@@ -64,7 +65,7 @@ def usage(argv):
 
 # Check command line arguments
 try:
-    (opts, val) = getopt.getopt(argv[1:], "h,d:,s;v,i:,t:,e:",
+    (opts, val) = getopt.getopt(argv[1:], "h,d:,s:,,v,i:,t:,e:",
            ["help", "database", "dbserver", "verbose", "interval", 
"starttime", "endtime"])
 except getopt.GetoptError as e:
     logging.error('%r' % e)
@@ -92,7 +93,7 @@ formatter = logging.Formatter('%(message)s')
 #formatter = logging.Formatter('{%(filename)s:%(lineno)d} - %(message)s')
 ch.setFormatter(formatter)
 root.addHandler(ch)
-terminator = ch.terminator
+#terminator = ch.terminator
 verbosity = logging.CRITICAL
 
 # process command line arguments, will override the defaults
@@ -122,9 +123,12 @@ ch.setLevel(verbosity)
 delta = 0
 dbname = ""
 connect = ""
-if options['dbserver'] != "localhost":
-    connect = "host='" + options['dbserver'] + "'"
-connect += " dbname='" + options['dbname'] + "'"
+epdb.set_trace()
+if options['dbserver'] is "localhost":
+    connect += " dbname='" + options['dbname'] + "'"
+else:
+    connect += "host='" + options['dbserver'] + "'"
+    connect += " dbname='" + options['dbname'] + "'"
 
 logging.debug(connect)
 dbshell = psycopg2.connect(connect)
@@ -142,6 +146,9 @@ if dbcursor.closed != 0:
 
 logging.info("Opened cursor in %r" % options['dbserver'])
 
+# Get the data on each sensor
+sensors = sensor.Sensors()
+
 # Setup optional timestamp filter
 start = ""
 end = ""
@@ -152,16 +159,29 @@ elif options['endtime'] != "" and options['starttime'] != 
"":
     if options['endtime'] != "" and options['starttime'] == "":
         end = " AND timestamp<=%r" % options['endtime']
 
-# Create the two subslots
-fig, (temp, dcvolts, amps) = plt.subplots(3, 1, sharex=True)
+# Create the subslots
+fig, (temp) = plt.subplots(1, 1, sharex=True)
+#fig, (temp, humidity) = plt.subplots(2, 1, sharex=True)
+#fig, (temp, dcvolts, amps) = plt.subplots(3, 1, sharex=True)
 plt.subplots_adjust(top=0.88, bottom=0.20, left=0.10, right=0.95, hspace=0.58,
                     wspace=0.35)
 
+
+# https://matplotlib.org/gallery/color/named_colors.html
 colors = list()
 colors.append("red")
 colors.append("green")
 colors.append("blue")
+colors.append("orange")
+colors.append("cyan")
+colors.append("yellow")
 colors.append("black")
+colors.append("violet")
+colors.append("silver")
+colors.append("purple")
+colors.append("grey")
+colors.append("navy")
+
 def animate(i):
     logging.debug("Refreshing data...")
     ids = list()
@@ -179,6 +199,7 @@ def animate(i):
         logging.debug(query)
         dbcursor.execute(query)
         logging.debug("Query returned %r records" % dbcursor.rowcount)
+
         x = list()
         y = list()
         for model,temperature,humidity,timestamp in dbcursor:
@@ -186,59 +207,66 @@ def animate(i):
             x.append(timestamp)
             y.append(temperature)
 
+        #sensors.dump()
+        #epdb.set_trace()
+        sense = sensors.get(id[0])
+        if sense != None:
+            location = sense.get('location')
+        else:
+            location = id[0]
         fig.suptitle('PowerGuru')
         temp.set_ylabel("Temperature in F")
         temp.set_title("Temperature")
         temp.grid(which='major', color='red')
         temp.grid(which='minor', color='blue', linestyle='dashed')
         temp.minorticks_on()
-        temp.plot(x, y, color=colors[cur], label=id[0])
         legend = temp.legend(loc='upper left', shadow=True)
+        temp.plot(x, y, color=colors[cur], label=location)
         cur += 1
-    
-    xx = list()
-    yy = list()
-    zz = list()
-    query = "SELECT DISTINCT id FROM power"
-    logging.debug(query)
-    dbcursor.execute(query)
-    logging.debug("Query returned %r records" % dbcursor.rowcount)
-    if  dbcursor.rowcount > 0:
-        for id in dbcursor:
-            ids.append(id)
-            query = "SELECT id,current,volts,timestamp FROM power WHERE 
(id='%s' %s %s) ORDER BY timestamp " % (id[0], start, end)
-            logging.debug(query)
-            dbcursor.execute(query)
-            logging.debug("Query returned %r records" % dbcursor.rowcount)
-            cur = 0
-            for id,current,voltage,timestamp in dbcursor:
-                #print("BATTERY: %r, %r, %r, %r" % (id, current, voltage, 
timestamp))
-                xx.append(timestamp)
-                yy.append(voltage)
-                zz.append(current)
 
-        dcvolts.set_title("DC Voltage")
-        dcvolts.plot(xx, yy, color="purple")
-        dcvolts.legend([id])
-        dcvolts.set_ylabel("DC Volts")
-        #dcvolts.set_xlabel("Time (hourly)")
-        dcvolts.grid(which='major', color='red')
-        dcvolts.grid(which='minor', color='blue', linestyle='dashed')
-        dcvolts.minorticks_on()
+    # xx = list()
+    # yy = list()
+    # zz = list()
+    # query = "SELECT DISTINCT id FROM power"
+    # logging.debug(query)
+    # dbcursor.execute(query)
+    # logging.debug("Query returned %r records" % dbcursor.rowcount)
+    # if  dbcursor.rowcount > 0:
+    #     for id in dbcursor:
+    #         ids.append(id)
+    #         query = "SELECT id,current,volts,timestamp FROM power WHERE 
(id='%s' %s %s) ORDER BY timestamp " % (id[0], start, end)
+    #         logging.debug(query)
+    #         dbcursor.execute(query)
+    #         logging.debug("Query returned %r records" % dbcursor.rowcount)
+    #         cur = 0
+    #         for id,current,voltage,timestamp in dbcursor:
+    #             #print("BATTERY: %r, %r, %r, %r" % (id, current, voltage, 
timestamp))
+    #             xx.append(timestamp)
+    #             yy.append(voltage)
+    #             zz.append(current)
+
+    #     dcvolts.set_title("DC Voltage")
+    #     dcvolts.plot(xx, yy, color="purple")
+    #     dcvolts.legend([id])
+    #     dcvolts.set_ylabel("DC Volts")
+    #     #dcvolts.set_xlabel("Time (hourly)")
+    #     dcvolts.grid(which='major', color='red')
+    #     dcvolts.grid(which='minor', color='blue', linestyle='dashed')
+    #     dcvolts.minorticks_on()
     
-        amps.set_title("DC Current")
-        amps.plot(xx, zz, color=colors[cur])
-        amps.legend([id])
-        cur += 1
-        amps.set_ylabel("Amps")
-        amps.set_xlabel("Time (hourly)")
-        amps.grid(which='major', color='red')
-        amps.grid(which='minor', color='blue', linestyle='dashed')
-        amps.minorticks_on()
-        plt.setp(amps.xaxis.get_majorticklabels(), rotation=90)
-        amps.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d %H'))
-        amps.xaxis.set_major_locator(mdates.HourLocator(byhour=range(0,24,6)))
-        amps.xaxis.set_minor_locator(mdates.HourLocator())
+    #     amps.set_title("DC Current")
+    #     amps.plot(xx, zz, color=colors[cur])
+    #     amps.legend([id])
+    #     cur += 1
+    #     amps.set_ylabel("Amps")
+    #     amps.set_xlabel("Time (hourly)")
+    #     amps.grid(which='major', color='red')
+    #     amps.grid(which='minor', color='blue', linestyle='dashed')
+    #     amps.minorticks_on()
+    #     plt.setp(amps.xaxis.get_majorticklabels(), rotation=90)
+    #     amps.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d %H'))
+    #     
amps.xaxis.set_major_locator(mdates.HourLocator(byhour=range(0,24,6)))
+    #     amps.xaxis.set_minor_locator(mdates.HourLocator())
 
     # Get the time delta between data samples, as it's not worth updating there
     # the display till their in fresh data. Sample may be minutes or hours 
apart,

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


commit b3e6be7febda439e04973e8bc1d9375ab97e2b7d
Author: Rob Savoye <address@hidden>
Date:   Tue Feb 12 10:35:49 2019 -0700

    When reading from /sys/, the ID is bigendian, so swap and capitalize it to 
match when ownet uses.

diff --git a/devices/onewire.cc b/devices/onewire.cc
index 1eb5cd8..41daaa1 100644
--- a/devices/onewire.cc
+++ b/devices/onewire.cc
@@ -18,10 +18,13 @@
 #include <boost/algorithm/string.hpp>
 #include <boost/filesystem.hpp>
 #include <boost/regex.hpp>
+#include <boost/endian/conversion.hpp>
 #include <iostream>
+#include <iomanip>
 #include <string>
 #include <map>
 #include <streambuf>
+#include <sstream>
 #include "onewire.h"
 #include "log.h"
 
@@ -206,7 +209,11 @@ Onewire::getTemperature(const std::string &device)
     std::string family = _sensors[device]->family;
     bool bus = _sensors[device]->bus;
     boost::shared_ptr<temperature_t> temp(new temperature_t);
-    temp->id = _sensors[device]->id;
+    // Data stored
+    int64_t idnum = std::stoll(_sensors[device]->id, 0, 16);
+    std::stringstream id;
+    id << std::hex << std::setw(12) << std::setfill('0') << 
boost::endian::endian_reverse(idnum << 16);
+    temp->id = boost::algorithm::to_upper_copy(id.str());
     std::string result;
     if (bus) {
         getValue(device, "w1_slave", result);

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


commit ecbb83aaf012e856e556cbb3053301472e849be1
Author: Rob Savoye <address@hidden>
Date:   Mon Feb 11 21:06:07 2019 -0700

    Battery table got rename to power

diff --git a/python/ownet.py b/python/ownet.py
index fa6faf3..dabedfc 100755
--- a/python/ownet.py
+++ b/python/ownet.py
@@ -46,8 +46,6 @@ def ownet_handler(args):
         logging.warning("Couldn't connect to database: %r" % e)
         
 
-    _sensors = list()
-
     # 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
@@ -62,8 +60,8 @@ def ownet_handler(args):
         retries -= 1
         # Get a list of all directories on the server
         try:
-            owproxy = protocol.proxy(host=args['owserver'], port=4304)
-            logging.error("Connected to OW server: %r" % args['owserver'])
+            owproxy = protocol.proxy(host=args['owserver'], port=4304, 
persistent=True)
+            logging.info("Connected to OW server: %r" % args['owserver'])
             owproxy.dir()
             break
         except Exception as e:
@@ -93,8 +91,7 @@ def ownet_handler(args):
                 time.sleep(1)   # give the server a second to recover
                 continue
 
-            logging.debug("%r" % sensor)
-            _sensors.append(sensor)
+            #logging.debug("%r" % sensor)
             # FIXME: format query and write to database
             # dbcursor.execute(query)
             # family | id | alias | type | timestamp
@@ -115,18 +112,22 @@ def ownet_handler(args):
                 # 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("
+                    temp['temperature'] = (float(temp['temperature']) * 1.8) + 
32.0
+                    if temp['lowtemp'] is not "0":
+                        temp['lowtemp'] =  (float(temp['lowtemp']) * 1.8) + 
32.0
+                    if temp['hightemp'] is not "0":
+                        temp['hightemp'] =  (float(temp['hightemp']) * 1.8) + 
32.0;
+                query = "INSERT INTO weather VALUES("
                 query += "'" + id + "'"
                 query += ", " + str(temp['temperature'])
                 query += ", " + str(temp['lowtemp'])
                 query += ", " + str(temp['hightemp'])
+                query += ", 0"
+                #query += ", " + str(temp['humidity'])
                 query += ", " + "'" + args['scale'] + "'"
                 query += ", '" + time.strftime("%Y-%m-%d %H:%M:%S") + "'"
                 query += ");"
-                logging.debug(query)
+                #logging.debug(query)
                 dbcursor.execute(query)
                 # id | temperature | temphigh | templow | scale | timestamp
  
@@ -143,14 +144,14 @@ def ownet_handler(args):
                     time.sleep(1)   # give the server a second to recover
                     continue
 
-                query = "INSERT INTO battery VALUES("
+                query = "INSERT INTO power VALUES("
                 query += "'" + id + "'"
                 query += ", " + batt['current']
                 query += ", " + batt['voltage']
                 query += ", 'DC'"
                 query += ", '" + time.strftime("%Y-%m-%d %H:%M:%S") + "'"
                 query += ");"
-                logging.debug(query)
+                #logging.debug(query)
                 dbcursor.execute(query)
                 # id | current | volts | type | timestamp
 

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


commit 5dfa375f931a0b90691a5c0dcb2941616d552d25
Author: Rob Savoye <address@hidden>
Date:   Mon Feb 11 21:05:13 2019 -0700

    Add humidity field change to weather table

diff --git a/python/mergedb.py b/python/mergedb.py
index bdf8c5e..2c0bbde 100755
--- a/python/mergedb.py
+++ b/python/mergedb.py
@@ -156,7 +156,7 @@ if options['starttime'] != "":
     start = "WHERE timestamp>=%r" % options['starttime']
 else:
     # Get the last entry
-    query = "SELECT timestamp FROM temperature ORDER BY timestamp DESC LIMIT 
1;"
+    query = "SELECT timestamp FROM weather ORDER BY timestamp DESC LIMIT 1;"
     logging.debug(query)
     destcursor.execute(query)
     last = destcursor.fetchone()
@@ -173,25 +173,26 @@ else:
     end = ""
 
 # FIXME: Add LIMIT if we need to transfer data by blocks
-query = """SELECT * FROM temperature %s %s ORDER BY timestamp;""" % (start, 
end)
+query = """SELECT * FROM weather %s %s ORDER BY timestamp;""" % (start, end)
 logging.debug(query)
 srccursor.execute(query)
 temps = dict()
 data = list()
 # Store the returned data
 logging.debug("Got %r records" % srccursor.rowcount)
-for id,temperature,temphigh,templow,scale,timestamp in srccursor:
+for id,temperature,temphigh,templow,humidity,scale,timestamp in srccursor:
     temps['id'] = id
     temps['temperature'] = temperature
     temps['temphigh'] = temphigh
     temps['templow'] = templow
+    temps['humidity'] = humidity
     temps['scale'] = scale
     temps['timestamp'] = timestamp
     #print("%r" % temps)
     data.append(temps)
     #INSERT INTO datas () VALUES 
('$data','$notes','$sortname','$listname','$url')";
 
-    query = """INSERT INTO temperature VALUES (%r, '%r', '%r', '%r', %r, %r) 
ON CONFLICT DO NOTHING;""" % (id, temperature, temphigh, templow, scale,
+    query = """INSERT INTO weather VALUES (%r, '%r', '%r', '%r', %r, %r, %r) 
ON CONFLICT DO NOTHING;""" % (id, temperature, temphigh, templow, humidity, 
scale,
                              timestamp.strftime("%Y-%m-%d %H:%M:%S"))
     logging.debug("Dest query: %r" % query)
     logging.debug("Dest status: %r" % destcursor.statusmessage)

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


commit 564571484f199c00c39146c8edec9b54e32b4fa1
Author: Rob Savoye <address@hidden>
Date:   Mon Feb 11 21:03:51 2019 -0700

    More minor changes to the enums and sensor table

diff --git a/powerguru.sql b/powerguru.sql
index 1a9f6a8..b6389d3 100644
--- a/powerguru.sql
+++ b/powerguru.sql
@@ -36,9 +36,11 @@
 --
 DROP TYPE IF EXISTS channel_type;
 CREATE TYPE public.channel_type AS ENUM (
+    '',
     'A',
     'B',
-    'C'
+    'C',
+    'X'
 );
 
 DROP TYPE IF EXISTS volt_type;
@@ -49,14 +51,14 @@ CREATE TYPE public.volt_type AS ENUM (
 
 DROP TYPE IF EXISTS device_type;
 CREATE TYPE public.device_type AS ENUM (
-    'unknown',
-    'onewire',
-    'ownet',
-    'rtl433',
-    'rtlsdr',
-    'usb',
-    'serial',
-    'gpio'
+    'UNKNOWN',
+    'ONEWIRE',
+    'OWNET',
+    'RTL433',
+    'RTLSDR',
+    'USB',
+    'SERIAL',
+    'GPIO'
 );
 
 DROP TYPE IF EXISTS sensor_type;
@@ -95,18 +97,18 @@ CREATE TABLE meters (
   battery_tempcomp float NOT NULL default '0'
 );
 
-DROP TABLE IF EXISTS sensor;
-CREATE TABLE sensor (
+DROP TABLE IF EXISTS sensors;
+CREATE TABLE sensors (
   id varchar(12) NOT NULL default '0',
-  alias varchar(12) NOT NULL default '0',
-  location varchar(12) NOT NULL default '0',
-  device device_type NOT NULL default '1wire',
-  type sensor_type NOT NULL default 'UNKNOWN',
+  alias varchar(24) NOT NULL default '0',
+  location varchar(24) NOT NULL default '0',
+  device device_type NOT NULL default 'ONEWIRE',
+  sensor sensor_type NOT NULL default 'UNKNOWN',
   channel channel_type NOT NULL default 'A'
 );
 
-DROP TABLE IF EXISTS temperature;
-CREATE TABLE temperature (
+DROP TABLE IF EXISTS weather;
+CREATE TABLE weather (
   id varchar(12) NOT NULL default '0',
   temperature float NOT NULL default '0',
   temphigh float NOT NULL default '0',

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


commit 7d42065236eb63dfa9dba230f36bf12c69ab51aa
Author: Rob Savoye <address@hidden>
Date:   Mon Feb 11 17:52:33 2019 -0700

    Add support for new Sensor class

diff --git a/python/pgd.py b/python/pgd.py
index ff92bec..ff7211d 100755
--- a/python/pgd.py
+++ b/python/pgd.py
@@ -22,11 +22,16 @@ import epdb
 import logging
 import getopt
 import sys
+import rtlsdr
+import rtl433
 import ownet
 import onewire
 from threading import Thread
 from time import sleep
 from sys import argv
+import psycopg2
+#from sensor import Sensor
+import sensor
 
 # Setup default command line options
 options = dict()
@@ -103,6 +108,9 @@ for (opt, val) in opts:
 
 ch.setLevel(verbosity)
 
+sensors = sensor.Sensors()
+sensors.dump()
+
 #
 # Start the I/O threads
 #
@@ -115,6 +123,14 @@ ownet_thread.start()
 onewire_thread = Thread(target = onewire.onewire_handler, args = (10, ))
 onewire_thread.start()
 
+# rtl_433 filesystem
+rtl433_thread = Thread(target = rtl433.rtl433_handler, args = (options, 
sensors,))
+rtl433_thread.start()
+
+# rtl_sdr filesystem
+rtlsdr_thread = Thread(target = rtlsdr.rtlsdr_handler, args = (options, ))
+rtlsdr_thread.start()
+
 #
 # Join the I/O threads as we're done.
 #
@@ -124,3 +140,9 @@ print("ownet_thread finished...exiting")
 onewire_thread.join()
 print("onewire_thread finished...exiting")
 
+rtl433_thread.join()
+print("rtl433_thread finished...exiting")
+
+rtlsdr_thread.join()
+print("rtlsdr_thread finished...exiting")
+

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


commit 1976be532c08f3c404b215c0d7825a7b6cdfc3e8
Author: Rob Savoye <address@hidden>
Date:   Mon Feb 11 17:45:02 2019 -0700

    Add legend

diff --git a/python/chart.py b/python/chart.py
index 93e7a2f..9bbf04f 100755
--- a/python/chart.py
+++ b/python/chart.py
@@ -181,7 +181,7 @@ def animate(i):
         logging.debug("Query returned %r records" % dbcursor.rowcount)
         x = list()
         y = list()
-        for id,temperature,humidity,timestamp in dbcursor:
+        for model,temperature,humidity,timestamp in dbcursor:
             #print("TEMP: %r, %r" % (temperature,timestamp))
             x.append(timestamp)
             y.append(temperature)
@@ -192,7 +192,8 @@ def animate(i):
         temp.grid(which='major', color='red')
         temp.grid(which='minor', color='blue', linestyle='dashed')
         temp.minorticks_on()
-        temp.plot(x, y, color=colors[cur])
+        temp.plot(x, y, color=colors[cur], label=id[0])
+        legend = temp.legend(loc='upper left', shadow=True)
         cur += 1
     
     xx = list()
@@ -211,13 +212,14 @@ def animate(i):
             logging.debug("Query returned %r records" % dbcursor.rowcount)
             cur = 0
             for id,current,voltage,timestamp in dbcursor:
-                print("BATTERY: %r, %r, %r, %r" % (id, current, voltage, 
timestamp))
+                #print("BATTERY: %r, %r, %r, %r" % (id, current, voltage, 
timestamp))
                 xx.append(timestamp)
                 yy.append(voltage)
                 zz.append(current)
 
         dcvolts.set_title("DC Voltage")
         dcvolts.plot(xx, yy, color="purple")
+        dcvolts.legend([id])
         dcvolts.set_ylabel("DC Volts")
         #dcvolts.set_xlabel("Time (hourly)")
         dcvolts.grid(which='major', color='red')
@@ -226,6 +228,7 @@ def animate(i):
     
         amps.set_title("DC Current")
         amps.plot(xx, zz, color=colors[cur])
+        amps.legend([id])
         cur += 1
         amps.set_ylabel("Amps")
         amps.set_xlabel("Time (hourly)")

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

Summary of changes:
 devices/onewire.cc |   9 +++-
 powerguru.sql      |  36 ++++++++-------
 python/chart.py    | 132 ++++++++++++++++++++++++++++++++---------------------
 python/i2c.py      |  67 +++++++++++++++++++++++++++
 python/mergedb.py  |   9 ++--
 python/ownet.py    |  33 ++++++++------
 python/pgd.py      |  83 +++++++++++++++++++++++++++++++--
 python/remote.py   | 105 ++++++++++++++++++++++++++++++++++++++++++
 python/sensor.py   |  95 ++++++++------------------------------
 9 files changed, 400 insertions(+), 169 deletions(-)
 create mode 100644 python/i2c.py
 create mode 100644 python/remote.py


hooks/post-receive
-- 
powerguru



reply via email to

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