summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2020-09-27 20:56:34 +0200
committerPatrick Simianer <p@simianer.de>2020-09-27 20:56:34 +0200
commitae15ee1cdb06b00803f4426b0e965510661c3322 (patch)
treed5f6eadaae86f588ab91b50db26624cdadaab8de
parent843bb50c48a8b11c572c1e64e0237d09d635e1f0 (diff)
2020-09-27
-rw-r--r--.gitignore4
-rw-r--r--DEVICES4
-rw-r--r--README2
-rwxr-xr-xfill-db.rb2
-rwxr-xr-xget-temps.rb16
-rwxr-xr-xquery-db.rb13
-rwxr-xr-xreceive-test.py2
-rwxr-xr-xrun2
-rw-r--r--test.rb27
-rwxr-xr-xweather-logger13
10 files changed, 68 insertions, 17 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0293661
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+*.db
+*.err
+*.gz
+*.out
diff --git a/DEVICES b/DEVICES
new file mode 100644
index 0000000..2b831d7
--- /dev/null
+++ b/DEVICES
@@ -0,0 +1,4 @@
+Berlin
+======
+- Inside: THGR810, THGN800
+- Outside: BTHR918
diff --git a/README b/README
index 58f6161..fb0448f 100644
--- a/README
+++ b/README
@@ -7,3 +7,5 @@ Dependencies:
```
./create-db.rb
``
+
+Time is in UTC.
diff --git a/fill-db.rb b/fill-db.rb
index 199db42..c4fa513 100755
--- a/fill-db.rb
+++ b/fill-db.rb
@@ -11,7 +11,7 @@ end
str = Proc.new do |x|
x.to_s
end
-common_conv = { "db" => str, "timestamp"=>float, "device_type"=>str, "device_id"=>str, "battery" => int, "rssi" => int }
+common_conv = { "db" => str, "timestamp"=>float, "device_type"=>str, "type"=>str, "device_id"=>str, "battery" => int, "battery_numeric" => int, "rssi" => int, "rssi_numeric" => int }
rain_conv = {"rain_rate"=>float, "rain_total"=>float}.merge(common_conv)
wind_conv = {"chill"=>float, "temperature"=>float,"average_speed"=>float,"direction"=>int,"gust"=>float}.merge(common_conv)
temp_conv = {"humidity"=>float, "humidity_status"=>str,"humidity_status_numeric"=>int,"temperature"=>float}.merge(common_conv)
diff --git a/get-temps.rb b/get-temps.rb
new file mode 100755
index 0000000..ac24051
--- /dev/null
+++ b/get-temps.rb
@@ -0,0 +1,16 @@
+#!/usr/bin/env ruby
+
+while line = STDIN.gets
+ a = line.split
+ d = {}
+ a.each { |i|
+ name, val = i.split("::")
+ if name == "temperature"
+ d["temperature"] = val
+ end
+ if name == "device_id"
+ d["dev"] = val
+ end
+ }
+ puts d.to_s
+end
diff --git a/query-db.rb b/query-db.rb
index 2418c7d..984a59d 100755
--- a/query-db.rb
+++ b/query-db.rb
@@ -4,17 +4,16 @@ require 'sqlite3'
db = SQLite3::Database.new("weather.db")
-db.execute("select * from rain") do |result|
- puts result.to_s
-end
-
-#db.execute("select * from wind") do |result|
+#db.execute("select * from rain") do |result|
# puts result.to_s
#end
-#db.execute("select * from temp") do |result|
+#db.execute("select * from wind") do |result|
# puts result.to_s
#end
-db.close
+db.execute("select * from temp") do |result|
+ puts result.to_s
+end
+db.close
diff --git a/receive-test.py b/receive-test.py
index 663f7a5..cb95d7c 100755
--- a/receive-test.py
+++ b/receive-test.py
@@ -1,4 +1,4 @@
-#!./bin/python3
+#!/usr/bin/env python3
from RFXtrx import PySerialTransport
import sys, datetime, os
diff --git a/run b/run
index 2538b13..c346553 100755
--- a/run
+++ b/run
@@ -1,5 +1,5 @@
#!/usr/bin/zsh -x
-source bin/activate
+source env/bin/activate
python receive.py 2>received.err | tee received | ./fill-db.rb 2>db.err > db.out
diff --git a/test.rb b/test.rb
new file mode 100644
index 0000000..16ab18a
--- /dev/null
+++ b/test.rb
@@ -0,0 +1,27 @@
+int = Proc.new do |x|
+ x.to_i
+end
+float = Proc.new do |x|
+ x.to_f
+end
+str = Proc.new do |x|
+ x.to_s
+end
+
+def parse_to_hash s, conv
+ h = {}
+ puts s.split("\t").map { |i| i=i.split("::"); "#{i[0]} #{conv[i[0]].call}" }
+ return h
+end
+
+common_conv = { "db" => str, "timestamp"=>float, "device_type"=>str, "type"=>str, "device_id"=>str, "battery" => int, "battery_numeric" => int, "rssi" => int, "rssi_numeric" => int }
+rain_conv = {"rain_rate"=>float, "rain_total"=>float}.merge(common_conv)
+wind_conv = {"chill"=>float, "temperature"=>float,"average_speed"=>float,"direction"=>int,"gust"=>float}.merge(common_conv)
+temp_conv = {"humidity"=>float, "humidity_status"=>str,"humidity_status_numeric"=>int,"temperature"=>float}.merge(common_conv)
+conv = { "rain" => rain_conv, "wind" => wind_conv, "temp" => temp_conv }
+
+while line = STDIN.gets
+ db = line.split("\t").first.split("::")[1]
+ parse_to_hash line, conv[db]
+end
+
diff --git a/weather-logger b/weather-logger
index a2c957b..fc1f6a8 100755
--- a/weather-logger
+++ b/weather-logger
@@ -1,20 +1,20 @@
-#! /bin/sh
+#!/bin/sh
# /etc/init.d/weather-logger
-#
+
export SUFFIX=$(date +'%Y-%m-%d-%H:%M:%S')
-export DIR=/home/pi/weather/
+export USER=pks
+export DIR=/home/$USER/weather/
-# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting weather-logger"
rm -f $DIR/stop
- runuser -l pi -c "source $DIR/env/bin/activate && python $DIR/receive.py 2>$DIR/weather.$SUFFIX.err > $DIR/weather.$SUFFIX.out"
+ runuser -l $USER -c "source $DIR/env/bin/activate && python $DIR/receive.py 2>$DIR/weather.$SUFFIX.err > $DIR/weather.$SUFFIX.out" &
;;
stop)
echo "Stopping weather-logger"
- runuser -l pi -c "touch $DIR/stop"
+ runuser -l $USER -c "touch $DIR/stop"
;;
*)
echo "Usage: /etc/init.d/weather-logger {start|stop}"
@@ -23,4 +23,3 @@ case "$1" in
esac
exit 0
-