[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Powerguru-commit] [SCM] powerguru branch, master, updated. 28fa3fba2182
From: |
Rob Savoye |
Subject: |
[Powerguru-commit] [SCM] powerguru branch, master, updated. 28fa3fba218240163be66c996e12891e09c5d624 |
Date: |
Tue, 5 Mar 2019 19:12:25 -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 28fa3fba218240163be66c996e12891e09c5d624 (commit)
via 747633ef2595f8fbf68aed382162180cd340cf5e (commit)
from 04166c62ae74d24349df87008b20a3c3d7a72dd2 (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=28fa3fba218240163be66c996e12891e09c5d624
commit 28fa3fba218240163be66c996e12891e09c5d624
Author: Rob Savoye <address@hidden>
Date: Tue Mar 5 17:06:08 2019 -0700
Have rtl_433 log to a csv file and parse that instead of stdout as it's
more reliable.
diff --git a/python/rtl433.py b/python/rtl433.py
index 7b0a8ab..6a1d8b4 100755
--- a/python/rtl433.py
+++ b/python/rtl433.py
@@ -26,6 +26,7 @@ import time
import os
import psycopg2
import sensor
+from datetime import datetime
import itertools, operator
from options import CmdOptions
from postgresql import Postgresql
@@ -42,28 +43,52 @@ def rtl433_handler(sensors):
#db.dump()
#ppp = Popen(cmd, stdout=PIPE, stderr=STDOUT, bufsize=1,
close_fds=ON_POSIX)
- cmd = [ 'rtl_433', '-F', 'csv', '-R', '40', '-T', '60']
+ #cmd = [ 'rtl_433', '-F', 'csv:/tmp/rtl433.csv', '-s',
time.sleep(options.get('interval'))]
+ cmd = [ 'rtl_433', '-F', 'csv:/tmp/rtl433.csv']
+ ppp = Popen(cmd, stdout=PIPE, bufsize=0, close_fds=ON_POSIX)
+ foo = open('/tmp/rtl433.csv', 'r+')
+ previous = dict()
while True:
- ppp = Popen(cmd, stdout=PIPE, bufsize=0, close_fds=ON_POSIX)
- out, err = ppp.communicate()
- #out, err = ppp.communicate(timeout=0.5)
+ out = sensor.follow(foo)
+ foo.truncate()
+ temp = dict()
#print("FIXME0: %r" % out)
- for line in out.splitlines():
- #mapper = map
- #for line in ppp.readline():
- #print("FIXME: %r" % line)
- str = line.decode('utf8')
- tokens = str.split(',')
- # this is just the csv header fields
+ for line in out:
+ #print("FIXME1: %r" % line)
+ tokens = line.split(',')
+ # Ignore the header in the csv file, which is the first line
if tokens[0] == 'time':
continue
temp = dict()
temp['timestamp'] = tokens[0]
+ #epdb.set_trace()
+ # Different parsing for different devices
temp['model'] = tokens[3]
- temp['id'] = tokens[4]
- temp['channel'] = tokens[6]
- temp['temperature'] = tokens[7]
- temp['humidity'] = tokens[8]
+ if temp['model'] == 'WT0124 Pool Thermometer':
+ # FIXME: use an array to convert a numberr to the file
+ # channel alpha numeric
+ temp['channel'] ='A'
+ temp['temperature'] = str(tokens[8])
+ temp['humidity'] = "0"
+ temp['id'] = tokens[10]
+ elif temp['model'] == 'Acurite tower sensor':
+ temp['id'] = tokens[5]
+ temp['channel'] = tokens[6]
+ temp['temperature'] = tokens[8]
+ temp['humidity'] = tokens[11]
+
+ # We don't want to record more samples than the specified interval,
+ FMT = "%Y-%m-%d %H:%M:%S"
+ if (temp['id'] in previous) is False:
+ previous[temp['id']] = datetime.now().strftime(FMT)
+ tdelta = datetime.strptime(temp['timestamp'], FMT) -
datetime.strptime(previous[temp['id']], FMT)
+ #logging.debug("TDELTA: %r: %r == %r" % (tdelta.seconds,
temp['timestamp'],
+ # previous[temp['id']]))
+ #epdb.set_trace()
+ if tdelta.seconds <= options.get('interval') and tdelta.days != -1:
+ #logging.debug("Not doing anything for %r!" % temp['id'])
+ continue
+ previous[temp['id']] = temp['timestamp']
if sensors.get(temp['id']) is None:
print("New sensor %r found!" % temp['id'])
sense = sensor.SensorDevice()
@@ -78,6 +103,7 @@ def rtl433_handler(sensors):
#sensor.sensors[temp['id']]['device'] = DeviceType.RTL433
#sensors.dump()
# Convert from Celcius if needed
+ #epdb.set_trace()
if (options.get('scale') == 'F'):
temp['temperature'] = (float(temp['temperature']) * 1.8) +
32.0;
#temp['lowtemp'] = (float(temp['lowtemp']) * 1.8) + 32.0;
@@ -85,7 +111,7 @@ def rtl433_handler(sensors):
query = """INSERT INTO weather VALUES( '%s', %s, %s, %s, %s, '%s',
'%s' ) ON CONFLICT DO NOTHING;; """ % (temp['id'], temp['temperature'], "0",
"0", temp['humidity'], options.get('scale'), temp['timestamp'])
logging.debug(query)
db.query(query)
- time.sleep(options.get('interval'))
+ ppp.truncate()
# _sensors = list()
http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=747633ef2595f8fbf68aed382162180cd340cf5e
commit 747633ef2595f8fbf68aed382162180cd340cf5e
Author: Rob Savoye <address@hidden>
Date: Mon Feb 25 11:06:52 2019 -0700
Use f00th to read frrom the 433Mhz receiver
diff --git a/python/gpiots.py b/python/gpiots.py
new file mode 100755
index 0000000..c44fcb7
--- /dev/null
+++ b/python/gpiots.py
@@ -0,0 +1,111 @@
+#!/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 sys
+from subprocess import PIPE, Popen, STDOUT
+from threading import Thread
+import epdb
+import logging
+import time
+import os
+import psycopg2
+import sensor
+import itertools, operator
+from options import CmdOptions
+from postgresql import Postgresql
+ON_POSIX = 'posix' in sys.builtin_module_names
+
+def follow(thefile):
+ thefile.seek(0,2)
+ while True:
+ line = thefile.readline()
+ if not line:
+ time.sleep(0.1)
+ continue
+ yield line
+
+#def gpio_ts_handler(sensors):
+def gpio_ts_handler():
+ """This is a handler for sensors using wireless at 433Mhz,
+ commonly used by many wireless weather sensors. This requires
+ a working gpio-ts driver module and the f007th utiity installed
+ from https://github.com/alex-konshin/f007th-rpi.git
+
+ Typical output looks like this:
+ 2019-02-25 09:24:55 MST
+ type = AcuRite 00592TXR
+ channel = B
+ rolling code = 75
+ temperature = 43.1F
+ humidity = 32%
+ battery = OK
+
+ The thermometers send data on an interval, if nothing has changed it
+ displays: "Data is not changed."
+
+ """
+
+ logging.debug("Start f007th-rpi_send...")
+
+ options = CmdOptions()
+ #db = Postgresql()
+
+ cmd = [ 'f007th-send', '-v', '-l', '/tmp/xxx', '-g', '27']
+ #cmd = [ 'f007th-send', '-v', '-V', '-g', '27']
+ #ppp = Popen(cmd, stdout=PIPE, stderr=STDOUT, bufsize=0,
close_fds=ON_POSIX)
+ #epdb.set_trace()
+ ppp = Popen(cmd, stdout=PIPE, bufsize=0, close_fds=ON_POSIX)
+ foo = open('/tmp/xxx', 'r')
+ while True:
+ #out, err = ppp.communicate()
+ out = follow(foo)
+ print("FIXME0: %r" % out)
+ for line in out:
+ print("FIXME1: %r" % line)
+ #mapper = map
+ #for line in ppp.readline():
+ temp = dict()
+ #temp['timestamp'] = tokens[0]
+ #temp['model'] = tokens[3]
+ #temp['id'] = tokens[4]
+ #temp['channel'] = tokens[6]
+ #temp['temperature'] = tokens[7]
+ #temp['humidity'] = tokens[8]
+ #if sensors.get(temp['id']) is None:
+ # print("New sensor %r found!" % temp['id'])
+ # sense = sensor.SensorDevice()
+ # sense.set('id', temp['id'])
+ # sense.set('alias', temp['model'])
+ # sense.set('device', sensor.DeviceType.RTL433)
+ # sense.set('sensor', sensor.SensorType.TEMPERATURE)
+ # sense.set('channel', temp['channel'])
+ # sensors.add(sense)
+ #if (options.get('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 weather VALUES( '%s', %s, %s, %s, %s, '%s',
'%s' ) ON CONFLICT DO NOTHING;; """ % (temp['id'], temp['temperature'], "0",
"0", temp['humidity'], options.get('scale'), temp['timestamp'])
+ #logging.debug(query)
+ #db.query(query)
+ #time.sleep(options.get('interval'))
+
+ # _sensors = list()
+
+
+gpio_ts_handler()
-----------------------------------------------------------------------
Summary of changes:
python/gpiots.py | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
python/rtl433.py | 58 +++++++++++++++++++++--------
2 files changed, 153 insertions(+), 16 deletions(-)
create mode 100755 python/gpiots.py
hooks/post-receive
--
powerguru
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Powerguru-commit] [SCM] powerguru branch, master, updated. 28fa3fba218240163be66c996e12891e09c5d624,
Rob Savoye <=