This commit is contained in:
Your Name
2025-03-28 16:41:54 +01:00
parent a6cb45a0bb
commit 5bf9586000
3 changed files with 139 additions and 39 deletions

View File

@@ -97,7 +97,6 @@ import os
import traceback
import sys
import sqlite3
import RPi.GPIO as GPIO
from threading import Thread
from datetime import datetime
@@ -130,31 +129,7 @@ uSpot_profile_id = 1
conn = sqlite3.connect("/var/www/moduleair_pro_4g/sqlite/sensors.db")
cursor = conn.cursor()
def blink_led(pin, blink_count, delay=1):
"""
Blink an LED on a specified GPIO pin.
Args:
pin (int): GPIO pin number (BCM mode) to which the LED is connected.
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
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM) # Use BCM numbering
GPIO.setup(pin, GPIO.OUT) # Set the specified pin as an 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
finally:
GPIO.cleanup(pin) # Clean up the specific pin to reset its state
print(f"GPIO {pin} cleaned up")
#get config data from SQLite table
def load_config_sqlite():
@@ -758,9 +733,6 @@ try:
print("Operation not allowed. This may require a different configuration.")
# Actions spécifiques pour ce type d'erreur
# Clignotement LED rouge en cas d'erreur
led_thread = Thread(target=blink_led, args=(24, 5, 0.5))
led_thread.start()
else:
# 2.Si la réponse contient une réponse HTTP valide
@@ -775,10 +747,7 @@ try:
print("*****")
print('<span style="color: red;font-weight: bold;">ATTENTION: HTTP operation failed</span>')
print("*****")
print("Blink red LED")
# Run LED blinking in a separate thread
led_thread = Thread(target=blink_led, args=(24, 5, 0.5))
led_thread.start()
# Get error code
print("Getting error code (11->Server connection error, 73->Secure socket connect error)")
@@ -820,9 +789,7 @@ try:
else:
# Si la commande HTTP a réussi
print('<span class="badge text-bg-success">✅✅HTTP operation successful.</span>')
print("Blink blue LED")
led_thread = Thread(target=blink_led, args=(23, 5, 0.5))
led_thread.start()
#4. Read reply from server
print("Reply from server:")
@@ -906,10 +873,7 @@ try:
#on a peut etre une ERROR de type "+CME ERROR: No connection to phone"
else:
print('<span style="color: red;font-weight: bold;">No UUHTTPCR response</span>')
print("Blink red LED")
# Run LED blinking in a separate thread
led_thread = Thread(target=blink_led, args=(24, 5, 0.5))
led_thread.start()
#Vérification de l'erreur
print("Getting type of error")
# Split the response into lines and search for "+CME ERROR:"