diff options
author | Patrick Simianer <p@simianer.de> | 2020-09-27 20:56:34 +0200 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2020-09-27 20:56:34 +0200 |
commit | ae15ee1cdb06b00803f4426b0e965510661c3322 (patch) | |
tree | d5f6eadaae86f588ab91b50db26624cdadaab8de | |
parent | 843bb50c48a8b11c572c1e64e0237d09d635e1f0 (diff) |
2020-09-27
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | DEVICES | 4 | ||||
-rw-r--r-- | README | 2 | ||||
-rwxr-xr-x | fill-db.rb | 2 | ||||
-rwxr-xr-x | get-temps.rb | 16 | ||||
-rwxr-xr-x | query-db.rb | 13 | ||||
-rwxr-xr-x | receive-test.py | 2 | ||||
-rwxr-xr-x | run | 2 | ||||
-rw-r--r-- | test.rb | 27 | ||||
-rwxr-xr-x | weather-logger | 13 |
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 @@ -0,0 +1,4 @@ +Berlin +====== +- Inside: THGR810, THGN800 +- Outside: BTHR918 @@ -7,3 +7,5 @@ Dependencies: ``` ./create-db.rb `` + +Time is in UTC. @@ -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 @@ -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 @@ -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 - |