Einfach nur den Befehl per Konsole aufrufen oder vorher löschen , dann mittels Touch erstellen und per nano ergänzen?udo1toni hat geschrieben: ↑11. Jul 2020 01:02 Aus irgendeinem Grund scheint derBefehl gar nicht erst ausgeführt zu werden. Ich würde da jetzt erst mal auf die whitelist tippen, da hat es schön mehrfach Probleme gegeben.
Hast Du mal die whitelist einfach neu abgespeichert? Am einfachsten geht das von der Konsole aus perCode: Alles auswählen
sudo touch /etc/openhab2/misc/exec.whitelist
Gesendet von iPad mit Tapatalk
Ultraschallsensor in OpenHAB intigrieren
-
- Beiträge: 167
- Registriert: 1. Jun 2020 17:29
Re: Ultraschallsensor in OpenHAB intigrieren
- udo1toni
- Beiträge: 15248
- Registriert: 11. Apr 2018 18:05
- Wohnort: Darmstadt
Re: Ultraschallsensor in OpenHAB intigrieren
Einfach nur den Befehl ausführen. Das sollte dazu führen, dass das laufende openHAB die Datei neu einliest, da sich der Zeitstempel der Datei geändert hat (da gibt es einen Dienst in karaf, der die Verzeichnisse daraufhin überwacht...)
Gesendet von iPad mit Tapatalk
Gesendet von iPad mit Tapatalk
openHAB4.3.3 stable in einem Debian-Container (bookworm) (Proxmox 8.3.5, LXC), mit openHABian eingerichtet
-
- Beiträge: 167
- Registriert: 1. Jun 2020 17:29
Re: Ultraschallsensor in OpenHAB intigrieren
Leider auch nicht der gewünschte Erfolg.udo1toni hat geschrieben: ↑11. Jul 2020 14:28 Einfach nur den Befehl ausführen. Das sollte dazu führen, dass das laufende openHAB die Datei neu einliest, da sich der Zeitstempel der Datei geändert hat (da gibt es einen Dienst in karaf, der die Verzeichnisse daraufhin überwacht...)
Gesendet von iPad mit Tapatalk
Ich als Laie denke aber dass er das Skript ausführt, da man eine Meldung bekommt, wenn man es händisch startet,
dass das Skript schon läuft.
Code: Alles auswählen
[14:55:06] openhabian@openhab:~$ sudo python /etc/openhab2/scripts/hc.py
[sudo] Passwort für openhabian:
/etc/openhab2/scripts/hc.py:9: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(GPIO_TRIGGER, GPIO.OUT)
110.9 cm
Code: Alles auswählen
[14:55:44] openhabian@openhab:~$ sudo python /etc/openhab2/scripts/hc.py
111.4 cm
Zuletzt geändert von Pepe1907 am 11. Jul 2020 15:00, insgesamt 1-mal geändert.
- udo1toni
- Beiträge: 15248
- Registriert: 11. Apr 2018 18:05
- Wohnort: Darmstadt
Re: Ultraschallsensor in OpenHAB intigrieren
Nein.
Die Meldung besagt, dass die Port schon benutzt werden.
Diese Meldung kann aber auch kommen, wenn schlicht Rechte fehlen.
Ob das Script ausgeführt wird, kannst Du nur feststellen, indem Du im Script Logging einrichtest und dieses Log anschließend prüfst.
Ich schau nachher mal, ob ich Dir Beispielcode schicken kann (geht vom Laptop besser als vom iPad...)
Gesendet von iPad mit Tapatalk
Die Meldung besagt, dass die Port schon benutzt werden.
Diese Meldung kann aber auch kommen, wenn schlicht Rechte fehlen.
Ob das Script ausgeführt wird, kannst Du nur feststellen, indem Du im Script Logging einrichtest und dieses Log anschließend prüfst.
Ich schau nachher mal, ob ich Dir Beispielcode schicken kann (geht vom Laptop besser als vom iPad...)
Gesendet von iPad mit Tapatalk
openHAB4.3.3 stable in einem Debian-Container (bookworm) (Proxmox 8.3.5, LXC), mit openHABian eingerichtet
-
- Beiträge: 167
- Registriert: 1. Jun 2020 17:29
Re: Ultraschallsensor in OpenHAB intigrieren
Vielen lieben Dank.udo1toni hat geschrieben: ↑11. Jul 2020 14:58 Nein.
Die Meldung besagt, dass die Port schon benutzt werden.
Diese Meldung kann aber auch kommen, wenn schlicht Rechte fehlen.
Ob das Script ausgeführt wird, kannst Du nur feststellen, indem Du im Script Logging einrichtest und dieses Log anschließend prüfst.
Ich schau nachher mal, ob ich Dir Beispielcode schicken kann (geht vom Laptop besser als vom iPad...)
Gesendet von iPad mit Tapatalk
Dann werde ich mal gespannt warten.
Habe selbst mal recherchiert.
hc.py
Code: Alles auswählen
#Bibliotheken
import RPi.GPIO as GPIO
import time
import logging
logging.basicConfig(filename='example.log', filemode='w', level=logging.INFO)
#GPIO definieren (Modus, Pins, Output)
GPIO.setmode(GPIO.BCM)
GPIO_TRIGGER = 18
GPIO_ECHO = 24
GPIO.setup(GPIO_TRIGGER, GPIO.OUT)
GPIO.setup(GPIO_ECHO, GPIO.IN)
def do_something():
logging.info('Skript gestartet')
def entfernung():
# Trig High setzen
GPIO.output(GPIO_TRIGGER, True)
# Trig Low setzen (nach 0.01ms)
time.sleep(0.00001)
GPIO.output(GPIO_TRIGGER, False)
Startzeit = time.time()
Endzeit = time.time()
# Start/Stop Zeit ermitteln
while GPIO.input(GPIO_ECHO) == 0:
Startzeit = time.time()
while GPIO.input(GPIO_ECHO) == 1:
Endzeit = time.time()
# Vergangene Zeit
Zeitdifferenz = Endzeit - Startzeit
# Schallgeschwindigkeit (34300 cm/s) einbeziehen
entfernung = 133 - (Zeitdifferenz * 34300) / 2
return entfernung
if __name__ == '__main__':
try:
while True:
distanz = entfernung()
print (" %.1f cm" % distanz)
time.sleep(20)
# Programm beenden
except KeyboardInterrupt:
print("Programm abgebrochen")
GPIO.cleanup()
- udo1toni
- Beiträge: 15248
- Registriert: 11. Apr 2018 18:05
- Wohnort: Darmstadt
Re: Ultraschallsensor in OpenHAB intigrieren
Ja, das passt schon fast.
Du hast aber das Problem, dass Du zwar eine Routine anlegst, in der Du eine Logzeile ausgibst, dieese Routine wird aber niemals ausgeführt (do_something)
Stattdessen musst Du natürlich den Befehl logging.info('irgendeine Message') z.B. in die Routine entfernung() einbauen, z.B. unmittelbar vor der Zeile
Eine andere Sache, die mir gerade auffällt: Das Programm wartet auf eine Tastatureingabe, um beendet zu werden. Das muss natürlich weg! So, wie das Programm momentan geschrieben ist, wird es gestartet und läuft ewig. also statt
einfach
Und schau mal mittels
ob da vielleicht eine (oder gar mehrere) Instanz(en) des Programms läuft/laufen.
Um ohne Neustart alle loszuwerden, kannst Du mit die einzelnen Instanzen los werden, also z.B.
für das Programm mit der PID 10456.
Du hast aber das Problem, dass Du zwar eine Routine anlegst, in der Du eine Logzeile ausgibst, dieese Routine wird aber niemals ausgeführt (do_something)
Stattdessen musst Du natürlich den Befehl logging.info('irgendeine Message') z.B. in die Routine entfernung() einbauen, z.B. unmittelbar vor der Zeile
Code: Alles auswählen
return entfernung
Code: Alles auswählen
if __name__ == '__main__':
try:
while True:
distanz = entfernung()
print (" %.1f cm" % distanz)
time.sleep(20)
# Programm beenden
except KeyboardInterrupt:
print("Programm abgebrochen")
GPIO.cleanup()
Code: Alles auswählen
if __name__ == '__main__':
try:
distanz = entfernung()
print (" %.1f cm" % distanz)
GPIO.cleanup()
Code: Alles auswählen
ps aux | grep -i python
Um ohne Neustart alle loszuwerden, kannst Du mit
Code: Alles auswählen
sudo kill <PID>
Code: Alles auswählen
sudo kill 10456
openHAB4.3.3 stable in einem Debian-Container (bookworm) (Proxmox 8.3.5, LXC), mit openHABian eingerichtet
-
- Beiträge: 167
- Registriert: 1. Jun 2020 17:29
Re: Ultraschallsensor in OpenHAB intigrieren
Vielen Dank
Skirpt sieht jetzt wie folgt aus.
Skirpt sieht jetzt wie folgt aus.
Code: Alles auswählen
#Bibliotheken
import RPi.GPIO as GPIO
import time
import logging
logging.basicConfig(filename='teich.log', filemode='w', level=logging.INFO)
#GPIO definieren (Modus, Pins, Output)
GPIO.setmode(GPIO.BCM)
GPIO_TRIGGER = 18
GPIO_ECHO = 24
GPIO.setup(GPIO_TRIGGER, GPIO.OUT)
GPIO.setup(GPIO_ECHO, GPIO.IN)
def entfernung():
logging.info ('Skript gestartet')
# Trig High setzen
GPIO.output(GPIO_TRIGGER, True)
# Trig Low setzen (nach 0.01ms)
time.sleep(0.00001)
GPIO.output(GPIO_TRIGGER, False)
Startzeit = time.time()
Endzeit = time.time()
# Start/Stop Zeit ermitteln
while GPIO.input(GPIO_ECHO) == 0:
Startzeit = time.time()
while GPIO.input(GPIO_ECHO) == 1:
Endzeit = time.time()
# Vergangene Zeit
Zeitdifferenz = Endzeit - Startzeit
# Schallgeschwindigkeit (34300 cm/s) einbeziehen
entfernung = 133 - (Zeitdifferenz * 34300) / 2
return entfernung
if __name__ == '__main__':
try:
while True:
distanz = entfernung()
print (" %.1f cm" % distanz)
time.sleep(20)
GPIO.cleanup()
Zuletzt geändert von Pepe1907 am 11. Jul 2020 16:10, insgesamt 3-mal geändert.
-
- Beiträge: 167
- Registriert: 1. Jun 2020 17:29
Re: Ultraschallsensor in OpenHAB intigrieren
Code: Alles auswählen
[15:49:22] openhabian@openhab:~$ ps aux | grep -i python
root 562 0.0 1.5 38708 15740 ? Ssl Jul10 0:00 /usr/bin/python 3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal
openhab 978 0.0 0.0 1940 372 ? S Jul10 0:00 sh -c sudo /usr /bin/python /etc/openhab2/scripts/hc.py
root 979 0.0 0.3 10028 3300 ? S Jul10 0:00 sudo /usr/bin/p ython /etc/openhab2/scripts/hc.py
openhab 980 0.0 0.0 1940 356 ? S Jul10 0:00 sh -c sudo /usr /bin/python /etc/openhab2/scripts/hc.py
root 982 0.0 0.3 10028 3240 ? S Jul10 0:00 sudo /usr/bin/p ython /etc/openhab2/scripts/hc.py
root 992 2.7 0.5 12040 5048 ? R Jul10 29:50 /usr/bin/python /etc/openhab2/scripts/hc.py
root 993 2.6 0.4 12040 4940 ? R Jul10 28:40 /usr/bin/python /etc/openhab2/scripts/hc.py
openhab+ 1927 0.0 0.0 7360 528 pts/0 S+ 15:50 0:00 grep --color=au to -i python
openhab 4652 0.0 0.0 1940 368 ? S Jul10 0:00 sh -c sudo /usr /bin/python /etc/openhab2/scripts/hc.py
root 4654 0.0 0.3 10028 3224 ? S Jul10 0:00 sudo /usr/bin/p ython /etc/openhab2/scripts/hc.py
root 4660 2.8 0.5 12040 5052 ? R Jul10 28:57 /usr/bin/python /etc/openhab2/scripts/hc.py
openhab 31727 0.0 0.0 1940 404 ? S 14:56 0:00 sh -c sudo /usr /bin/python /etc/openhab2/scripts/hc.py
root 31729 0.0 0.3 10028 3336 ? S 14:56 0:00 sudo /usr/bin/p ython /etc/openhab2/scripts/hc.py
root 31736 52.4 0.5 12040 5048 ? R 14:56 28:02 /usr/bin/python /etc/openhab2/scripts/hc.py
openhab 32741 0.0 0.0 1940 408 ? S 15:16 0:00 sh -c sudo /usr /bin/python /etc/openhab2/scripts/hc.py
root 32742 0.0 0.3 10028 3456 ? S 15:16 0:00 sudo /usr/bin/p ython /etc/openhab2/scripts/hc.py
root 32750 49.2 0.5 12448 5476 ? R 15:16 16:33 /usr/bin/python /etc/openhab2/scripts/hc.py
[15:50:17] openhabian@openhab:~$ sudo kill <PID>
-bash: Syntaxfehler beim unerwarteten Wort `newline'
-
- Beiträge: 167
- Registriert: 1. Jun 2020 17:29
Re: Ultraschallsensor in OpenHAB intigrieren
Habe jetzt alle hänidsch geschlossen.Pepe1907 hat geschrieben: ↑11. Jul 2020 15:51kann sie leider nicht schließenCode: Alles auswählen
[15:49:22] openhabian@openhab:~$ ps aux | grep -i python root 562 0.0 1.5 38708 15740 ? Ssl Jul10 0:00 /usr/bin/python 3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal openhab 978 0.0 0.0 1940 372 ? S Jul10 0:00 sh -c sudo /usr /bin/python /etc/openhab2/scripts/hc.py root 979 0.0 0.3 10028 3300 ? S Jul10 0:00 sudo /usr/bin/p ython /etc/openhab2/scripts/hc.py openhab 980 0.0 0.0 1940 356 ? S Jul10 0:00 sh -c sudo /usr /bin/python /etc/openhab2/scripts/hc.py root 982 0.0 0.3 10028 3240 ? S Jul10 0:00 sudo /usr/bin/p ython /etc/openhab2/scripts/hc.py root 992 2.7 0.5 12040 5048 ? R Jul10 29:50 /usr/bin/python /etc/openhab2/scripts/hc.py root 993 2.6 0.4 12040 4940 ? R Jul10 28:40 /usr/bin/python /etc/openhab2/scripts/hc.py openhab+ 1927 0.0 0.0 7360 528 pts/0 S+ 15:50 0:00 grep --color=au to -i python openhab 4652 0.0 0.0 1940 368 ? S Jul10 0:00 sh -c sudo /usr /bin/python /etc/openhab2/scripts/hc.py root 4654 0.0 0.3 10028 3224 ? S Jul10 0:00 sudo /usr/bin/p ython /etc/openhab2/scripts/hc.py root 4660 2.8 0.5 12040 5052 ? R Jul10 28:57 /usr/bin/python /etc/openhab2/scripts/hc.py openhab 31727 0.0 0.0 1940 404 ? S 14:56 0:00 sh -c sudo /usr /bin/python /etc/openhab2/scripts/hc.py root 31729 0.0 0.3 10028 3336 ? S 14:56 0:00 sudo /usr/bin/p ython /etc/openhab2/scripts/hc.py root 31736 52.4 0.5 12040 5048 ? R 14:56 28:02 /usr/bin/python /etc/openhab2/scripts/hc.py openhab 32741 0.0 0.0 1940 408 ? S 15:16 0:00 sh -c sudo /usr /bin/python /etc/openhab2/scripts/hc.py root 32742 0.0 0.3 10028 3456 ? S 15:16 0:00 sudo /usr/bin/p ython /etc/openhab2/scripts/hc.py root 32750 49.2 0.5 12448 5476 ? R 15:16 16:33 /usr/bin/python /etc/openhab2/scripts/hc.py [15:50:17] openhabian@openhab:~$ sudo kill <PID> -bash: Syntaxfehler beim unerwarteten Wort `newline'
Code: Alles auswählen
[16:07:21] openhabian@openhab:~$ sudo python /etc/openhab2/scripts/hc.py
File "/etc/openhab2/scripts/hc.py", line 49
^
IndentationError: unexpected unindent
und das passiert im openhab.log
2020-07-11 16:20:25.576 [vent.ItemStateChangedEvent] - teichmessung changed from OFF to ON
2020-07-11 16:20:25.749 [vent.ItemStateChangedEvent] - teichmessung changed from ON to OFF
==> /var/log/openhab2/openhab.log <==
2020-07-11 16:20:25.756 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Teichstand': For input string: "File "/etc/openhab2/scripts/hc.py", line 49
^
IndentationError: unexpected unindent
File "/etc/openhab2/scripts/hc.py", line 49
^
Zuletzt geändert von Pepe1907 am 11. Jul 2020 16:21, insgesamt 1-mal geändert.
- udo1toni
- Beiträge: 15248
- Registriert: 11. Apr 2018 18:05
- Wohnort: Darmstadt
Re: Ultraschallsensor in OpenHAB intigrieren
Schau Dir bitte mal genau an, was ich gepostet habe. 
Eventuell muss sogar noch das try: weg.
Dann sähe es so aus:

Eventuell muss sogar noch das try: weg.
Dann sähe es so aus:
Code: Alles auswählen
if __name__ == '__main__':
distanz = entfernung()
print (" %.1f cm" % distanz)
GPIO.cleanup()
openHAB4.3.3 stable in einem Debian-Container (bookworm) (Proxmox 8.3.5, LXC), mit openHABian eingerichtet