Commit b35de1bf authored by julric's avatar julric

changed all files needed for adding a new sensor (here: TGS2600)

parent 5c775491
import operator
import datetime
import time
import os
os.chdir("/srv/airpi/lcd/")
from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate
from subprocess import check_output
lcd = Adafruit_CharLCDPlate.Adafruit_CharLCDPlate()
......@@ -17,13 +19,14 @@ lcd.backlight(lcd.OFF)
# type: apt-get install rrdtools #
# #
#########################################################
# set some options here and the shortnames, symbols and #
# order of the displayed data in line 45 and further #
# set some options here #
#########################################################
rrd_file_airpi = '../data_airpi.rrd' # path to your rrd-file with airpi weather data
display_time = 3 # time in seconds, each value should be displayed on lcd
display_color = lcd.GREEN # backlight-color of lcd: lcd.RED, lcd.BLUE, lcd.GREEN, lcd.VIOLETT or lcd.ON (lightblue)
rrd_file_airpi = '../data_airpi.rrd' # path to your rrd-file with airpi weather data
display_time = 3 # time in seconds, each value should be displayed on lcd
display_color = lcd.ON # backlight-color of lcd: lcd.RED, lcd.BLUE, lcd.GREEN, lcd.VIOLETT or lcd.ON (lightblue)
show_flukso = 1 # also show last energy consumption? 1 = yes, 0 = no
rrd_file_flukso = '../../flukso/data_wohnung.rrd' # path to your rrd-file with flukso-data
#########################################################
......@@ -34,9 +37,8 @@ while True:
last = check_output(["rrdtool", "lastupdate", rrd_file_airpi])
lastvalues = last.split( )
# array lastvalues consists of every sensor-name, followed by the time and the sensor-values:
# ['tempbmp', 'tempdht', 'press', 'humi', 'light', 'no2', 'co', 'vol', '1403275748:', '24', 'U', '1001', 'U', '546', '98830', '161637', '235']
# (for the rrd, generated as shown in https://git.cccmz.de/julric/airpi/wikis/rrd-support )
# array lastvalues consists of every sensor-name, then the time and the sensor-values:
# ['tempbmp', 'tempdht', 'press', 'humi', 'light', 'no2', 'co', 'vol', 'smoke', '1406917791:', '9969', '28', '30', '993', '40', '1840', '64672', '424615', '3081']
data = []
sensors = (len(lastvalues)-1)/2
......@@ -52,13 +54,13 @@ while True:
dataPoints["number"] = 1
data.append(dataPoints)
elif 'press' in value:
dataPoints["sname"] = "Pressure:"
dataPoints["sname"] = "Druck: "
dataPoints["value"] = lastvalues[(position+sensors+1)]
dataPoints["symbol"] = "hPa"
dataPoints["number"] = 2
data.append(dataPoints)
elif 'humi' in value:
dataPoints["sname"] = "Humidity:"
dataPoints["sname"] = "Feuchte: "
dataPoints["value"] = lastvalues[(position+sensors+1)]
dataPoints["symbol"] = "%"
dataPoints["number"] = 3
......@@ -82,17 +84,23 @@ while True:
dataPoints["number"] = 6
data.append(dataPoints)
elif 'light' in value:
dataPoints["sname"] = "Light: "
dataPoints["sname"] = "Licht: "
dataPoints["value"] = lastvalues[(position+sensors+1)]
dataPoints["symbol"] = "mV"
dataPoints["number"] = 7
data.append(dataPoints)
elif 'vol' in value:
dataPoints["sname"] = "Volume:"
dataPoints["sname"] = "Vol: "
dataPoints["value"] = lastvalues[(position+sensors+1)]
dataPoints["symbol"] = "Ohm"
dataPoints["number"] = 8
data.append(dataPoints)
elif 'smoke' in value:
dataPoints["sname"] = "Luft: "
dataPoints["value"] = lastvalues[(position+sensors+1)]
dataPoints["symbol"] = "Ohm"
dataPoints["number"] = 9
data.append(dataPoints)
elif ':' in value:
measurementtime = value[:-1]
else:
......@@ -104,21 +112,26 @@ while True:
lcd.clear()
lcd.backlight(display_color)
lcd.message(" AirPi \n" + '{:%d.%m.%Y %H:%M}'.format(datetime.datetime.fromtimestamp(float(measurementtime))))
lcd.message(" Wetterstation \n" + '{:%d.%m.%Y %H:%M}'.format(datetime.datetime.fromtimestamp(float(measurementtime))))
# show output on console
# print " AirPi \n" + '{:%d.%m.%Y %H:%M}'.format(datetime.datetime.fromtimestamp(float(measurementtime)))
# print " Wetterstation \n" + '{:%d.%m.%Y %H:%M}'.format(datetime.datetime.fromtimestamp(float(measurementtime)))
time.sleep(display_time)
lcd.clear()
currentDisplay = 0
for currentDisplay in range(0, 4, 1):
for currentDisplay in range(0, 5, 1):
data1 = data[currentDisplay*2]
if data1["value"] == "U":
data1["value"] = " "
else:
str(int(round(float(data1["value"]))))
data2 = data[currentDisplay*2 + 1]
if currentDisplay == 4:
data2["sname"] = " "
data2["value"] = "U"
data2["symbol"] = " "
else:
data2 = data[currentDisplay*2 + 1]
if data2["value"] == "U":
data2["value"] = " "
else:
......@@ -132,6 +145,22 @@ while True:
time.sleep(display_time)
lcd.clear()
# show current energy consumption
if show_flukso == 1:
lastvalues = []
last = check_output(["rrdtool", "lastupdate", rrd_file_flukso])
lastvalues = last.split( )
# array lastvalues consists of every sensor-name, then the time and the sensor-values:
# ['watt', '1403275748', '137']
lcd.message("Stromverbrauch: \n " + lastvalues[2] + " Watt")
# show output on console
# print "Stromverbrauch: \n " + lastvalues[2] + " Watt"
time.sleep(display_time)
# clear and turn off lcd
lcd.clear()
lcd.backlight(lcd.OFF)
......
......@@ -54,8 +54,12 @@ class rrd(output.Output):
rrd_value = rrd_value + ":" + str(int(round(dataPoints[array_index]["value"])))
else:
rrd_value = rrd_value + ":U"
if [i for i, x in enumerate(dataPoints) if x["name"] == "Smoke_Level" and x["sensor"] == "TGS2600"]:
array_index = [i for i, x in enumerate(dataPoints) if x["name"] == "Smoke_Level" and x["sensor"] == "TGS2600"][0]
rrd_value = rrd_value + ":" + str(int(round(dataPoints[array_index]["value"])))
else:
rrd_value = rrd_value + ":U"
# print rrd_value
ret = rrd_update(self.rrd_file, rrd_value);
return True
\ No newline at end of file
#! /bin/bash
RRDTOOL="/usr/bin/rrdtool"
RRD_DB="/srv/airpi/data_airpi.rrd"
RRD_DB="../data_airpi.rrd"
GRAPH_PATH="/srv/flukso/graph"
GRAPH_PATH="../graph"
# hour
$RRDTOOL graph $GRAPH_PATH/airpi-temp-hour.png -a PNG --width=800 --height=300 \
......
#! /bin/bash
RRDTOOL="/usr/bin/rrdtool"
RRD_DB="/srv/airpi/data_airpi.rrd"
RRD_DB="../data_airpi.rrd"
GRAPH_PATH="/srv/flukso/graph"
GRAPH_PATH="../graph"
$RRDTOOL graph $GRAPH_PATH/airpi-tempbmp-day.png -a PNG --width=800 --height=300 \
......@@ -127,3 +127,16 @@ VDEF:vol_average=vol,AVERAGE \
VDEF:vol_max=vol,MAXIMUM \
'GPRINT:vol_max:<b>Maximum</b>\: %5.0lf ' \
> /dev/null
$RRDTOOL graph $GRAPH_PATH/airpi-smoke-day.png -a PNG --width=800 --height=300 \
--start -1d --pango-markup --vertical-label 'Luftverschmutzung' \
DEF:smoke=$RRD_DB:smoke:AVERAGE \
AREA:smoke#acc6fb \
LINE1:smoke#4f5a72:"<big>Luftverschmutzung (TGS2600)</big> " \
VDEF:smoke_min=smoke,MINIMUM \
'GPRINT:smoke_min:<b>Minimum</b>\: %5.0lf ' \
VDEF:smoke_average=smoke,AVERAGE \
'GPRINT:smoke_average:<b>Durchschnitt</b>\: %5.0lf ' \
VDEF:smoke_max=smoke,MAXIMUM \
'GPRINT:smoke_max:<b>Maximum</b>\: %5.0lf ' \
> /dev/null
#! /bin/bash
RRDTOOL="/usr/bin/rrdtool"
RRD_DB="/srv/airpi/data_airpi.rrd"
RRD_DB="../data_airpi.rrd"
GRAPH_PATH="/srv/flukso/graph"
GRAPH_PATH="../graph"
$RRDTOOL graph $GRAPH_PATH/airpi-tempbmp-hour.png -a PNG --width=800 --height=300 \
......@@ -125,3 +125,16 @@ VDEF:vol_average=vol,AVERAGE \
VDEF:vol_max=vol,MAXIMUM \
'GPRINT:vol_max:<b>Maximum</b>\: %5.0lf ' \
> /dev/null
$RRDTOOL graph $GRAPH_PATH/airpi-smoke-hour.png -a PNG --width=800 --height=300 \
--start -1h --pango-markup --vertical-label 'Luftverschmutzung' \
DEF:smoke=$RRD_DB:smoke:AVERAGE \
AREA:smoke#acc6fb \
LINE1:smoke#4f5a72:"<big>Luftverschmutzung (TGS2600)</big> " \
VDEF:smoke_min=smoke,MINIMUM \
'GPRINT:smoke_min:<b>Minimum</b>\: %5.0lf ' \
VDEF:smoke_average=smoke,AVERAGE \
'GPRINT:smoke_average:<b>Durchschnitt</b>\: %5.0lf ' \
VDEF:smoke_max=smoke,MAXIMUM \
'GPRINT:smoke_max:<b>Maximum</b>\: %5.0lf ' \
> /dev/null
#! /bin/bash
RRDTOOL="/usr/bin/rrdtool"
RRD_DB="/srv/airpi/data_airpi.rrd"
RRD_DB="../data_airpi.rrd"
GRAPH_PATH="/srv/flukso/graph"
GRAPH_PATH="../graph"
$RRDTOOL graph $GRAPH_PATH/airpi-tempbmp-month.png -a PNG --width=800 --height=300 \
......@@ -127,3 +127,16 @@ VDEF:vol_average=vol,AVERAGE \
VDEF:vol_max=vol,MAXIMUM \
'GPRINT:vol_max:<b>Maximum</b>\: %5.0lf ' \
> /dev/null
$RRDTOOL graph $GRAPH_PATH/airpi-smoke-month.png -a PNG --width=800 --height=300 \
--start -1m --pango-markup --vertical-label 'Luftverschmutzung' \
DEF:smoke=$RRD_DB:smoke:AVERAGE \
AREA:smoke#acc6fb \
LINE1:smoke#4f5a72:"<big>Luftverschmutzung (TGS2600)</big> " \
VDEF:smoke_min=smoke,MINIMUM \
'GPRINT:smoke_min:<b>Minimum</b>\: %5.0lf ' \
VDEF:smoke_average=smoke,AVERAGE \
'GPRINT:smoke_average:<b>Durchschnitt</b>\: %5.0lf ' \
VDEF:smoke_max=smoke,MAXIMUM \
'GPRINT:smoke_max:<b>Maximum</b>\: %5.0lf ' \
> /dev/null
#! /bin/bash
RRDTOOL="/usr/bin/rrdtool"
RRD_DB="/srv/airpi/data_airpi.rrd"
RRD_DB="../data_airpi.rrd"
GRAPH_PATH="/srv/flukso/graph"
GRAPH_PATH="../graph"
$RRDTOOL graph $GRAPH_PATH/airpi-tempbmp-week.png -a PNG --width=800 --height=300 \
......@@ -127,3 +127,16 @@ VDEF:vol_average=vol,AVERAGE \
VDEF:vol_max=vol,MAXIMUM \
'GPRINT:vol_max:<b>Maximum</b>\: %5.0lf ' \
> /dev/null
$RRDTOOL graph $GRAPH_PATH/airpi-smoke-week.png -a PNG --width=800 --height=300 \
--start -1w --pango-markup --vertical-label 'Luftverschmutzung' \
DEF:smoke=$RRD_DB:smoke:AVERAGE \
AREA:smoke#acc6fb \
LINE1:smoke#4f5a72:"<big>Luftverschmutzung (TGS2600)</big> " \
VDEF:smoke_min=smoke,MINIMUM \
'GPRINT:smoke_min:<b>Minimum</b>\: %5.0lf ' \
VDEF:smoke_average=smoke,AVERAGE \
'GPRINT:smoke_average:<b>Durchschnitt</b>\: %5.0lf ' \
VDEF:smoke_max=smoke,MAXIMUM \
'GPRINT:smoke_max:<b>Maximum</b>\: %5.0lf ' \
> /dev/null
#! /bin/bash
RRDTOOL="/usr/bin/rrdtool"
RRD_DB="/srv/airpi/data_airpi.rrd"
RRD_DB="../data_airpi.rrd"
GRAPH_PATH="/srv/flukso/graph"
GRAPH_PATH="../graph"
$RRDTOOL graph $GRAPH_PATH/airpi-tempbmp-year.png -a PNG --width=800 --height=300 \
......@@ -127,3 +127,16 @@ VDEF:vol_average=vol,AVERAGE \
VDEF:vol_max=vol,MAXIMUM \
'GPRINT:vol_max:<b>Maximum</b>\: %5.0lf ' \
> /dev/null
$RRDTOOL graph $GRAPH_PATH/airpi-smoke-year.png -a PNG --width=800 --height=300 \
--start -1y --pango-markup --vertical-label 'Luftverschmutzung' \
DEF:smoke=$RRD_DB:smoke:AVERAGE \
AREA:smoke#acc6fb \
LINE1:smoke#4f5a72:"<big>Luftverschmutzung (TGS2600)</big> " \
VDEF:smoke_min=smoke,MINIMUM \
'GPRINT:smoke_min:<b>Minimum</b>\: %5.0lf ' \
VDEF:smoke_average=smoke,AVERAGE \
'GPRINT:smoke_average:<b>Durchschnitt</b>\: %5.0lf ' \
VDEF:smoke_max=smoke,MAXIMUM \
'GPRINT:smoke_max:<b>Maximum</b>\: %5.0lf ' \
> /dev/null
......@@ -38,7 +38,7 @@ sensorName = LDR
[TGS2600]
filename=analogue
enabled=off
enabled=on
pullDownResistance=22000
measurement=Smoke_Level
adcPin=1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment