[rrd-users] pi rrdtool python temperature

r100gs s.soellner at gmail.com
Tue Mar 29 10:25:59 CEST 2016


Dear all, 

I´m new to python and rrdtool. I created the following python script to
access some sensors on my raspberry. So, sensors are working fine and i get
results in terminal. Now I tried to insert those data into an rrd databas
but I always get the failure posted later on: 
Verwendete Sensoren: 

DHT22 (temperature, humidity) 
BMP085 (pressure, temperature) 
BH1750FVI (light) 

In the terminal I get: 

T1:	13.10 °C 
Druck: 960.00 hPa 
Druck NN: 1003.21 hPa 
Helligkeit : 0.0 lx 
T2:	12.40 °C 
LF: 61.30 
Traceback (most recent call last): 
File „./wetter_sens_ab_rdd.py“, line 62, in 
data1 = „N:%.2f:%.2f:%.2f:%.2f:%.2f:%.2f“ % (t1, t2, lf, druck, dnn, he1) 
TypeError: float argument required, not function 

Using the script: 

#!/usr/bin/python 
# -*- coding: utf-8 -*- 

from Adafruit_BMP085 import BMP085 
import smbus 
import time 
import sys 
import Adafruit_DHT 
import re, os, rrdtool 

bmp = BMP085(0x77) 

bmp = BMP085(0x77, 3) # ULTRAHIRES Mode 

t1 = bmp.readTemperature() 

druckr = bmp.readPressure() 

altitude = 364 
dnn = druckr / pow(1.0 – altitude/44330.0, 5.255) 

druck = druckr/100 

DEVICE = 0x23 # Default device I2C address 

POWER_DOWN = 0x00 # No active state 
POWER_ON = 0x01 # Power on 
RESET = 0x07 # Reset data register value 

CONTINUOUS_LOW_RES_MODE = 0x13 
CONTINUOUS_HIGH_RES_MODE_1 = 0x10 
CONTINUOUS_HIGH_RES_MODE_2 = 0x11 
ONE_TIME_HIGH_RES_MODE_1 = 0x20 
ONE_TIME_HIGH_RES_MODE_2 = 0x21 
ONE_TIME_LOW_RES_MODE = 0x23 

bus = smbus.SMBus(1) # Rev 2 Pi uses 1 

def convertToNumber(data): 
return ((data[1] + (256 * data[0])) / 1.2) 

def he1(addr=DEVICE): 
data = bus.read_i2c_block_data(addr,ONE_TIME_HIGH_RES_MODE_1) 
return convertToNumber(data) 

lf, t2 = Adafruit_DHT.read_retry(22, 14) 

print „T1: %.2f °C“ % t1 
print „Druck: %.2f hPa“ % druck 
print „Druck NN: %.2f hPa“ % (dnn / 100.0) 
print „Helligkeit : “ + str(he1()) + “ lx“ 

if lf is not None and t2 is not None: 
print „T2: %.2f °C“ % t2 
print „LF: %.2f“ % lf #alt:print ‚T2 = {0:0.1f}°C LF = {1:0.1f}%‘.format(t2,
lf) 
else: 
print ‚Lesefehler! Neu probieren‘ 
sys.exit(1) 

data1 = „N:%.2f:%.2f:%.2f:%.2f:%.2f:%.2f“ % (t1, t2, lf, druck, dnn, he1) 

rrdtool.update( 
„%s/wetter.rrd“ % (os.path.dirname(os.path.abspath(__file__))), 
data1) 

end of script. 

RRD database: wetter.rrd I put some more sensores in case I want to add some
additionl ones) 

temp 1 t1 
temp 2 t2 
temp 3 t3 
temp 4 t4 

wind richtung wr 
wind geschw wg 

Druck (NN) dnn 

regen 1 r1 
regen 2 r2 
regen 3 r3 
luftfeuchte lf 

helligkeit he1 

Abfragen jede Minute, alle 60s 
Speichern 10 Tage = 14400 Werte 
dann reduzieren auf 1 Wert pro Tag 
Aufbewahren 50 Jahre: 18000 Werte 

rrdtool create wetter.rrd \ 
–step ’60‘ \ 
‚DS:t1:GAUGE:60:-40:80‘ \ 
‚DS:t2:GAUGE:60:-40:80‘ \ 
‚DS:t3:GAUGE:60:-40:80‘ \ 
‚DS:t4:GAUGE:60:-40:80‘ \ 
‚DS:wr:GAUGE:60:0:360‘ \ 
‚DS:wg:GAUGE:60:0:100‘ \ 
‚DS:dnn:GAUGE:60:850:1250‘ \ 
‚DS:r1:GAUGE:60:0:100‘ \ 
‚DS:r2:GAUGE:60:0:100‘ \ 
‚DS:r3:GAUGE:60:0:100‘ \ 
‚DS:lf:GAUGE:60:0:100‘ \ 
‚DS:he1:GAUGE:60:0:1000‘ \ 
‚RRA:AVERAGE:0.5:1:14400‘ \ 
‚RRA:MIN:0.5:1440:18000‘ \ 
‚RRA:MAX:0.5:1440:18000‘ \ 
‚RRA:AVERAGE:0.5:1440:18000‘ 

Maybe s.b. can give some hints. I´m really new to all this stuff, so I´m
very happy to have the sensores running. Next step is to get a database and
than get some nice graphs. 


Best regardings, 
Stefan



--
View this message in context: http://rrd-mailinglists.937164.n2.nabble.com/pi-rrdtool-python-temperature-tp7583334.html
Sent from the RRDtool Users Mailinglist mailing list archive at Nabble.com.



More information about the rrd-users mailing list