update
This commit is contained in:
@@ -577,195 +577,6 @@ def reset_server_hostname_https(profile_id):
|
|||||||
http_reset_success = False
|
http_reset_success = False
|
||||||
return http_reset_success
|
return http_reset_success
|
||||||
|
|
||||||
def modem_complete_reboot_and_reinitialize(modem_version, aircarto_profile_id):
|
|
||||||
"""
|
|
||||||
Performs a complete modem restart sequence:
|
|
||||||
1. Reboots the modem using the appropriate command for its version
|
|
||||||
2. Waits for the modem to restart
|
|
||||||
3. Resets the HTTP profile
|
|
||||||
4. For SARA-R5, resets the PDP connection
|
|
||||||
|
|
||||||
Args:
|
|
||||||
modem_version (str): The modem version, e.g., 'SARA-R500' or 'SARA-R410'
|
|
||||||
aircarto_profile_id (int): The HTTP profile ID to reset
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
bool: True if the complete sequence was successful, False otherwise
|
|
||||||
"""
|
|
||||||
print('<span style="color: orange;font-weight: bold;">🔄 Complete SARA reboot and reinitialize sequence 🔄</span>')
|
|
||||||
|
|
||||||
# Step 1: Reboot the modem - Integrated modem_software_reboot logic
|
|
||||||
print('<span style="color: orange;font-weight: bold;">🔄 Software SARA reboot (CFUN)! 🔄</span>')
|
|
||||||
|
|
||||||
# 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)
|
|
||||||
|
|
||||||
print('<p class="text-danger-emphasis">')
|
|
||||||
print(response)
|
|
||||||
print("</p>", end="")
|
|
||||||
|
|
||||||
# Check if reboot command was acknowledged
|
|
||||||
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(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...")
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
# Step 4: Reset AirCarto HTTP Profile
|
|
||||||
print('<span style="color: orange;font-weight: bold;">🔧 Resetting AirCarto HTTP Profile</span>')
|
|
||||||
#command = f'AT+UHTTP={aircarto_profile_id},1,"data.nebuleair.fr"\r'
|
|
||||||
#ser_sara.write(command.encode('utf-8'))
|
|
||||||
#responseResetHTTP = read_complete_response(ser_sara, timeout=5, end_of_response_timeout=5,wait_for_lines=["OK", "+CME ERROR"], debug=True)
|
|
||||||
#print('<p class="text-danger-emphasis">')
|
|
||||||
#print(responseResetHTTP)
|
|
||||||
#print("</p>", end="")
|
|
||||||
|
|
||||||
print("➡️SET URL")
|
|
||||||
command = f'AT+UHTTP={aircarto_profile_id},1,"data.nebuleair.fr"\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)
|
|
||||||
|
|
||||||
|
|
||||||
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")
|
|
||||||
# Continue anyway, don't return False here
|
|
||||||
|
|
||||||
if send_uSpot:
|
|
||||||
print('<span style="color: orange;font-weight: bold;">🔧 Resetting uSpot HTTP Profile</span>')
|
|
||||||
uSpot_profile_id = 1
|
|
||||||
uSpot_url="api-prod.uspot.probesys.net"
|
|
||||||
security_profile_id = 1
|
|
||||||
|
|
||||||
#step 1: import the certificate
|
|
||||||
print("➡️ import certificate")
|
|
||||||
certificate_name = "e6"
|
|
||||||
with open("/var/www/nebuleair_pro_4g/SARA/SSL/certificate/e6.pem", "rb") as cert_file:
|
|
||||||
certificate = cert_file.read()
|
|
||||||
size_of_string = len(certificate)
|
|
||||||
|
|
||||||
# AT+USECMNG=0,<type>,<internal_name>,<data_size>
|
|
||||||
# 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={uSpot_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={uSpot_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={uSpot_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)
|
|
||||||
|
|
||||||
# Return overall success
|
|
||||||
#return http_reset_success and pdp_reset_success
|
|
||||||
return http_reset_success
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
'''
|
'''
|
||||||
@@ -1234,13 +1045,6 @@ try:
|
|||||||
print('<p class="text-danger">Could not extract error code from response</p>')
|
print('<p class="text-danger">Could not extract error code from response</p>')
|
||||||
|
|
||||||
|
|
||||||
#Software Reboot
|
|
||||||
#software_reboot_success = modem_complete_reboot_and_reinitialize(modem_version, aircarto_profile_id)
|
|
||||||
#if software_reboot_success:
|
|
||||||
# print("✅Modem successfully rebooted and reinitialized")
|
|
||||||
#else:
|
|
||||||
# print("⛔There were issues with the modem reboot/reinitialize process")
|
|
||||||
|
|
||||||
|
|
||||||
# 2.2 code 1 (✅✅HHTP / UUHTTPCR succeded✅✅)
|
# 2.2 code 1 (✅✅HHTP / UUHTTPCR succeded✅✅)
|
||||||
else:
|
else:
|
||||||
@@ -1379,12 +1183,6 @@ try:
|
|||||||
#Send notification (WIFI)
|
#Send notification (WIFI)
|
||||||
send_error_notification(device_id, "SARA CME ERROR")
|
send_error_notification(device_id, "SARA CME ERROR")
|
||||||
|
|
||||||
#Software Reboot
|
|
||||||
#software_reboot_success = modem_complete_reboot_and_reinitialize(modem_version, aircarto_profile_id)
|
|
||||||
#if software_reboot_success:
|
|
||||||
# print("Modem successfully rebooted and reinitialized")
|
|
||||||
#else:
|
|
||||||
# print("There were issues with the modem reboot/reinitialize process")
|
|
||||||
#Hardware Reboot
|
#Hardware Reboot
|
||||||
hardware_reboot_success = modem_hardware_reboot()
|
hardware_reboot_success = modem_hardware_reboot()
|
||||||
if hardware_reboot_success:
|
if hardware_reboot_success:
|
||||||
|
|||||||
Reference in New Issue
Block a user