Raspberry temp rrd: Skirtumas tarp puslapio versijų
Jump to navigation
Jump to search
(some updates, i've got cpu monitoring support in the graph) |
(Jokio skirtumo)
|
Dabartinė 10:51, 13 birželio 2019 versija
Šiame straipsnyje jau naudojamas paruoštas dht22 sensorius.
Pasidarome RRD[keisti]
rrdtool create /etc/mods/temp.rrd --step 60 \ DS:temperature:GAUGE:120:-50:100 \ DS:humidity:GAUGE:120:0:100 \ DS:rasptemp:GAUGE:120:0:100 \ RRA:AVERAGE:0.5:1:1440 \ RRA:MIN:0.5:1:1440 \ RRA:MAX:0.5:1:1440 \ RRA:AVERAGE:0.5:30:17520 \ RRA:MIN:0.5:30:17520 \ RRA:MAX:0.5:30:17520 \ RRA:AVERAGE:0.5:1:1440 \ RRA:MIN:0.5:1:1440 \ RRA:MAX:0.5:1:1440
RRD Atnaujinimas (RaspberryPI)[keisti]
Sujungimas:
PIN1 = + PIN6 = - PIN7 = DATA
Sudiegiame reikalingas bibliotekas:
apt-get install build-essential python-dev python-openssl git git clone https://github.com/adafruit/Adafruit_Python_DHT.git && cd Adafruit_Python_DHT python setup.py install
Sudedame si scripta i /usr/local/bin/readtemp.py
#!/usr/bin/env python2.7
# apt install python-rrdtool python-dill
import Adafruit_DHT
import time
import argparse as ap
from rrdtool import update as rrd_update
import rrdtool
import dill
sensor = Adafruit_DHT.DHT22
pin = 4
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
if humidity is None and temperature is None:
dill.load_session("/tmp/tempout")
def DHT22_print_data():
if humidity is not None and temperature is not None:
if args.update is not None:
rrd_update('/etc/mods/temp.rrd', 'N:%s:%s:%s' %(temperature, humidity, rasp_temp()))
else:
print 'Temp: {0:0.1f}C, Dregme: {1:0.1f}%'.format(temperature, humidity)
else:
print('Failed to get reading. Try again!')
sys.exit(1)
def rasp_temp():
tFile = open('/sys/class/thermal/thermal_zone0/temp')
temp = round((float(tFile.read())/1000),2)
return temp
def MakeNiceGraph():
for sched in ['daily' , 'weekly', 'monthly', 'yearly']:
if sched == 'weekly':
period = 'w'
elif sched == 'daily':
period = 'd'
elif sched == 'monthly':
period = 'm'
elif sched == 'yearly':
period = 'y'
ret = rrdtool.graph( "/var/www/html/temp-%s.png" %(sched), "--start", "-1%s" %(period), "--vertical-label=Temperatura",
'--watermark=Vidaus temperatura - Veranda',
"-w 800 -h 400",
"DEF:temperature=/etc/mods/temp.rrd:temperature:AVERAGE",
"DEF:humidity=/etc/mods/temp.rrd:humidity:AVERAGE",
"DEF:rasptemp=/etc/mods/temp.rrd:rasptemp:AVERAGE",
"AREA:temperature#EA450C:Temperatura",
"GPRINT:temperature:LAST:Dabar\:%8.2lf %s",
"GPRINT:temperature:MIN:Min\:%8.2lf %s",
"GPRINT:temperature:AVERAGE:Vidurkis\:%8.2lf %s",
"GPRINT:temperature:MAX:Max\:%8.2lf %s\\n",
"LINE1:humidity#19803C:Dregme",
"GPRINT:humidity:LAST: Dabar\:%8.2lf %s",
"GPRINT:humidity:MIN:Min\:%8.2lf %s",
"GPRINT:humidity:AVERAGE:Vidurkis\:%8.2lf %s",
"GPRINT:humidity:MAX:Max\:%8.2lf %s\\n",
"LINE2:rasptemp#FA4BBD:CPU",
"GPRINT:rasptemp:LAST: Dabar\:%8.2lf %s",
"GPRINT:rasptemp:MIN:Min\:%8.2lf %s",
"GPRINT:rasptemp:AVERAGE:Vidurkis\:%8.2lf %s",
"GPRINT:rasptemp:MAX:Max\:%8.2lf %s\\n")
parser = ap.ArgumentParser(description="Just another script")
parser.add_argument("--graph")
parser.add_argument("--update")
args, leftovers = parser.parse_known_args()
if args.graph is not None:
MakeNiceGraph()
else:
DHT22_print_data()
dill.dump_session("/tmp/tempout")
RRD Atnaujinimas (OrangePI)[keisti]
#!/usr/bin/env python2.7
# apt install python-rrdtool
from pyA20.gpio import gpio
from pyA20.gpio import port
import dht22 as dht
import time
import argparse as ap
from rrdtool import update as rrd_update
import rrdtool
# initialize GPIO
DHT22_PIN = port.PA6
gpio.init()
#gpio.cleanup()
DHT22_instance = dht.DHT22(pin=DHT22_PIN)
def DHT22_print_data(DHT22_result):
if DHT22_result.is_valid():
if args.update is not None:
rrd_update('/etc/mods/temp.rrd', 'N:%s:%s' %(DHT22_result.temperature, DHT22_result.humidity))
else:
print 'Temp: {}C, Dregme: {}%'.format(DHT22_result.temperature, DHT22_result.humidity)
else:
DHT22_read_sensor()
def DHT22_read_sensor():
DHT22_result = DHT22_instance.read()
DHT22_print_data(DHT22_result)
def MakeNiceGraph():
for sched in ['daily' , 'weekly', 'monthly', 'yearly']:
if sched == 'weekly':
period = 'w'
elif sched == 'daily':
period = 'd'
elif sched == 'monthly':
period = 'm'
elif sched == 'yearly':
period = 'y'
ret = rrdtool.graph( "/var/www/html/temp-%s.png" %(sched), "--start", "-1%s" %(period), "--vertical-label=Temperatura",
'--watermark=Vidaus temperatura - Svetaine',
"-w 800 -h 400",
"DEF:temperature=/etc/mods/temp.rrd:temperature:AVERAGE",
"DEF:humidity=/etc/mods/temp.rrd:humidity:AVERAGE",
"AREA:temperature#EA450C:Temperatura",
"GPRINT:temperature:LAST:Dabar\:%8.2lf %s",
"GPRINT:temperature:AVERAGE:Vidurkis\:%8.2lf %s",
"GPRINT:temperature:MAX:Max\:%8.2lf %s\\n",
"LINE1:humidity#19803C:Dregme",
"GPRINT:humidity:LAST: Dabar\:%8.2lf %s",
"GPRINT:humidity:AVERAGE:Vidurkis\:%8.2lf %s",
"GPRINT:humidity:MAX:Max\:%8.2lf %s\\n")
parser = ap.ArgumentParser(description="Just another script")
parser.add_argument("--graph")
parser.add_argument("--update")
args, leftovers = parser.parse_known_args()
if args.graph is not None:
MakeNiceGraph()
else:
DHT22_read_sensor()
Crontab:
* * * * * root /usr/local/bin/readtemp.py --update RRD > /dev/null 2>&1
RRD paveikslėlio atvaizdavimas[keisti]
Crontab:
*/5 * * * * root /usr/local/bin/readtemp.py --graph RRD > /dev/null 2>&1