The validate function is there to check if the sensor return something
if not it will return ':U' => unknow
Code: Select all
ef Validate(value):
if value == None:
return ":U"
else:
return ":{}".format(value)
And yes if your rrdtool needs 3 inputs you should send all your inputs.
Code: Select all
#create text string to insert data
rdata = "N" + Validate(cpuTemp) + Validate(sensorData[0]) + Validate(sensorData[1])
#now let insert it into the rddtool data
fileRrdtool = "/home/pi/temperatures.rrd"
subprocess.Popen(["/usr/bin/rrdtool","update",fileRrdtool,rdata])
If you add some input data at your rrd database you could check using the info command
ex:
Code: Select all
pi@Pi2 ~ $ rrdtool info temperatures.rrd
filename = "temperatures.rrd"
rrd_version = "0003"
step = 300
last_update = 1420088400
header_size = 5096
ds[th_cpu].index = 0
ds[th_cpu].type = "GAUGE"
ds[th_cpu].minimal_heartbeat = 1200
ds[th_cpu].min = -4,0000000000e+01
ds[th_cpu].max = 1,0000000000e+02
ds[th_cpu].last_ds = "U"
ds[th_cpu].value = 0,0000000000e+00
ds[th_cpu].unknown_sec = 0
ds[th_dht22].index = 1
ds[th_dht22].type = "GAUGE"
ds[th_dht22].minimal_heartbeat = 1200
ds[th_dht22].min = -4,0000000000e+01
ds[th_dht22].max = 1,0000000000e+02
ds[th_dht22].last_ds = "U"
ds[th_dht22].value = 0,0000000000e+00
ds[th_dht22].unknown_sec = 0
ds[hm_dht22].index = 2
ds[hm_dht22].type = "GAUGE"
ds[hm_dht22].minimal_heartbeat = 1200
ds[hm_dht22].min = -4,0000000000e+01
ds[hm_dht22].max = 1,0000000000e+02
ds[hm_dht22].last_ds = "U"
ds[hm_dht22].value = 0,0000000000e+00
ds[hm_dht22].unknown_sec = 0
On this example I do have 3 inputs. Cpu temperature, DHT22 Temperature and DHT22 humidity.
Maybe it is a good thing to read the rrdtool doc.
Daniel