diff --git a/loop/SARA_send_data_v2.py b/loop/SARA_send_data_v2.py index ce3c67b..df2209f 100755 --- a/loop/SARA_send_data_v2.py +++ b/loop/SARA_send_data_v2.py @@ -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('🔄 Complete SARA reboot and reinitialize sequence 🔄') - + # Step 1: Reboot the modem - Integrated modem_software_reboot logic - print('🔄 Software SARA reboot! 🔄') + print('🔄 Software SARA reboot (CFUN)! 🔄') # 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("

", 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('🔧 Resetting AirCarto HTTP Profile') command = f'AT+UHTTP={aircarto_profile_id},1,"data.nebuleair.fr"\r' @@ -792,7 +803,7 @@ try: print("
") #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("
") #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('

Error 11: Server connection error

') elif error_code == 22: print('

⚠️Error 22: PSD or CSD connection not established (SARA-R5 need to reset PDP conection)⚠️

') + send_error_notification(device_id, "UHTTPER (error n°22) -> PSD or CSD connection not established") + elif error_code == 26: + print('

Error 26: Connection timed out

') + send_error_notification(device_id, "UHTTPER (error n°26) -> Connection timed out") + elif error_code == 44: + print('

Error 44: Connection lost

') + send_error_notification(device_id, "UHTTPER (error n°44) -> Connection lost") elif error_code == 73: print('

Error 73: Secure socket connect error

') 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('No UUHTTPCR response') 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('

No error detected

') elif error_code == 4: print('

Error 4: Invalid server Hostname

', 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('

Error 11: Server connection error

', end="") elif error_code == 22: print('

Error 22: PSD or CSD connection not established

', end="") + elif error_code == 26: + print('

Error 26: Connection timed out

') + elif error_code == 44: + print('

Error 44: Connection lost

') elif error_code == 73: print('

Error 73: Secure socket connect error

', end="") send_error_notification(device_id, "uSpot - Secure socket connect error") #Software Reboot ?? else: - print(f'

Unknown error code: {error_code}

') + print(f'

Unknown error code: {error_code}

',end="") else: - print('

Could not extract error code from response

') + print('

Could not extract error code from response

', end="") #Pas forcément un moyen de résoudre le soucis