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 os
import traceback
import threading
import sys
import sqlite3
import RPi.GPIO as GPIO
@@ -130,6 +131,9 @@ uSpot_profile_id = 1
conn = sqlite3.connect("/var/www/nebuleair_pro_4g/sqlite/sensors.db")
cursor = conn.cursor()
_gpio_lock = threading.Lock() # Global lock for GPIO access
def blink_led(pin, blink_count, delay=1):
"""
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.
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.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:
for _ in range(blink_count):
GPIO.output(pin, GPIO.HIGH) # Turn the LED on
#print(f"LED on GPIO {pin} is ON")
time.sleep(delay) # Wait for the specified delay
GPIO.output(pin, GPIO.LOW) # Turn the LED off
#print(f"LED on GPIO {pin} is OFF")
time.sleep(delay) # Wait for the specified delay
GPIO.output(pin, GPIO.HIGH) # Turn LED on
time.sleep(delay)
GPIO.output(pin, GPIO.LOW) # Turn LED off
time.sleep(delay)
finally:
GPIO.cleanup(pin) # Clean up the specific pin to reset its state
print(f"GPIO {pin} cleaned up")
GPIO.output(pin, GPIO.LOW) # Ensure LED is off
print(f"LED on GPIO {pin} turned OFF (cleanup avoided)")
#get data from config
def load_config(config_file):