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 !!!
|
||||
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:
|
||||
wait_for_lines = [] # Default to an empty list if not provided
|
||||
@@ -383,15 +386,17 @@ def modem_complete_reboot_and_reinitialize(modem_version, aircarto_profile_id):
|
||||
bool: True if the complete sequence was successful, False otherwise
|
||||
"""
|
||||
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
|
||||
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
|
||||
if 'R5' in modem_version: # For SARA-R5 series
|
||||
command = 'AT+CFUN=16\r' # Normal restart for R5
|
||||
else: # For SARA-R4 series
|
||||
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'))
|
||||
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="")
|
||||
|
||||
# Check if reboot command was acknowledged
|
||||
reboot_success = response is not None and "OK" in response
|
||||
if not reboot_success:
|
||||
print("⚠️ Modem reboot command failed")
|
||||
return False
|
||||
if response is None or ("OK" not in response and "ERROR" in response):
|
||||
print("⚠️ Reboot command may have failed or modem restarted before responding.")
|
||||
# Still continue, as the modem may have rebooted correctly
|
||||
else:
|
||||
print("✅ Modem acknowledged reboot command.")
|
||||
|
||||
# Step 2: Wait for the modem to restart (adjust time as needed)
|
||||
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
|
||||
print("Checking if modem is responsive...")
|
||||
ser_sara.write(b'AT\r')
|
||||
response_check = read_complete_response(ser_sara, wait_for_lines=["OK"], debug=True)
|
||||
if response_check is None or "OK" not in response_check:
|
||||
print("⚠️ Modem not responding after reboot")
|
||||
|
||||
for attempt in range(5):
|
||||
ser_sara.write(b'AT\r')
|
||||
response_check = read_complete_response(ser_sara, wait_for_lines=["OK"], debug=True)
|
||||
if response_check and "OK" in response_check:
|
||||
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
|
||||
|
||||
print("✅ Modem restarted successfully")
|
||||
|
||||
# Step 4: Reset AirCarto HTTP Profile
|
||||
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'
|
||||
@@ -792,7 +803,7 @@ try:
|
||||
print("<hr>")
|
||||
|
||||
#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
|
||||
sys.exit()
|
||||
@@ -815,7 +826,7 @@ try:
|
||||
print('🛑STOP LOOP🛑')
|
||||
print("<hr>")
|
||||
#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
|
||||
sys.exit()
|
||||
|
||||
@@ -989,6 +1000,13 @@ try:
|
||||
print('<p class="text-danger">Error 11: Server connection error</p>')
|
||||
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>')
|
||||
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:
|
||||
print('<p class="text-danger">Error 73: Secure socket connect error</p>')
|
||||
else:
|
||||
@@ -1090,7 +1108,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" ou "ERROR"
|
||||
#on a peut être 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")
|
||||
@@ -1139,7 +1157,7 @@ try:
|
||||
if "ERROR" in line:
|
||||
print("⛔Attention ERROR!⛔")
|
||||
#Send notification (WIFI)
|
||||
send_error_notification(device_id, "sara_error")
|
||||
send_error_notification(device_id, "SARA CME ERROR")
|
||||
|
||||
#Software Reboot
|
||||
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>')
|
||||
elif error_code == 4:
|
||||
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:
|
||||
print('<p class="text-danger">Error 11: Server connection error</p>', end="")
|
||||
elif error_code == 22:
|
||||
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:
|
||||
print('<p class="text-danger">Error 73: Secure socket connect error</p>', end="")
|
||||
send_error_notification(device_id, "uSpot - Secure socket connect error")
|
||||
#Software Reboot ??
|
||||
|
||||
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:
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user