diff --git a/loop/SARA_send_data_v2.py b/loop/SARA_send_data_v2.py
index b6f26ce..731bc1d 100755
--- a/loop/SARA_send_data_v2.py
+++ b/loop/SARA_send_data_v2.py
@@ -99,6 +99,7 @@ import time
import busio
import re
import os
+import requests
import traceback
import threading
import sys
@@ -325,6 +326,7 @@ try:
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'
print(rtc_time_str)
+
if rtc_time_str == 'not connected':
print("⛔ Atttention RTC module not connected⛔")
rtc_status = "disconnected"
@@ -481,14 +483,37 @@ try:
response2 = read_complete_response(ser_sara, wait_for_lines=["OK"])
#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
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('🛑STOP LOOP🛑')
print("
")
+
+ # 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()
+ else :
+ print("✅SARA is connected over serial")
+
print('')
print(response2)
print("
", end="")
@@ -730,9 +755,9 @@ try:
print(f'Time difference: {time_diff:.2f} seconds
', end="")
- # Check if difference is more than 10 seconds
+ # Check if difference is more than 60 seconds
# and update the RTC clock
- if time_diff > 10:
+ if time_diff > 60:
print(f'⚠️ RTC time differs from server time by {time_diff:.2f} seconds!
', end="")
# Format server time for RTC update
server_time_formatted = server_datetime.strftime('%Y-%m-%d %H:%M:%S')
diff --git a/sqlite/create_db.py b/sqlite/create_db.py
index 8024cae..22b8553 100755
--- a/sqlite/create_db.py
+++ b/sqlite/create_db.py
@@ -30,6 +30,15 @@ cursor.execute("""
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
cursor.execute("""
CREATE TABLE IF NOT EXISTS data_NPM (