+ # type-> 0 -> trusted root CA
+ command = f'AT+USECMNG=0,0,"{certificate_name}",{size_of_string}\r'
+ ser_sara.write((command + '\r').encode('utf-8'))
+ response_SARA_1 = read_complete_response(ser_sara, wait_for_lines=[">"])
+ print(response_SARA_1)
+
+ time.sleep(0.5)
+
+ print("➡️ add certificate")
+ ser_sara.write(certificate)
+ response_SARA_2 = read_complete_response(ser_sara, wait_for_lines=["OK"])
+ print(response_SARA_2)
+
+ time.sleep(0.5)
+
+ # op_code: 0 -> certificate validation level
+ # param_val : 0 -> Level 0 No validation; 1-> Level 1 Root certificate validation
+ print("➡️Set the security profile (params)")
+ certification_level=0
+ command = f'AT+USECPRF={security_profile_id},0,{certification_level}\r'
+ ser_sara.write((command + '\r').encode('utf-8'))
+ response_SARA_5b = read_complete_response(ser_sara, wait_for_lines=["OK"])
+ print(response_SARA_5b)
+ time.sleep(0.5)
+
+ # op_code: 1 -> minimum SSL/TLS version
+ # param_val : 0 -> any; server can use any version for the connection; 1-> LSv1.0; 2->TLSv1.1; 3->TLSv1.2;
+ print("➡️Set the security profile (params)")
+ minimum_SSL_version = 0
+ command = f'AT+USECPRF={security_profile_id},1,{minimum_SSL_version}\r'
+ ser_sara.write((command + '\r').encode('utf-8'))
+ response_SARA_5bb = read_complete_response(ser_sara, wait_for_lines=["OK"])
+ print(response_SARA_5bb)
+ time.sleep(0.5)
+
+ #op_code: 2 -> legacy cipher suite selection
+ # 0 (factory-programmed value): a list of default cipher suites is proposed at the beginning of handshake process, and a cipher suite will be negotiated among the cipher suites proposed in the list.
+ print("➡️Set cipher")
+ cipher_suite = 0
+ command = f'AT+USECPRF={security_profile_id},2,{cipher_suite}\r'
+ ser_sara.write((command + '\r').encode('utf-8'))
+ response_SARA_5cc = read_complete_response(ser_sara, wait_for_lines=["OK"])
+ print(response_SARA_5cc)
+ time.sleep(0.5)
+
+ # op_code: 3 -> trusted root certificate internal name
+ print("➡️Set the security profile (choose cert)")
+ command = f'AT+USECPRF={security_profile_id},3,"{certificate_name}"\r'
+ ser_sara.write((command + '\r').encode('utf-8'))
+ response_SARA_5c = read_complete_response(ser_sara, wait_for_lines=["OK"])
+ print(response_SARA_5c)
+ time.sleep(0.5)
+
+ # op_code: 10 -> SNI (server name indication)
+ print("➡️Set the SNI")
+ command = f'AT+USECPRF={security_profile_id},10,"{uSpot_url}"\r'
+ ser_sara.write((command + '\r').encode('utf-8'))
+ response_SARA_5cf = read_complete_response(ser_sara, wait_for_lines=["OK"])
+ print(response_SARA_5cf)
+ time.sleep(0.5)
+
+ #step 4: set url (op_code = 1)
+ print("➡️SET URL")
+ command = f'AT+UHTTP={profile_id},1,"{uSpot_url}"\r'
+ ser_sara.write((command + '\r').encode('utf-8'))
+ response_SARA_5 = read_complete_response(ser_sara, wait_for_lines=["OK"])
+ print(response_SARA_5)
+ time.sleep(1)
+
+ #step 4: set PORT (op_code = 5)
+ print("➡️SET PORT")
+ port = 443
+ command = f'AT+UHTTP={profile_id},5,{port}\r'
+ ser_sara.write((command + '\r').encode('utf-8'))
+ response_SARA_55 = read_complete_response(ser_sara, wait_for_lines=["OK"])
+ print(response_SARA_55)
+ time.sleep(1)
+
+ #step 4: set url to SSL (op_code = 6) (http_secure = 1 for HTTPS)(USECMNG_PROFILE = 2)
+ print("➡️SET SSL")
+ http_secure = 1
+ command = f'AT+UHTTP={profile_id},6,{http_secure},{security_profile_id}\r'
+
+ ser_sara.write(command.encode('utf-8'))
+ response_SARA_5fg = read_complete_response(ser_sara, wait_for_lines=["OK"])
+ print(response_SARA_5fg)
+ time.sleep(1)
+
+ http_reset_success = response_SARA_5 is not None and "OK" in response_SARA_5
+ if not http_reset_success:
+ print("⚠️ AirCarto HTTP profile reset failed")
+ #Pour uSpot
+ elif profile_id ==1:
+ pass #on utilise la fonction reset_server_hostname_https pour uSpot
else:
print(f"❌ Unsupported profile ID: {profile_id}")
http_reset_success = False
@@ -1381,9 +1504,16 @@ try:
# Display interpretation based on error code
if error_code == 0:
print('No error detected
')
+ # INVALID SERVER HOSTNAME
elif error_code == 4:
print('Error 4: Invalid server Hostname
', end="")
send_error_notification(device_id, "UHTTPER (4) uSpot Invalid server Hostname")
+ server_hostname_resets = reset_server_hostname_https(uSpot_profile_id)
+ if server_hostname_resets:
+ print("✅server hostname reset successfully")
+ else:
+ 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="")
elif error_code == 22:
@@ -1444,7 +1574,14 @@ try:
print(f"HTTP response code: {http_response_code}")
if http_response_code == 201:
print('✅✅HTTP 201 ressource created.')
-
+ elif http_response_code == 308:
+ print(' ⚠️⚠️HTTP 308 Redirect, need to set up HTTPS.')
+ server_hostname_resets = reset_server_hostname_https(uSpot_profile_id)
+ if server_hostname_resets:
+ print("✅server hostname reset successfully")
+ else:
+ print("⛔There were issues with the modem server hostname reinitialize process")
+
except Exception as e:
# If any error occurs during parsing, keep the default value
print(f"Error parsing HTTP code: {e}")