From c038084343a3db07a4f6b33cd530077990fb6111 Mon Sep 17 00:00:00 2001 From: AirLab Date: Mon, 3 Nov 2025 17:20:37 +0100 Subject: [PATCH] update --- loop/SARA_send_data_v2.py | 47 ++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/loop/SARA_send_data_v2.py b/loop/SARA_send_data_v2.py index 9a701e9..cdcc344 100755 --- a/loop/SARA_send_data_v2.py +++ b/loop/SARA_send_data_v2.py @@ -714,7 +714,7 @@ try: |_____\___/ \___/|_| ''' - print('

START LOOP

') + print('

START LOOP

', end="") payload = SensorPayload(device_id) print("deviceID (ASCII):") print(payload.get_bytes()[:8].hex()) @@ -966,7 +966,7 @@ try: ser_sara.write((command + '\r').encode('utf-8')) response2 = read_complete_response(ser_sara, wait_for_lines=["OK", "ERROR", "+CME ERROR","Socket:bind"]) - print('

') + print('

', end="") print(response2) print("

", end="") @@ -1039,23 +1039,22 @@ try: print('⚠️ATTENTION: Signal Quality indicates no signal (99)⚠️') #Pas besoin d'essayer de se reconnecter car reconnection automatique - print("TRY TO RECONNECT:") - command = f'AT+COPS=1,2,{selected_networkID}\r' + #print("TRY TO RECONNECT:") + #command = f'AT+COPS=1,2,{selected_networkID}\r' #command = f'AT+COPS=0\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="") + #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("
") #on arrete le script pas besoin de continuer sys.exit() else: - print("Signal Quality:", signal_quality) - - - + #print("Signal Quality:", signal_quality) + print(f"📶 Signal Quality: {signal_quality} - {'⚫ No signal' if signal_quality == 99 else '🔴 Very poor' if signal_quality == 0 else '🟠 Poor' if signal_quality <= 24 else '🟡 Good' if signal_quality <= 26 else '🟢 Very good' if signal_quality <= 28 else '🔵 Excellent' if signal_quality <= 30 else '🟣 Very Strong'}") ''' ____ _____ _ _ ____ _ _ ____ ____ / ___|| ____| \ | | _ \ | | | | _ \| _ \ @@ -1080,7 +1079,7 @@ try: command = f'AT+USOCR=17\r' ser_sara.write(command.encode('utf-8')) response_SARA_1 = read_complete_response(ser_sara, wait_for_lines=["OK", "+CME ERROR", "ERROR"], debug=False) - print('

') + print('

', end="") print(response_SARA_1) print("

", end="") @@ -1091,13 +1090,16 @@ try: print("✅PSD CSD connection reset successfully") else: print("⛔There were issues with the modem CSD PSD reinitialize process") + # Clignotement LED rouge en cas d'erreur + led_thread = Thread(target=blink_led, args=(24, 5, 0.5)) + led_thread.start() #Retreive Socket ID match = re.search(r'\+USOCR:\s*(\d+)', response_SARA_1) if match: socket_id = match.group(1) - print(f"Socket ID: {socket_id}") + print(f"Socket ID: {socket_id}", end="") else: print("Failed to extract socket ID") @@ -1106,24 +1108,24 @@ try: command = f'AT+USOCO={socket_id},"192.168.0.20",4242\r' ser_sara.write(command.encode('utf-8')) response_SARA_2 = read_complete_response(ser_sara, wait_for_lines=["OK", "+CME ERROR", "ERROR"], debug=False) - print('

') + print('

', end="") print(response_SARA_2) print("

", end="") # Write data and send - print(f"Write data: {len(binary_data)} bytes") + print(f"Write data: {len(binary_data)} bytes", end="") command = f'AT+USOWR={socket_id},{len(binary_data)}\r' ser_sara.write(command.encode('utf-8')) response_SARA_2 = read_complete_response(ser_sara, wait_for_lines=["@","OK", "+CME ERROR", "ERROR"], debug=False) - print('

') + print('

', end="") print(response_SARA_2) print("

", end="") # Send the raw payload bytes (already prepared) ser_sara.write(binary_data) response_SARA_2 = read_complete_response(ser_sara, wait_for_lines=["@","OK", "+CME ERROR", "ERROR"], debug=False) - print('

') + print('

', end="") print(response_SARA_2) print("

", end="") @@ -1141,7 +1143,12 @@ try: command = f'AT+USOCL={socket_id}\r' ser_sara.write(command.encode('utf-8')) response_SARA_2 = read_complete_response(ser_sara, wait_for_lines=["OK", "+CME ERROR", "ERROR"], debug=False) - print('

') + + #blink green LEDs + led_thread = Thread(target=blink_led, args=(23, 5, 0.5)) + led_thread.start() + + print('

', end="") print(response_SARA_2) print("

", end="")