From 10c4348e5496735ad9a4f003a1d8908be0f29f38 Mon Sep 17 00:00:00 2001
From: Your Name ')
print(response2)
- print("START LOOP
')
#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'
- # Convert to a datetime object
- dt_object = datetime.strptime(rtc_time_str, '%Y-%m-%d %H:%M:%S')
- # Convert to InfluxDB RFC3339 format with UTC 'Z' suffix
- influx_timestamp = dt_object.strftime('%Y-%m-%dT%H:%M:%SZ')
- print(influx_timestamp)
+ 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)
+ if rtc_time_str == 'not connected':
+ print("⛔ Atttention RTC module not connected⛔")
+ rtc_status = "disconnected"
+ influx_timestamp="rtc_disconnected"
+ else :
+ # Convert to a datetime object
+ dt_object = datetime.strptime(rtc_time_str, '%Y-%m-%d %H:%M:%S')
+ # Check if timestamp is reset (year 2000)
+ if dt_object.year == 2000:
+ print("⛔ Attention: RTC has been reset to default date ⛔")
+ rtc_status = "reset"
+ else:
+ 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)
#NEXTPM
+ # We take the last measures (order by rowid and not by timestamp)
print("➡️Getting NPM values (last 6 measures)")
#cursor.execute("SELECT * FROM data_NPM ORDER BY timestamp DESC LIMIT 1")
- cursor.execute("SELECT * FROM data_NPM ORDER BY timestamp DESC LIMIT 6")
+ #cursor.execute("SELECT * FROM data_NPM ORDER BY timestamp DESC LIMIT 6")
+ cursor.execute("SELECT rowid, * FROM data_NPM ORDER BY rowid DESC LIMIT 6")
+
rows = cursor.fetchall()
# Exclude the timestamp column (assuming first column is timestamp)
- data_values = [row[1:] for row in rows] # Exclude timestamp
+ data_values = [row[2:] for row in rows] # Exclude timestamp
# Compute column-wise average
num_columns = len(data_values[0])
averages = [round(sum(col) / len(col),1) for col in zip(*data_values)]
@@ -407,7 +429,7 @@ try:
response2 = read_complete_response(ser_sara, wait_for_lines=["OK"])
print('
') print(responseReconnect) - print("
") + print("", end="") print('🛑STOP LOOP🛑') print("') print(response_SARA_3) - print("
") + print("", end="") # si on recoit la réponse UHTTPCR if "+UUHTTPCR" in response_SARA_3: @@ -547,7 +569,7 @@ try: response_SARA_9 = read_complete_response(ser_sara, wait_for_lines=["OK"], debug=False) print('') print(response_SARA_9) - print("
") + print("", end="") ''' +UHTTPER: profile_id,error_class,error_code @@ -580,7 +602,7 @@ try: responseResetHTTP2_profile = read_complete_response(ser_sara, timeout=5, end_of_response_timeout=5, wait_for_lines=["OK", "+CME ERROR"], debug=True) print('') print(responseResetHTTP2_profile) - print("
") + print("", end="") # 2.2 code 1 (HHTP succeded) @@ -597,7 +619,75 @@ try: response_SARA_4 = read_complete_response(ser_sara, wait_for_lines=["OK"], debug=False) print('') print(response_SARA_4) - print('
') + print("", end="") + + #Parse the server datetime + # Extract just the date from the response + date_string = None + date_start = response_SARA_4.find("Date: ") + if date_start != -1: + date_end = response_SARA_4.find("\n", date_start) + date_string = response_SARA_4[date_start + 6:date_end].strip() + print(f'Parsed datetime: {server_datetime}
') + except Exception as e: + print(f'Error parsing date: {e}
') + + # Get RTC time from SQLite + cursor.execute("SELECT * FROM timestamp_table LIMIT 1") + row = cursor.fetchone() + rtc_time_str = row[1] # '2025-02-07 12:30:45' or '2000-01-01 00:55:21' or 'not connected' + print(f'Error comparing times: {e}
') + #Si non ne recoit pas de réponse UHTTPCR #on a peut etre une ERROR de type "+CME ERROR: No connection to phone" ou "Operation not allowed" @@ -629,7 +719,7 @@ try: responseReconnect = read_complete_response(ser_sara, timeout=5, end_of_response_timeout=120, wait_for_lines=["OK", "+CME ERROR"], debug=True) print('') print(responseReconnect) - print("
") + print("", end="") # Handle "Operation not allowed" error if error_message == "Operation not allowed": print('❓Try Resetting the HTTP Profile❓') @@ -638,7 +728,7 @@ try: responseResetHTTP_profile = read_complete_response(ser_sara, timeout=5, end_of_response_timeout=5, wait_for_lines=["OK", "+CME ERROR"], debug=True) print('') print(responseResetHTTP_profile) - print("
") + print("", end="") check_lines = responseResetHTTP_profile.strip().splitlines() for line in check_lines: if "+CME ERROR: Operation not allowed" in line: @@ -687,7 +777,7 @@ try: print('') print(response_SARA_8) - print("
") + print("", end="") # si on recoit la réponse UHTTPCR if "+UUHTTPCR" in response_SARA_8: @@ -740,7 +830,7 @@ try: response_SARA_9b = read_complete_response(ser_sara, wait_for_lines=["OK"], debug=False) print('') print(response_SARA_9b) - print("
") + print("", end="") ''' +UHTTPER: profile_id,error_class,error_code @@ -773,7 +863,7 @@ try: response_SARA_4b = read_complete_response(ser_sara, wait_for_lines=["OK"], debug=False) print('') print(response_SARA_4b) - print('
') + print("", end="")