update
This commit is contained in:
@@ -370,6 +370,45 @@ def send_error_notification(device_id, error_type, additional_info=None):
|
||||
|
||||
return False
|
||||
|
||||
def modem_hardware_reboot():
|
||||
"""
|
||||
Performs a hardware reboot using transistors connected to pin 16 and 20:
|
||||
pin 16 set to SARA GND
|
||||
pin 20 set to SARA ON (not used)
|
||||
|
||||
LOW -> cut the current
|
||||
HIGH -> current flow
|
||||
|
||||
"""
|
||||
print('<span style="color: orange;font-weight: bold;">🔄 Hardware SARA reboot 🔄</span>')
|
||||
|
||||
SARA_power_GPIO = 16
|
||||
SARA_ON_GPIO = 20
|
||||
|
||||
GPIO.setmode(GPIO.BCM) # Use BCM numbering
|
||||
GPIO.setup(SARA_power_GPIO, GPIO.OUT) # Set GPIO17 as an output
|
||||
|
||||
GPIO.output(SARA_power_GPIO, GPIO.LOW)
|
||||
time.sleep(2)
|
||||
GPIO.output(SARA_power_GPIO, GPIO.HIGH)
|
||||
time.sleep(2)
|
||||
|
||||
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.")
|
||||
return True
|
||||
print(f"⏳ Waiting for modem... attempt {attempt + 1}")
|
||||
time.sleep(2)
|
||||
else:
|
||||
print("❌ Modem not responding after reboot.")
|
||||
return False
|
||||
|
||||
|
||||
|
||||
def modem_complete_reboot_and_reinitialize(modem_version, aircarto_profile_id):
|
||||
"""
|
||||
Performs a complete modem restart sequence:
|
||||
@@ -433,15 +472,22 @@ def modem_complete_reboot_and_reinitialize(modem_version, aircarto_profile_id):
|
||||
|
||||
# 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.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="")
|
||||
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 = responseResetHTTP is not None and "OK" in responseResetHTTP
|
||||
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
|
||||
@@ -784,7 +830,8 @@ try:
|
||||
|
||||
# Getting the LTE Signal
|
||||
print("➡️Getting LTE signal")
|
||||
ser_sara.write(b'AT+CSQ\r')
|
||||
command = f'AT+CSQ\r'
|
||||
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(response2)
|
||||
@@ -827,6 +874,12 @@ try:
|
||||
print("<hr>")
|
||||
#Send notification (WIFI)
|
||||
send_error_notification(device_id, "SERIAL ISSUE -> Treck TCP/IP stack error")
|
||||
#Software Reboot
|
||||
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")
|
||||
#end loop
|
||||
sys.exit()
|
||||
|
||||
@@ -1031,8 +1084,9 @@ try:
|
||||
led_thread.start()
|
||||
|
||||
#4. Read reply from server
|
||||
print("Reply from server:")
|
||||
ser_sara.write(b'AT+URDFILE="aircarto_server_response.txt"\r')
|
||||
print("Reply from server:")
|
||||
command = f'AT+URDFILE="aircarto_server_response.txt""\r'
|
||||
ser_sara.write((command + '\r').encode('utf-8'))
|
||||
response_SARA_4 = read_complete_response(ser_sara, wait_for_lines=["OK"], debug=False)
|
||||
print('<p class="text-success">')
|
||||
print(response_SARA_4)
|
||||
@@ -1169,7 +1223,8 @@ try:
|
||||
|
||||
#5. empty json
|
||||
print("Empty SARA memory:")
|
||||
ser_sara.write(b'AT+UDELFILE="sensordata_csv.json"\r')
|
||||
command = f'AT+UDELFILE="sensordata_csv.json"\r'
|
||||
ser_sara.write((command + '\r').encode('utf-8'))
|
||||
response_SARA_5 = read_complete_response(ser_sara, wait_for_lines=["OK","+CME ERROR"], debug=True)
|
||||
print('<p class="text-danger-emphasis">')
|
||||
print(response_SARA_5)
|
||||
@@ -1309,8 +1364,9 @@ try:
|
||||
led_thread.start()
|
||||
|
||||
#4. Read reply from server
|
||||
print("Reply from server:")
|
||||
ser_sara.write(b'AT+URDFILE="uSpot_server_response.txt"\r')
|
||||
print("Reply from server:")
|
||||
command = f'AT+URDFILE="uSpot_server_response.txt"\r'
|
||||
ser_sara.write((command + '\r').encode('utf-8'))
|
||||
response_SARA_4b = read_complete_response(ser_sara, wait_for_lines=["OK"], debug=False)
|
||||
print('<p class="text-success">')
|
||||
print(response_SARA_4b)
|
||||
@@ -1349,7 +1405,8 @@ try:
|
||||
|
||||
#5. empty json
|
||||
print("Empty SARA memory:")
|
||||
ser_sara.write(b'AT+UDELFILE="sensordata_json.json"\r')
|
||||
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)
|
||||
print(response_SARA_9t)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user