Unit-Files erstellt und Skript soweit
This commit is contained in:
parent
625f74026c
commit
9802d0853e
|
@ -11,16 +11,19 @@ if [ -z "$GRAFANADB" ] then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
if [ "$EUID" -ne 0 ]
|
||||
then echo "Bitte mit sudo laufen lassen!"
|
||||
exit
|
||||
fi
|
||||
|
||||
# generell update
|
||||
sudo apt-get update
|
||||
sudo apt-get upgrade
|
||||
apt-get update
|
||||
apt-get upgrade
|
||||
|
||||
# wir brauchen python3
|
||||
sudo apt install python3
|
||||
apt install python3
|
||||
# wir brauchen pip3
|
||||
sudo apt-get install python3-pip
|
||||
apt-get install python3-pip
|
||||
#Nö: sudo pip3 install --upgrade setuptools
|
||||
|
||||
# Run the following command to install the Raspberry PI GPIO library:
|
||||
|
@ -28,3 +31,22 @@ sudo apt-get install python3-pip
|
|||
#pip3 install adafruit-blinka
|
||||
|
||||
sudo pip3 install Adafruit_DHT
|
||||
|
||||
|
||||
# Skripte nach usr/bin kopieren
|
||||
cp src/temp+feucht-DHT22.py /usr/bin/temp+feucht-DHT22.py
|
||||
cp src/weight-datageneration.py /usr/bin/weight-datageneration.py
|
||||
|
||||
# systemd unit files kopieren und chmod
|
||||
cp src/systemd/temp+feuchte-sammler.service /etc/systemd/system/temp+feuchte-sammler.service
|
||||
chmod 644 /etc/systemd/system/temp+feuchte-sammler.service
|
||||
cp src/systemd/weight-sammler.service /etc/systemd/system/weight-sammler.service
|
||||
chmod 644 /etc/systemd/system/weight-sammler.service
|
||||
|
||||
# services enablen - starten so automatisch
|
||||
systemctl enable temp+feuchte-sammler
|
||||
systemctl enable weight-sammler
|
||||
|
||||
# und starten
|
||||
systemctl start temp+feuchte-sammler
|
||||
systemctl start weight-sammler
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Temperatur und Luftfeuchte-Sammler-service.
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/bin/python3 /usr/bin/temp+feucht-DHT22.py
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Gewicht-Sammler-service.
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/bin/python3 /usr/bin/weight-datageneration.py
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
|
@ -1,43 +1,48 @@
|
|||
#!/usr/bin/python
|
||||
# Author: Robert Köpferl
|
||||
# Skript, um Sensoren des Typs AD2302 auszulesen und die umgerechneten
|
||||
# Temperatur und Feuchte-Werte zu pushen
|
||||
# Temperatur und Luftfeuchte-Werte zu pushen
|
||||
|
||||
import sys
|
||||
|
||||
import Adafruit_DHT
|
||||
import datetime
|
||||
import time
|
||||
#import Adafruit_DHT
|
||||
|
||||
|
||||
# Einfach alle Sensoren der Reihe nach auslesen
|
||||
|
||||
sensor = [
|
||||
{'Name': 'Bienen0_o', 'Pin': 24, 'Ziel': 'B0-o'},
|
||||
{'Name': 'Bienen0_u', 'Pin': 26, 'Ziel': 'B0-u'},
|
||||
{'Name': 'Bienen1_o', 'Pin': 32, 'Ziel': 'B1-o'},
|
||||
{'Name': 'Bienen1_u', 'Pin': 36, 'Ziel': 'B1-u'},
|
||||
{'Name': 'Bienen2_o', 'Pin': 38, 'Ziel': 'B2-o'},
|
||||
{'Name': 'Bienen2_u', 'Pin': 40, 'Ziel': 'B2-u'},
|
||||
sensoren = [
|
||||
{'Name': 'Bienen0_o', 'GPIO': 8, 'Pin': 24, 'Ziel': 'B0-o'},
|
||||
{'Name': 'Bienen0_u', 'GPIO': 7, 'Pin': 26, 'Ziel': 'B0-u'},
|
||||
{'Name': 'Bienen1_o', 'GPIO': 12, 'Pin': 32, 'Ziel': 'B1-o'},
|
||||
{'Name': 'Bienen1_u', 'GPIO': 16, 'Pin': 36, 'Ziel': 'B1-u'},
|
||||
{'Name': 'Bienen2_o', 'GPIO': 20, 'Pin': 38, 'Ziel': 'B2-o'},
|
||||
{'Name': 'Bienen2_u', 'GPIO': 21, 'Pin': 40, 'Ziel': 'B2-u'},
|
||||
]
|
||||
intervall = 10
|
||||
jez = datetime.datetime.now().isoformat()
|
||||
|
||||
* GPIO8 (24) (Bienen0) - Sensor A
|
||||
* GPIO7 (26) (Bienen0) - Sensor B
|
||||
* GPIO12 (32) (Bienen1) - Sensor A
|
||||
* GPIO16 (36) (Bienen1) - Sensor B
|
||||
* GPIO20 (38) (Bienen2) - Sensor A
|
||||
* GPIO21 (40) (Bienen2) - Sensor B
|
||||
print(f"{jez}: Starten von AD2302-Auslese-Skript. Läuft dauerhaft, periodisches Abfragen im Intervall: {intervall}s. Folgende Sensoren konfiguriert:")
|
||||
|
||||
# Try to grab a sensor reading. Use the read_retry method which will retry up
|
||||
# to 15 times to get a sensor reading (waiting 2 seconds between each retry).
|
||||
humidity, temperature = Adafruit_DHT.read(sensor, pin)
|
||||
for sensor in sensoren:
|
||||
print( sensor['Name'], "@ GPIO:", sensor['GPIO'], "/ Pin: ", sensor['Pin'])
|
||||
|
||||
while True:
|
||||
for sensor in sensoren:
|
||||
gpio = sensor['GPIO']
|
||||
# Try to grab a sensor reading. Use the read_retry method which will retry up
|
||||
# to 15 times to get a sensor reading (waiting 2 seconds between each retry).
|
||||
# using read fails immediately
|
||||
#humidity, temperature = Adafruit_DHT.read('22', gpio)
|
||||
humidity, temperature = None,None
|
||||
|
||||
|
||||
# Note that sometimes you won't get a reading and
|
||||
# the results will be null (because Linux can't
|
||||
# guarantee the timing of calls to read the sensor).
|
||||
# If this happens try again!
|
||||
if humidity is not None and temperature is not None:
|
||||
print('Temp={0:0.1f}* Humidity={1:0.1f}%'.format(temperature, humidity))
|
||||
else:
|
||||
print('Failed to get reading. Try again!')
|
||||
sys.exit(1)
|
||||
# Note that sometimes you won't get a reading and
|
||||
# the results will be null (because Linux can't
|
||||
# guarantee the timing of calls to read the sensor).
|
||||
# If this happens try again!
|
||||
if humidity is not None and temperature is not None:
|
||||
print('Temp={0:0.1f}°C Humidity={1:0.1f}%'.format(temperature, humidity))
|
||||
else:
|
||||
jez = datetime.datetime.now().isoformat()
|
||||
print(f"{jez} Fehler bei Sensor {sensor['Name']} Pin:{sensor['Pin']} - keine Werte erhalten.")
|
||||
# eine Runde pennen
|
||||
time.sleep(intervall)
|
||||
|
|
Loading…
Reference in New Issue