From bc71a271ebd2af488ecba7620cabb925923dd290 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 3 Jul 2025 09:54:32 +0100 Subject: [PATCH] update --- loop/SARA_send_data_v2.py | 53 +++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/loop/SARA_send_data_v2.py b/loop/SARA_send_data_v2.py index 879e900..ed7915e 100755 --- a/loop/SARA_send_data_v2.py +++ b/loop/SARA_send_data_v2.py @@ -646,7 +646,7 @@ try: |_____\___/ \___/|_| ''' - print('

START LOOP

') + print('

START LOOP

', end="") # Check system uptime with open('/proc/uptime', 'r') as f: @@ -854,19 +854,19 @@ try: time.sleep(0.1) # On vérifie si le signal n'est pas à 99 pour déconnexion - # si c'est le cas on essaie de se reconnecter if signal_quality == 99: update_config_sqlite('SARA_network_status', 'disconnected') update_config_sqlite('SARA_signal_quality', '99') print('⚠️ATTENTION: Signal Quality indicates no signal (99)⚠️') - print("TRY TO RECONNECT:") - command = f'AT+COPS=1,2,"{selected_networkID}"\r' - ser_sara.write(command.encode('utf-8')) - responseReconnect = read_complete_response(ser_sara, timeout=20, end_of_response_timeout=20, wait_for_lines=["OK", "+CME ERROR", "ERROR"], debug=True) - print('

') - print(responseReconnect) - print("

", end="") + + #print("TRY TO RECONNECT:") + #command = f'AT+COPS=1,2,"{selected_networkID}"\r' + #ser_sara.write(command.encode('utf-8')) + #responseReconnect = read_complete_response(ser_sara, timeout=20, end_of_response_timeout=20, wait_for_lines=["OK", "+CME ERROR", "ERROR"], debug=True) + #print('

') + #print(responseReconnect) + #print("

", end="") print('🛑STOP LOOP🛑') print("
") @@ -938,7 +938,7 @@ try: # 1.Vérifier si la réponse contient un message d'erreur CME if "+CME ERROR" in lines[-1]: print("*****") - print('ATTENTION: CME ERROR') + print('⛔ATTENTION: CME ERROR') print("error:", lines[-1]) print("*****") @@ -973,13 +973,13 @@ try: # 2.1 code 0 (HTTP failed) ⛔⛔⛔ if len(parts) == 3 and parts[-1] == '0': # The third value indicates success print("*****") - print('ATTENTION: HTTP operation failed') + print('⛔ATTENTION: HTTP operation failed') print("*****") update_config_sqlite('SARA_network_status', 'error') # Get error code - print("Getting error code") + print("Getting error code", end="") command = f'AT+UHTTPER={aircarto_profile_id}\r' ser_sara.write(command.encode('utf-8')) response_SARA_9 = read_complete_response(ser_sara, wait_for_lines=["OK","ERROR"], debug=False) @@ -994,30 +994,40 @@ try: # Display interpretation based on error code if error_code == 0: print('

No error detected

', end="") + # N°4 INVALID SERVER HOSTNAME elif error_code == 4: print('

Error 4: Invalid server Hostname

', end="") - send_error_notification(device_id, "UHTTPER (error n°4) -> Invalid Server Hostname", end="") + send_error_notification(device_id, "UHTTPER (error n°4) -> Invalid Server Hostname") server_hostname_resets = reset_server_hostname(aircarto_profile_id) if server_hostname_resets: print("✅server hostname reset successfully", end="") else: print("⛔There were issues with the modem server hostname reinitialize process") + # N°11 SERVER CONNECTION ERROR elif error_code == 11: - print('

Error 11: Server connection error

') + print('

Error 11: AirCarto - Server connection error

', end="") + hardware_reboot_success = modem_hardware_reboot() + if hardware_reboot_success: + print("✅Modem successfully rebooted and reinitialized") + else: + print("⛔There were issues with the modem reboot/reinitialize process") + # N°22 PSD CSD CONNECTION NOT ESTABLISHED elif error_code == 22: - print('

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

') + print('

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

', end="") send_error_notification(device_id, "UHTTPER (error n°22) -> PSD or CSD connection not established") psd_csd_resets = reset_PSD_CSD_connection() if psd_csd_resets: print("✅PSD CSD connection reset successfully", end="") else: print("⛔There were issues with the modem CSD PSD reinitialize process", end="") + # N°26 CONNECTION TIMED OUT elif error_code == 26: print('

Error 26: Connection timed out

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

Error 44: Connection lost

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

Error 73: Secure socket connect error

', end="") else: @@ -1173,7 +1183,7 @@ try: #5. empty json - print("Empty SARA memory:") + print("Empty SARA memory:", end="") ser_sara.write(b'AT+UDELFILE="sensordata_csv.json"\r') response_SARA_5 = read_complete_response(ser_sara, wait_for_lines=["OK"], debug=False) print('

') @@ -1282,7 +1292,7 @@ try: print("⛔There were issues with the modem server hostname reinitialize process") # SERVER CONNECTION ERROR elif error_code == 11: - print('

Error 11: Server connection error

', end="") + print('

Error 11: uSpot - Server connection error

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

Error 22: PSD or CSD connection not established

', end="") elif error_code == 26: @@ -1354,7 +1364,7 @@ try: #5. empty json - print("Empty SARA memory:") + print("Empty SARA memory:", end="") command = f'AT+UDELFILE="sensordata_json.json"\r' ser_sara.write((command + '\r').encode('utf-8')) response_SARA_9t = read_complete_response(ser_sara, wait_for_lines=["OK"], debug=False) @@ -1366,7 +1376,8 @@ try: # Calculate and print the elapsed time elapsed_time = time.time() - start_time_script print(f"Elapsed time: {elapsed_time:.2f} seconds") - print("
") + print("
", end="") + print("
", end="") except Exception as e: print("An error occurred:", e)