update
This commit is contained in:
@@ -266,6 +266,9 @@ def read_complete_response(serial_connection, timeout=2, end_of_response_timeout
|
|||||||
'''
|
'''
|
||||||
Fonction très importante !!!
|
Fonction très importante !!!
|
||||||
Reads the complete response from a serial connection and waits for specific lines.
|
Reads the complete response from a serial connection and waits for specific lines.
|
||||||
|
timeout -> temps d'attente de la réponse de la première ligne (assez rapide car le SARA répond direct avec la commande recue)
|
||||||
|
end_of_response_timeout -> le temps d'inactivité entre deux lignes imprimées (plus long dans certain cas: le SARA mouline avant de finir vraiment)
|
||||||
|
wait_for_lines -> si on rencontre la string la fonction s'arrete
|
||||||
'''
|
'''
|
||||||
if wait_for_lines is None:
|
if wait_for_lines is None:
|
||||||
wait_for_lines = [] # Default to an empty list if not provided
|
wait_for_lines = [] # Default to an empty list if not provided
|
||||||
@@ -385,7 +388,7 @@ def modem_complete_reboot_and_reinitialize(modem_version, aircarto_profile_id):
|
|||||||
print('<span style="color: orange;font-weight: bold;">🔄 Complete SARA reboot and reinitialize sequence 🔄</span>')
|
print('<span style="color: orange;font-weight: bold;">🔄 Complete SARA reboot and reinitialize sequence 🔄</span>')
|
||||||
|
|
||||||
# Step 1: Reboot the modem - Integrated modem_software_reboot logic
|
# Step 1: Reboot the modem - Integrated modem_software_reboot logic
|
||||||
print('<span style="color: orange;font-weight: bold;">🔄 Software SARA reboot! 🔄</span>')
|
print('<span style="color: orange;font-weight: bold;">🔄 Software SARA reboot (CFUN)! 🔄</span>')
|
||||||
|
|
||||||
# Use different commands based on modem version
|
# Use different commands based on modem version
|
||||||
if 'R5' in modem_version: # For SARA-R5 series
|
if 'R5' in modem_version: # For SARA-R5 series
|
||||||
@@ -393,6 +396,8 @@ def modem_complete_reboot_and_reinitialize(modem_version, aircarto_profile_id):
|
|||||||
else: # For SARA-R4 series
|
else: # For SARA-R4 series
|
||||||
command = 'AT+CFUN=15\r' # Factory reset for R4
|
command = 'AT+CFUN=15\r' # Factory reset for R4
|
||||||
|
|
||||||
|
#ATTENTION : AT+CFUN=16 sometimes causes the modem to reset before replying OK
|
||||||
|
|
||||||
ser_sara.write(command.encode('utf-8'))
|
ser_sara.write(command.encode('utf-8'))
|
||||||
response = read_complete_response(ser_sara, wait_for_lines=["OK", "ERROR"], debug=True)
|
response = read_complete_response(ser_sara, wait_for_lines=["OK", "ERROR"], debug=True)
|
||||||
|
|
||||||
@@ -401,25 +406,31 @@ def modem_complete_reboot_and_reinitialize(modem_version, aircarto_profile_id):
|
|||||||
print("</p>", end="")
|
print("</p>", end="")
|
||||||
|
|
||||||
# Check if reboot command was acknowledged
|
# Check if reboot command was acknowledged
|
||||||
reboot_success = response is not None and "OK" in response
|
if response is None or ("OK" not in response and "ERROR" in response):
|
||||||
if not reboot_success:
|
print("⚠️ Reboot command may have failed or modem restarted before responding.")
|
||||||
print("⚠️ Modem reboot command failed")
|
# Still continue, as the modem may have rebooted correctly
|
||||||
return False
|
else:
|
||||||
|
print("✅ Modem acknowledged reboot command.")
|
||||||
|
|
||||||
# Step 2: Wait for the modem to restart (adjust time as needed)
|
# Step 2: Wait for the modem to restart (adjust time as needed)
|
||||||
print("Waiting for modem to restart...")
|
print("Waiting for modem to restart...")
|
||||||
time.sleep(15) # 15 seconds should be enough for most modems to restart
|
time.sleep(7) # 7 seconds should be enough for most modems to restart
|
||||||
|
|
||||||
# Step 3: Check if modem is responsive after reboot
|
# Step 3: Check if modem is responsive after reboot
|
||||||
print("Checking if modem is responsive...")
|
print("Checking if modem is responsive...")
|
||||||
|
|
||||||
|
for attempt in range(5):
|
||||||
ser_sara.write(b'AT\r')
|
ser_sara.write(b'AT\r')
|
||||||
response_check = read_complete_response(ser_sara, wait_for_lines=["OK"], debug=True)
|
response_check = read_complete_response(ser_sara, wait_for_lines=["OK"], debug=True)
|
||||||
if response_check is None or "OK" not in response_check:
|
if response_check and "OK" in response_check:
|
||||||
print("⚠️ Modem not responding after reboot")
|
print("✅ Modem is responsive after reboot.")
|
||||||
|
break
|
||||||
|
print(f"⏳ Waiting for modem... attempt {attempt + 1}")
|
||||||
|
time.sleep(2)
|
||||||
|
else:
|
||||||
|
print("❌ Modem not responding after reboot.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
print("✅ Modem restarted successfully")
|
|
||||||
|
|
||||||
# Step 4: Reset AirCarto HTTP Profile
|
# Step 4: Reset AirCarto HTTP Profile
|
||||||
print('<span style="color: orange;font-weight: bold;">🔧 Resetting AirCarto HTTP Profile</span>')
|
print('<span style="color: orange;font-weight: bold;">🔧 Resetting AirCarto HTTP Profile</span>')
|
||||||
command = f'AT+UHTTP={aircarto_profile_id},1,"data.nebuleair.fr"\r'
|
command = f'AT+UHTTP={aircarto_profile_id},1,"data.nebuleair.fr"\r'
|
||||||
@@ -792,7 +803,7 @@ try:
|
|||||||
print("<hr>")
|
print("<hr>")
|
||||||
|
|
||||||
#Send notification (WIFI)
|
#Send notification (WIFI)
|
||||||
send_error_notification(device_id, "serial_error(no answer from sara)")
|
send_error_notification(device_id, "SERIAL ISSUE ->no answer from sara")
|
||||||
|
|
||||||
#end loop
|
#end loop
|
||||||
sys.exit()
|
sys.exit()
|
||||||
@@ -815,7 +826,7 @@ try:
|
|||||||
print('🛑STOP LOOP🛑')
|
print('🛑STOP LOOP🛑')
|
||||||
print("<hr>")
|
print("<hr>")
|
||||||
#Send notification (WIFI)
|
#Send notification (WIFI)
|
||||||
send_error_notification(device_id, "Treck TCP/IP stack error")
|
send_error_notification(device_id, "SERIAL ISSUE -> Treck TCP/IP stack error")
|
||||||
#end loop
|
#end loop
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
@@ -989,6 +1000,13 @@ try:
|
|||||||
print('<p class="text-danger">Error 11: Server connection error</p>')
|
print('<p class="text-danger">Error 11: Server connection error</p>')
|
||||||
elif error_code == 22:
|
elif error_code == 22:
|
||||||
print('<p class="text-danger">⚠️Error 22: PSD or CSD connection not established (SARA-R5 need to reset PDP conection)⚠️</p>')
|
print('<p class="text-danger">⚠️Error 22: PSD or CSD connection not established (SARA-R5 need to reset PDP conection)⚠️</p>')
|
||||||
|
send_error_notification(device_id, "UHTTPER (error n°22) -> PSD or CSD connection not established")
|
||||||
|
elif error_code == 26:
|
||||||
|
print('<p class="text-danger">Error 26: Connection timed out</p>')
|
||||||
|
send_error_notification(device_id, "UHTTPER (error n°26) -> Connection timed out")
|
||||||
|
elif error_code == 44:
|
||||||
|
print('<p class="text-danger">Error 44: Connection lost</p>')
|
||||||
|
send_error_notification(device_id, "UHTTPER (error n°44) -> Connection lost")
|
||||||
elif error_code == 73:
|
elif error_code == 73:
|
||||||
print('<p class="text-danger">Error 73: Secure socket connect error</p>')
|
print('<p class="text-danger">Error 73: Secure socket connect error</p>')
|
||||||
else:
|
else:
|
||||||
@@ -1090,7 +1108,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" ou "ERROR"
|
#on a peut être 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")
|
||||||
@@ -1139,7 +1157,7 @@ try:
|
|||||||
if "ERROR" in line:
|
if "ERROR" in line:
|
||||||
print("⛔Attention ERROR!⛔")
|
print("⛔Attention ERROR!⛔")
|
||||||
#Send notification (WIFI)
|
#Send notification (WIFI)
|
||||||
send_error_notification(device_id, "sara_error")
|
send_error_notification(device_id, "SARA CME 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)
|
||||||
@@ -1261,20 +1279,24 @@ try:
|
|||||||
print('<p class="text-success">No error detected</p>')
|
print('<p class="text-success">No error detected</p>')
|
||||||
elif error_code == 4:
|
elif error_code == 4:
|
||||||
print('<p class="text-danger">Error 4: Invalid server Hostname</p>', end="")
|
print('<p class="text-danger">Error 4: Invalid server Hostname</p>', end="")
|
||||||
send_error_notification(device_id, "uSpot - Invalid server Hostname")
|
send_error_notification(device_id, "UHTTPER (4) uSpot Invalid server Hostname")
|
||||||
elif error_code == 11:
|
elif error_code == 11:
|
||||||
print('<p class="text-danger">Error 11: Server connection error</p>', end="")
|
print('<p class="text-danger">Error 11: Server connection error</p>', end="")
|
||||||
elif error_code == 22:
|
elif error_code == 22:
|
||||||
print('<p class="text-danger">Error 22: PSD or CSD connection not established</p>', end="")
|
print('<p class="text-danger">Error 22: PSD or CSD connection not established</p>', end="")
|
||||||
|
elif error_code == 26:
|
||||||
|
print('<p class="text-danger">Error 26: Connection timed out</p>')
|
||||||
|
elif error_code == 44:
|
||||||
|
print('<p class="text-danger">Error 44: Connection lost</p>')
|
||||||
elif error_code == 73:
|
elif error_code == 73:
|
||||||
print('<p class="text-danger">Error 73: Secure socket connect error</p>', end="")
|
print('<p class="text-danger">Error 73: Secure socket connect error</p>', end="")
|
||||||
send_error_notification(device_id, "uSpot - Secure socket connect error")
|
send_error_notification(device_id, "uSpot - Secure socket connect error")
|
||||||
#Software Reboot ??
|
#Software Reboot ??
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print(f'<p class="text-danger">Unknown error code: {error_code}</p>')
|
print(f'<p class="text-danger">Unknown error code: {error_code}</p>',end="")
|
||||||
else:
|
else:
|
||||||
print('<p class="text-danger">Could not extract error code from response</p>')
|
print('<p class="text-danger">Could not extract error code from response</p>', end="")
|
||||||
|
|
||||||
#Pas forcément un moyen de résoudre le soucis
|
#Pas forcément un moyen de résoudre le soucis
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user