Hey guys,
since I’ve learned a lot in this forum, I’m facing a problem which i can’t solve by searching the forum.
I’m using 2 different python scripts in my OpenHab installation. The first one is for a DHT22 sensor, which i’m using for a longer time with no problems. The second one is for 6x HC-SR04 sensors which control my garage door.
Unfortunately the scripts stop working after ~2 hours. The scripts are not called anymore by OpenHab. When I call them via shell, they start to work for some time (the items are updated again) and stop again.
The log files don’t put up any errors regarding my scripts.
Since I call the second script for each of the 6 HC-SR04 every second, i think this might cause some problems. Is there a limit for the calls of python scripts?
I hope you can guide me to the mistake in my project
Best Regards
OpenHab Version: 2.5.0~S1486-1
- DHT22 Sensor
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#import Adafruit_BMP.BMP085 as BMP085
import Adafruit_DHT
import sys, time
# constants
DHT_PIN = 4 # GPIO nr
DHT_SENSOR = Adafruit_DHT.DHT22
if __name__ == '__main__':
if len(sys.argv) > 1:
call = sys.argv[1].lower()
if call == 'temperature':
temperature = None
while temperature == None:
_, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)
if temperature == None:
time.sleep(1.5)
print(temperature)
elif call == 'humidity':
humidity = None
while humidity == None:
humidity, _ = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)
if humidity == None:
time.sleep(1.5)
print(humidity)
elif call == 'pressure':
#sensor = BMP085.BMP085()
print(100.0)
- HC-SR04 Sensors (6x), which use the same python script (just the GPIO are changed)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
import time
if __name__ == '__main__':
#GPIO Modus (BOARD / BCM)
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
#GPIO Pins zuweisen
GPIO_TRIGGER = 25
GPIO_ECHO = 8
#Richtung der GPIO-Pins festlegen (IN / OUT) l
GPIO.setup(GPIO_TRIGGER, GPIO.OUT)
GPIO.setup(GPIO_ECHO, GPIO.IN)
# setze Trigger auf HIGH
GPIO.output(GPIO_TRIGGER, True)
# setze Trigger nach 0.01ms aus LOW
time.sleep(0.00001)
GPIO.output(GPIO_TRIGGER, False)
StartZeit = time.time()
StopZeit = time.time()
# speichere Startzeit
while GPIO.input(GPIO_ECHO) == 0:
StartZeit = time.time()
# speichere Ankunftszeit
while GPIO.input(GPIO_ECHO) == 1:
StopZeit = time.time()
# Zeit Differenz zwischen Start und Ankunft
TimeElapsed = StopZeit - StartZeit
# mit der Schallgeschwindigkeit (34300 cm/s) multiplizieren
# und durch 2 teilen, da hin und zurueck
distanz = (TimeElapsed * 34300) / 2
# GPIO.cleanup()
print (distanz)
Things:
Thing exec:command:weatherstation_temperature "Temperatur" [command="/etc/openhab2/scripts/weatherstation.py temperature", transform="REGEX((.*?))", interval=60, timeout=10, autorun=true]
Thing exec:command:weatherstation_humidity "Luftfeuchtigkeit" [command="/etc/openhab2/scripts/weatherstation.py humidity", transform="REGEX((.*?))", interval=60, timeout=10, autorun=true]
Thing exec:command:uss_sensor1 "Polo 1" [command="/etc/openhab2/scripts/uss_sensor4.py", transform="REGEX((.*?))", interval=1, timeout=10, autorun=true]
Thing exec:command:uss_sensor2 "Polo 2" [command="/etc/openhab2/scripts/uss_sensor5.py", interval=1, timeout=10, autorun=true]
Thing exec:command:uss_sensor3 "Polo 3" [command="/etc/openhab2/scripts/uss_sensor6.py", interval=1, timeout=10, autorun=true]
Thing exec:command:uss_sensor4 "Audi 1" [command="/etc/openhab2/scripts/uss_sensor1.py", interval=1, timeout=10, autorun=true]
Thing exec:command:uss_sensor5 "Audi 2" [command="/etc/openhab2/scripts/uss_sensor2.py", interval=1, timeout=10, autorun=true]
Thing exec:command:uss_sensor6 "Audi 3" [command="/etc/openhab2/scripts/uss_sensor3.py", interval=1, timeout=10, autorun=true]
items:
//for the first script
Number Weatherstation_Temperature_unfiltered "ungefilterte Temperatur [%.1f °C]" <temperature>
Number Weatherstation_Humidity_unfiltered "ungefilterte Luftfeuchtigkeit [%.1f %%]" <humidity>
String temperature_out { channel="exec:command:weatherstation_temperature:output" }
String humidity_out { channel="exec:command:weatherstation_humidity:output" }
//for the second script
String Polo_uss_1 "Polo uss 1 [%d]" { channel="exec:command:uss_sensor1:output" }
String Polo_uss_2 "Polo uss 2 [%d]" { channel="exec:command:uss_sensor3:output" }
String Polo_uss_3 "Polo uss 3 [%d]" { channel="exec:command:uss_sensor2:output" }
String Audi_uss_1 "Audi uss 1 [%d]" { channel="exec:command:uss_sensor4:output" }
String Audi_uss_2 "Audi uss 2 [%d]" { channel="exec:command:uss_sensor5:output" }
String Audi_uss_3 "Audi uss 3 [%d]" { channel="exec:command:uss_sensor6:output" }