update
This commit is contained in:
@@ -99,6 +99,7 @@ import time
|
|||||||
import busio
|
import busio
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
|
import requests
|
||||||
import traceback
|
import traceback
|
||||||
import threading
|
import threading
|
||||||
import sys
|
import sys
|
||||||
@@ -325,6 +326,7 @@ try:
|
|||||||
row = cursor.fetchone() # Get the first (and only) row
|
row = cursor.fetchone() # Get the first (and only) row
|
||||||
rtc_time_str = row[1] # '2025-02-07 12:30:45' ou '2000-01-01 00:55:21' ou 'not connected'
|
rtc_time_str = row[1] # '2025-02-07 12:30:45' ou '2000-01-01 00:55:21' ou 'not connected'
|
||||||
print(rtc_time_str)
|
print(rtc_time_str)
|
||||||
|
|
||||||
if rtc_time_str == 'not connected':
|
if rtc_time_str == 'not connected':
|
||||||
print("⛔ Atttention RTC module not connected⛔")
|
print("⛔ Atttention RTC module not connected⛔")
|
||||||
rtc_status = "disconnected"
|
rtc_status = "disconnected"
|
||||||
@@ -481,14 +483,37 @@ try:
|
|||||||
response2 = read_complete_response(ser_sara, wait_for_lines=["OK"])
|
response2 = read_complete_response(ser_sara, wait_for_lines=["OK"])
|
||||||
|
|
||||||
#Here it's possible that the SARA do not repond at all
|
#Here it's possible that the SARA do not repond at all
|
||||||
#-> try to establish connection
|
#-> TO DO : harware reboot
|
||||||
|
#-> send notification
|
||||||
#-> end loop, no need to continue
|
#-> end loop, no need to continue
|
||||||
if response2 is None or response2 == "" or not any(expected in response2 for expected in ["OK", "ERROR", "+", "AT"]):
|
if response2 is None or response2 == "" or not any(expected in response2 for expected in ["OK", "ERROR", "+", "AT"]):
|
||||||
print("No answer from SARA module")
|
print("No answer from SARA module")
|
||||||
print('🛑STOP LOOP🛑')
|
print('🛑STOP LOOP🛑')
|
||||||
print("<hr>")
|
print("<hr>")
|
||||||
|
|
||||||
|
# Send notification
|
||||||
|
try:
|
||||||
|
# Format the URL with the device_id
|
||||||
|
alert_url = f'http://data.nebuleair.fr/pro_4G/alert.php?capteur_id={device_id}&error_type=serial_error'
|
||||||
|
|
||||||
|
# Send POST request with short timeout
|
||||||
|
response = requests.post(alert_url, timeout=3)
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
print(f"Alert notification sent successfully")
|
||||||
|
else:
|
||||||
|
print(f"Alert notification failed with status code: {response.status_code}")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
# Catch any exception and continue
|
||||||
|
print(f"Alert notification failed: {e}")
|
||||||
|
|
||||||
|
#end loop
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
else :
|
||||||
|
print("✅SARA is connected over serial")
|
||||||
|
|
||||||
print('<p class="text-danger-emphasis">')
|
print('<p class="text-danger-emphasis">')
|
||||||
print(response2)
|
print(response2)
|
||||||
print("</p>", end="")
|
print("</p>", end="")
|
||||||
@@ -730,9 +755,9 @@ try:
|
|||||||
|
|
||||||
print(f'<div class="text-primary">Time difference: {time_diff:.2f} seconds</div>', end="")
|
print(f'<div class="text-primary">Time difference: {time_diff:.2f} seconds</div>', end="")
|
||||||
|
|
||||||
# Check if difference is more than 10 seconds
|
# Check if difference is more than 60 seconds
|
||||||
# and update the RTC clock
|
# and update the RTC clock
|
||||||
if time_diff > 10:
|
if time_diff > 60:
|
||||||
print(f'<div class="text-warning"><strong>⚠️ RTC time differs from server time by {time_diff:.2f} seconds!</strong></div>', end="")
|
print(f'<div class="text-warning"><strong>⚠️ RTC time differs from server time by {time_diff:.2f} seconds!</strong></div>', end="")
|
||||||
# Format server time for RTC update
|
# Format server time for RTC update
|
||||||
server_time_formatted = server_datetime.strftime('%Y-%m-%d %H:%M:%S')
|
server_time_formatted = server_datetime.strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
|||||||
@@ -30,6 +30,15 @@ cursor.execute("""
|
|||||||
VALUES (1, CURRENT_TIMESTAMP);
|
VALUES (1, CURRENT_TIMESTAMP);
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
#create a modem status table
|
||||||
|
cursor.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS modem_status (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
timestamp TEXT,
|
||||||
|
status TEXT
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
# Create a table NPM
|
# Create a table NPM
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
CREATE TABLE IF NOT EXISTS data_NPM (
|
CREATE TABLE IF NOT EXISTS data_NPM (
|
||||||
|
|||||||
Reference in New Issue
Block a user