This commit is contained in:
AirLab
2025-11-03 17:20:37 +01:00
parent 6069ab04cf
commit c038084343

View File

@@ -714,7 +714,7 @@ try:
|_____\___/ \___/|_|
'''
print('<h3>START LOOP</h3>')
print('<h3>START LOOP</h3>', 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('<p class="text-danger-emphasis">')
print('<p class="text-danger-emphasis">', end="")
print(response2)
print("</p>", end="")
@@ -1039,23 +1039,22 @@ try:
print('<span style="color: red;font-weight: bold;">⚠ATTENTION: Signal Quality indicates no signal (99)⚠️</span>')
#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('<p class="text-danger-emphasis">')
print(responseReconnect)
print("</p>", 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('<p class="text-danger-emphasis">')
#print(responseReconnect)
#print("</p>", end="")
print('🛑STOP LOOP🛑')
print("<hr>")
#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('<p class="text-danger-emphasis">')
print('<p class="text-danger-emphasis">', end="")
print(response_SARA_1)
print("</p>", 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('<p class="text-danger-emphasis">')
print('<p class="text-danger-emphasis">', end="")
print(response_SARA_2)
print("</p>", 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('<p class="text-danger-emphasis">')
print('<p class="text-danger-emphasis">', end="")
print(response_SARA_2)
print("</p>", 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('<p class="text-danger-emphasis">')
print('<p class="text-danger-emphasis">', end="")
print(response_SARA_2)
print("</p>", 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('<p class="text-danger-emphasis">')
#blink green LEDs
led_thread = Thread(target=blink_led, args=(23, 5, 0.5))
led_thread.start()
print('<p class="text-danger-emphasis">', end="")
print(response_SARA_2)
print("</p>", end="")