This commit is contained in:
Your Name
2025-02-27 11:07:52 +01:00
parent ec6fbf6bb2
commit 700de9c9f4

View File

@@ -95,6 +95,7 @@ import busio
import re import re
import os import os
import traceback import traceback
import threading
import sys import sys
import sqlite3 import sqlite3
import RPi.GPIO as GPIO import RPi.GPIO as GPIO
@@ -130,6 +131,9 @@ uSpot_profile_id = 1
conn = sqlite3.connect("/var/www/nebuleair_pro_4g/sqlite/sensors.db") conn = sqlite3.connect("/var/www/nebuleair_pro_4g/sqlite/sensors.db")
cursor = conn.cursor() cursor = conn.cursor()
_gpio_lock = threading.Lock() # Global lock for GPIO access
def blink_led(pin, blink_count, delay=1): def blink_led(pin, blink_count, delay=1):
""" """
Blink an LED on a specified GPIO pin. Blink an LED on a specified GPIO pin.
@@ -139,22 +143,21 @@ def blink_led(pin, blink_count, delay=1):
blink_count (int): Number of times the LED should blink. blink_count (int): Number of times the LED should blink.
delay (float): Time in seconds for the LED to stay ON or OFF (default is 1 second). delay (float): Time in seconds for the LED to stay ON or OFF (default is 1 second).
""" """
# GPIO setup with _gpio_lock:
GPIO.setwarnings(False) GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM) # Use BCM numbering GPIO.setmode(GPIO.BCM) # Use BCM numbering
GPIO.setup(pin, GPIO.OUT) # Set the specified pin as an output GPIO.setup(pin, GPIO.OUT) # Ensure pin is set as OUTPUT
try: try:
for _ in range(blink_count): for _ in range(blink_count):
GPIO.output(pin, GPIO.HIGH) # Turn the LED on GPIO.output(pin, GPIO.HIGH) # Turn LED on
#print(f"LED on GPIO {pin} is ON") time.sleep(delay)
time.sleep(delay) # Wait for the specified delay GPIO.output(pin, GPIO.LOW) # Turn LED off
GPIO.output(pin, GPIO.LOW) # Turn the LED off time.sleep(delay)
#print(f"LED on GPIO {pin} is OFF")
time.sleep(delay) # Wait for the specified delay
finally: finally:
GPIO.cleanup(pin) # Clean up the specific pin to reset its state GPIO.output(pin, GPIO.LOW) # Ensure LED is off
print(f"GPIO {pin} cleaned up") print(f"LED on GPIO {pin} turned OFF (cleanup avoided)")
#get data from config #get data from config
def load_config(config_file): def load_config(config_file):