-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWX.py
142 lines (127 loc) · 3.68 KB
/
WX.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#! /usr/bin/python3
# -*- coding: utf-8 -*-
"""
Python Modul WX
"""
import os, sys
import pdb
import logging
import Config
import BME280
import APRS
import rrdtool
import datetime
def writeRRD(file, temperature, pressure, humidity) :
rrdtool.update(file, 'N:%f:%f:%f' % (temperature, humidity, pressure))
logging.info('Update RRD: N:%f:%f:%f' % (temperature, humidity, pressure))
def createRRD(file) :
rrdtool.create(file, "--step", "300", "--start", 'N',
"DS:temp1:GAUGE:1200:-40:50",
"DS:humid:GAUGE:1200:0:100",
"DS:baro:GAUGE:1200:850:1250",
"RRA:AVERAGE:0.5:1:2880",
"RRA:AVERAGE:0.5:6:700",
"RRA:AVERAGE:0.5:24:775",
"RRA:AVERAGE:0.5:144:1500",
"RRA:AVERAGE:0.5:288:2000",
"RRA:MIN:0.5:1:600",
"RRA:MIN:0.5:6:700",
"RRA:MIN:0.5:24:775",
"RRA:MIN:0.5:144:1500",
"RRA:MIN:0.5:288:2000",
"RRA:MAX:0.5:6:700",
"RRA:MAX:0.5:24:775",
"RRA:MAX:0.5:144:1500",
"RRA:MAX:0.5:288:2000"
)
def BMEInterval() :
if (Config.EN_BME280) :
readBME280()
wxGraph(Config.WXrrd)
def readBME280() :
#pdb.set_trace()
if not (Config.EN_BME280) :
return # no BME280 available
if not (os.path.exists(Config.WXrrd)) :
createRRD(Config.WXrrd)
logging.info("Created new RRD-DB: %s" % (Config.WXrrd))
logging.info("Read BME280")
try :
_altitude = int(Config.HEIGHT)
except:
logging.info("Wrong Altitude format, assume 400m asl")
_altitude = 400
try :
#pdb.set_trace()
(temp, press_nn, hum) = BME280.getBME280(_altitude)
writeRRD(Config.WXrrd, temp, press_nn, hum)
except :
Config.EN_BME280 = False
Config.EN_WXDATA = False
temp = 0
press_nn = 0
hum = 0
logging.info("BME280 not available, BME280 and WX-DATA disabled")
Config.Temperature = round(temp,2)
Config.AirPressureNN = round(press_nn,1)
Config.Humidity = round(hum,1)
def WxReport() :
#pdb.set_trace()
if (Config.EN_WXDATA) :
logging.info("Prepare WxReport")
dt = datetime.datetime.now(datetime.timezone.utc)
_DHM = dt.strftime("@%d%H%Mz")
_pos = Config.POS[0] + "/" + Config.POS[1]
_wind = "_.../...g..."
_tempf = (Config.Temperature * 1.8) + 32 # APRS benötigt Farenheit
_temp = "t" + str(int(round(_tempf,1)))
_rain = "r...p...P..."
_hum = "h" + str(int(round(Config.Humidity)))
_press = "b" + str(int(10*round(Config.AirPressureNN,1)))
_id = " BME280"
_WxReport = Config.CALL + ">APRS:" +_DHM + _pos + _wind + _temp + _rain + _hum + _press + _id
APRS.sendMsg(_WxReport)
def wxGraph(rrd) :
rrdtool.graph(
"static/wx-temp-d.png",
"--start", "-1d",
"--vertical-label", "Grad Celsius",
"-w 800",
"--title=Aussentemperatur",
"DEF:t1=%s:temp1:AVERAGE" %(rrd),
"LINE1:t1#0000FF:Temperatur",
"GPRINT:t1:LAST:Aktuell %5.2lf °C",
"GPRINT:t1:AVERAGE:Mittlelwert %5.2lf °C",
"GPRINT:t1:MIN: Minimal %5.2lf °C",
"GPRINT:t1:MAX: Maximal %5.2lf °C" )
rrdtool.graph(
"static/wx-humid-d.png",
"--start", "-1d",
"--vertical-label", "Rel. Feuchtigkeit",
"-w 800",
"--title=Rel. Feuchtigkeit",
"--upper-limit=100", "--lower-limit=0",
"DEF:h1=%s:humid:AVERAGE" % (rrd),
"LINE1:h1#0000FF:Rel. Feuchtigkeit",
"GPRINT:h1:LAST:Aktuell %5.0lf %%",
"GPRINT:h1:AVERAGE:Mittlelwert %5.0lf %%",
"GPRINT:h1:MIN: Minimal %5.0lf %%",
"GPRINT:h1:MAX: Maximal %5.0lf %%"
)
rrdtool.graph( "static/wx-barom-d.png",
"--start", "-1d",
"--vertical-label", "Rel. Luftdruck",
"-w 800",
"--title=Rel. Luftdruck",
"--alt-autoscale",
"--alt-y-grid",
"DEF:p1=%s:baro:AVERAGE" % (rrd),
"LINE1:p1#0000FF:Rel. Luftdruck",
"GPRINT:p1:LAST:Aktuell %5.0lf hpa",
"GPRINT:p1:AVERAGE:Mittlelwert %5.0lf hpa",
"GPRINT:p1:MIN: Minimal %5.0lf hpa",
"GPRINT:p1:MAX: Maximal %5.0lf hpa"
)