update
This commit is contained in:
@@ -304,6 +304,49 @@ def extract_error_code(response):
|
|||||||
# Return None if we couldn't find the error code
|
# Return None if we couldn't find the error code
|
||||||
return None
|
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):
|
def modem_complete_reboot_and_reinitialize(modem_version, aircarto_profile_id):
|
||||||
"""
|
"""
|
||||||
Performs a complete modem restart sequence:
|
Performs a complete modem restart sequence:
|
||||||
@@ -611,16 +654,8 @@ try:
|
|||||||
print('🛑STOP LOOP🛑')
|
print('🛑STOP LOOP🛑')
|
||||||
print("<hr>")
|
print("<hr>")
|
||||||
|
|
||||||
# Send notification
|
#Send notification (WIFI)
|
||||||
try:
|
send_error_notification(device_id, "serial_error")
|
||||||
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}")
|
|
||||||
|
|
||||||
#end loop
|
#end loop
|
||||||
sys.exit()
|
sys.exit()
|
||||||
@@ -695,11 +730,15 @@ try:
|
|||||||
|
|
||||||
#3. Send to endpoint (with device ID)
|
#3. Send to endpoint (with device ID)
|
||||||
print("Send data (POST REQUEST):")
|
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'))
|
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)
|
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('<p class="text-danger-emphasis">')
|
||||||
print(response_SARA_3)
|
print(response_SARA_3)
|
||||||
print("</p>", end="")
|
print("</p>", end="")
|
||||||
@@ -898,7 +937,7 @@ try:
|
|||||||
|
|
||||||
|
|
||||||
#Si non ne recoit pas de réponse UHTTPCR
|
#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:
|
else:
|
||||||
print('<span style="color: red;font-weight: bold;">No UUHTTPCR response</span>')
|
print('<span style="color: red;font-weight: bold;">No UUHTTPCR response</span>')
|
||||||
print("Blink red LED")
|
print("Blink red LED")
|
||||||
@@ -946,6 +985,9 @@ try:
|
|||||||
|
|
||||||
if "ERROR" in line:
|
if "ERROR" in line:
|
||||||
print("⛔Attention ERROR!⛔")
|
print("⛔Attention ERROR!⛔")
|
||||||
|
#Send notification (WIFI)
|
||||||
|
send_error_notification(device_id, "sara_error")
|
||||||
|
|
||||||
#Software Reboot
|
#Software Reboot
|
||||||
software_reboot_success = modem_complete_reboot_and_reinitialize(modem_version, aircarto_profile_id)
|
software_reboot_success = modem_complete_reboot_and_reinitialize(modem_version, aircarto_profile_id)
|
||||||
if software_reboot_success:
|
if software_reboot_success:
|
||||||
|
|||||||
Reference in New Issue
Block a user