Compare commits
2 Commits
76336d0073
...
29f9ec445a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
29f9ec445a | ||
|
|
7b398d0d6d |
@@ -323,6 +323,49 @@ def extract_error_code(response):
|
||||
# Return None if we couldn't find the error code
|
||||
return None
|
||||
|
||||
def send_error_notification(device_id, error_type, additional_info=None):
|
||||
"""
|
||||
Send an error notification to the server when issues with the SARA module occur.
|
||||
Will silently fail if there's no internet connection.
|
||||
|
||||
Parameters:
|
||||
-----------
|
||||
device_id : str
|
||||
The unique identifier of the device
|
||||
error_type : str
|
||||
Type of error encountered (e.g., 'serial_error', 'cme_error', 'http_error', 'timeout')
|
||||
additional_info : str, optional
|
||||
Any additional information about the error for logging purposes
|
||||
|
||||
Returns:
|
||||
--------
|
||||
bool
|
||||
True if notification was sent successfully, False otherwise
|
||||
"""
|
||||
|
||||
# Create the alert URL with all relevant parameters
|
||||
base_url = 'http://data.nebuleair.fr/pro_4G/alert.php'
|
||||
alert_url = f'{base_url}?capteur_id={device_id}&error_type={error_type}'
|
||||
|
||||
# Add additional info if provided
|
||||
if additional_info:
|
||||
# Make sure to URL encode the additional info
|
||||
from urllib.parse import quote
|
||||
alert_url += f'&details={quote(str(additional_info))}'
|
||||
|
||||
# Try to send the notification, catch ALL exceptions
|
||||
try:
|
||||
response = requests.post(alert_url, timeout=3)
|
||||
if response.status_code == 200:
|
||||
print(f"✅ Alert notification sent successfully")
|
||||
return True
|
||||
else:
|
||||
print(f"⚠️ Alert notification failed: Status code {response.status_code}")
|
||||
except Exception as e:
|
||||
print(f"⚠️ Alert notification couldn't be sent: {e}")
|
||||
|
||||
return False
|
||||
|
||||
def modem_complete_reboot_and_reinitialize(modem_version, aircarto_profile_id):
|
||||
"""
|
||||
Performs a complete modem restart sequence:
|
||||
@@ -630,17 +673,9 @@ try:
|
||||
print('🛑STOP LOOP🛑')
|
||||
print("<hr>")
|
||||
|
||||
# Send notification
|
||||
try:
|
||||
alert_url = f'http://data.nebuleair.fr/pro_4G/alert.php?capteur_id={device_id}&error_type=serial_error'
|
||||
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:
|
||||
print(f"Alert notification failed: {e}")
|
||||
|
||||
#Send notification (WIFI)
|
||||
send_error_notification(device_id, "serial_error")
|
||||
|
||||
#end loop
|
||||
sys.exit()
|
||||
|
||||
@@ -714,11 +749,15 @@ try:
|
||||
|
||||
#3. Send to endpoint (with device ID)
|
||||
print("Send data (POST REQUEST):")
|
||||
command= f'AT+UHTTPC={aircarto_profile_id},4,"/pro_4G/data.php?sensor_id={device_id}&lat{device_latitude_raw}=&long={device_longitude_raw}&datetime={influx_timestamp}","aircarto_server_response.txt","sensordata_csv.json",4\r'
|
||||
command= f'AT+UHTTPC={aircarto_profile_id},4,"/pro_4G/data.php?sensor_id={device_id}&lat={device_latitude_raw}&long={device_longitude_raw}&datetime={influx_timestamp}","aircarto_server_response.txt","sensordata_csv.json",4\r'
|
||||
print("sending:")
|
||||
print('<p class="text-danger-emphasis">')
|
||||
print(command)
|
||||
print("</p>", end="")
|
||||
ser_sara.write(command.encode('utf-8'))
|
||||
|
||||
response_SARA_3 = read_complete_response(ser_sara, timeout=5, end_of_response_timeout=120, wait_for_lines=["+UUHTTPCR", "+CME ERROR", "ERROR"], debug=True)
|
||||
|
||||
print("receiving:")
|
||||
print('<p class="text-danger-emphasis">')
|
||||
print(response_SARA_3)
|
||||
print("</p>", end="")
|
||||
@@ -913,7 +952,7 @@ try:
|
||||
|
||||
|
||||
#Si non ne recoit pas de réponse UHTTPCR
|
||||
#on a peut etre une ERROR de type "+CME ERROR: No connection to phone" ou "Operation not allowed"
|
||||
#on a peut etre une ERROR de type "+CME ERROR: No connection to phone" ou "Operation not allowed" ou "ERROR"
|
||||
else:
|
||||
print('<span style="color: red;font-weight: bold;">No UUHTTPCR response</span>')
|
||||
print("Blink red LED")
|
||||
@@ -961,6 +1000,9 @@ try:
|
||||
|
||||
if "ERROR" in line:
|
||||
print("⛔Attention ERROR!⛔")
|
||||
#Send notification (WIFI)
|
||||
send_error_notification(device_id, "sara_error")
|
||||
|
||||
#Software Reboot
|
||||
software_reboot_success = modem_complete_reboot_and_reinitialize(modem_version, aircarto_profile_id)
|
||||
if software_reboot_success:
|
||||
|
||||
Reference in New Issue
Block a user