udpate
This commit is contained in:
@@ -165,7 +165,7 @@ def blink_led(pin, blink_count, delay=1):
|
||||
|
||||
finally:
|
||||
GPIO.output(pin, GPIO.LOW) # Ensure LED is off
|
||||
print(f"LED on GPIO {pin} turned OFF (cleanup avoided)")
|
||||
#print(f"LED on GPIO {pin} turned OFF (cleanup avoided)")
|
||||
|
||||
#get config data from SQLite table
|
||||
def load_config_sqlite():
|
||||
@@ -652,17 +652,17 @@ try:
|
||||
|
||||
'''
|
||||
print('<h3>START LOOP</h3>')
|
||||
print(f'Modem version: {modem_version}')
|
||||
#print(f'Modem version: {modem_version}')
|
||||
|
||||
#Local timestamp
|
||||
#ATTENTION:
|
||||
# -> RTC module can be deconnected ""
|
||||
# -> RTC module can be out of time like "2000-01-01T00:55:21Z"
|
||||
print("➡️Getting local timestamp")
|
||||
cursor.execute("SELECT * FROM timestamp_table LIMIT 1")
|
||||
row = cursor.fetchone() # Get the first (and only) row
|
||||
rtc_time_str = row[1] # '2025-02-07 12:30:45' ou '2000-01-01 00:55:21' ou 'not connected'
|
||||
print(rtc_time_str)
|
||||
print(f"➡️Getting local timestamp: {rtc_time_str}")
|
||||
|
||||
|
||||
if rtc_time_str == 'not connected':
|
||||
print("⛔ Atttention RTC module not connected⛔")
|
||||
@@ -676,14 +676,14 @@ try:
|
||||
print("⛔ Attention: RTC has been reset to default date ⛔")
|
||||
rtc_status = "reset"
|
||||
else:
|
||||
print("✅ RTC timestamp is valid")
|
||||
#print("✅ RTC timestamp is valid")
|
||||
rtc_status = "valid"
|
||||
|
||||
# Always convert to InfluxDB format
|
||||
# Convert to InfluxDB RFC3339 format with UTC 'Z' suffix
|
||||
influx_timestamp = dt_object.strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||
rtc_status = "valid"
|
||||
print(influx_timestamp)
|
||||
#print(influx_timestamp)
|
||||
|
||||
#NEXTPM
|
||||
# We take the last measures (order by rowid and not by timestamp)
|
||||
@@ -826,21 +826,22 @@ try:
|
||||
else:
|
||||
print("No data available in the database.")
|
||||
|
||||
print("Verify SARA R4 connection")
|
||||
#print("Verify SARA connection (AT)")
|
||||
|
||||
# Getting the LTE Signal
|
||||
print("➡️Getting LTE signal")
|
||||
# Getting the LTE Signal (AT+CSQ)
|
||||
print("➡️Getting SARA LTE signal")
|
||||
|
||||
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)
|
||||
print("</p>", end="")
|
||||
|
||||
|
||||
#Here it's possible that the SARA do not repond at all or send a error message
|
||||
#-> TO DO : harware reboot
|
||||
#-> send notification
|
||||
#-> hardware reboot
|
||||
#-> end loop, no need to continue
|
||||
|
||||
#1. No answer at all form SARA
|
||||
@@ -851,6 +852,12 @@ try:
|
||||
|
||||
#Send notification (WIFI)
|
||||
send_error_notification(device_id, "SERIAL ISSUE ->no answer from sara")
|
||||
#Hardware 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()
|
||||
@@ -874,7 +881,7 @@ try:
|
||||
print("<hr>")
|
||||
#Send notification (WIFI)
|
||||
send_error_notification(device_id, "SERIAL ISSUE -> Treck TCP/IP stack error")
|
||||
#Software Reboot
|
||||
#hardware reboot
|
||||
hardware_reboot_success = modem_hardware_reboot()
|
||||
if hardware_reboot_success:
|
||||
print("✅Modem successfully rebooted and reinitialized")
|
||||
@@ -932,7 +939,7 @@ try:
|
||||
print("Open JSON:")
|
||||
command = f'AT+UDWNFILE="sensordata_csv.json",{size_of_string}\r'
|
||||
ser_sara.write(command.encode('utf-8'))
|
||||
response_SARA_1 = read_complete_response(ser_sara, wait_for_lines=[">"], debug=True)
|
||||
response_SARA_1 = read_complete_response(ser_sara, wait_for_lines=[">"], debug=False)
|
||||
print('<p class="text-danger-emphasis">')
|
||||
print(response_SARA_1)
|
||||
print("</p>", end="")
|
||||
@@ -942,10 +949,8 @@ try:
|
||||
#2. Write to shell
|
||||
print("Write data to memory:")
|
||||
ser_sara.write(csv_string.encode())
|
||||
response_SARA_2 = read_complete_response(ser_sara, wait_for_lines=["OK"], debug=True)
|
||||
print('<p class="text-danger-emphasis">')
|
||||
print(response_SARA_2)
|
||||
print("</p>", end="")
|
||||
response_SARA_2 = read_complete_response(ser_sara, wait_for_lines=["OK"], debug=False)
|
||||
print(f'<p class="text-danger-emphasis">{response_SARA_2.strip()}</p>', end="")
|
||||
|
||||
#3. Send to endpoint (with device ID)
|
||||
print("Send data (POST REQUEST):")
|
||||
|
||||
Reference in New Issue
Block a user