Hallo es geht um folgenden Code
import RPi.GPIO as GPIO
import time
import datetime
import os
import subprocess
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def play_sound():
# Audiodatei abspielen
subprocess.Popen(["vlc", "--play-and-exit", "/home/loxice/Desktop/test.mp3"])
def log_vibration(duration):
# Log-Datei erstellen/anhängen
logfile_name = datetime.datetime.now().strftime("%Y-%m-%d") + ".txt"
log_dir = "/home/loxice/Log A/"
if not os.path.exists(log_dir):
os.makedirs(log_dir)
logfile_path = log_dir + logfile_name
with open(logfile_path, "a") as logfile:
logfile.write("Vibration detected at " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + " for " + str(duration) + " seconds\n")
def detect_vibration():
vibration_start = None
while True:
if GPIO.input(12) == 0:
if vibration_start is None:
vibration_start = time.time()
else:
if vibration_start:
vibration_duration = time.time() - vibration_start
log_vibration(vibration_duration)
if 6 <= datetime.datetime.now().hour <= 8 or 18 <= datetime.datetime.now().hour <= 20:
play_sound()
vibration_start = None
time.sleep(0.1)
detect_vibration()
Ich habe das Problem das keine Soundausgabe stattfindet. das Log wird angelegt. Das Script startet automatisch mit dem Starten des Raspberry.
es wird auch kein Fehler ausgespuckt... bin etwas am verzweifeln.
kann mir bitte jemand helfen ?
Ich bedanke mich bereits vielmals im vorraus