update
This commit is contained in:
@@ -283,43 +283,50 @@ try:
|
||||
'''
|
||||
print('<h3>START LOOP</h3>')
|
||||
|
||||
#Local timestamp
|
||||
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)
|
||||
|
||||
#NEXTPM
|
||||
print("➡️Getting NPM values")
|
||||
cursor.execute("SELECT * FROM data_NPM ORDER BY timestamp DESC LIMIT 1")
|
||||
last_row = cursor.fetchone()
|
||||
# Display the result
|
||||
if last_row:
|
||||
print("SQLite DB last available row:", last_row)
|
||||
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")
|
||||
rows = cursor.fetchall()
|
||||
# Exclude the timestamp column (assuming first column is timestamp)
|
||||
data_values = [row[1:] for row in rows] # Exclude timestamp
|
||||
# Compute column-wise average
|
||||
num_columns = len(data_values[0])
|
||||
averages = [round(sum(col) / len(col)) for col in zip(*data_values)]
|
||||
|
||||
datetime_measure_PM = last_row[0] #on récupère le datetime de la table data_NPM
|
||||
# Convert to a datetime object
|
||||
dt_object = datetime.strptime(datetime_measure_PM, '%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')
|
||||
PM1 = averages[0]
|
||||
PM25 = averages[1]
|
||||
PM10 = averages[2]
|
||||
npm_temp = averages[3]
|
||||
npm_hum = averages[4]
|
||||
|
||||
PM1 = last_row[1]
|
||||
PM25 = last_row[2]
|
||||
PM10 = last_row[3]
|
||||
npm_temp = last_row[4]
|
||||
npm_hum = last_row[5]
|
||||
#Add data to payload CSV
|
||||
payload_csv[0] = PM1
|
||||
payload_csv[1] = PM25
|
||||
payload_csv[2] = PM10
|
||||
payload_csv[18] = npm_temp
|
||||
payload_csv[19] = npm_hum
|
||||
|
||||
#Add data to payload CSV
|
||||
payload_csv[0] = PM1
|
||||
payload_csv[1] = PM25
|
||||
payload_csv[2] = PM10
|
||||
payload_csv[18] = npm_temp
|
||||
payload_csv[19] = npm_hum
|
||||
|
||||
#Add data to payload JSON
|
||||
payload_json["sensordatavalues"].append({"value_type": "NPM_P0", "value": str(PM1)})
|
||||
payload_json["sensordatavalues"].append({"value_type": "NPM_P1", "value": str(PM10)})
|
||||
payload_json["sensordatavalues"].append({"value_type": "NPM_P2", "value": str(PM25)})
|
||||
else:
|
||||
print("No data available in the database.")
|
||||
#Add data to payload JSON
|
||||
payload_json["sensordatavalues"].append({"value_type": "NPM_P0", "value": str(PM1)})
|
||||
payload_json["sensordatavalues"].append({"value_type": "NPM_P1", "value": str(PM10)})
|
||||
payload_json["sensordatavalues"].append({"value_type": "NPM_P2", "value": str(PM25)})
|
||||
|
||||
|
||||
#NextPM 5 channels
|
||||
if npm_5channel:
|
||||
print("➡️Getting NextPM 5 channels values")
|
||||
print("➡️Getting NextPM 5 channels values (last 6 measures)")
|
||||
cursor.execute("SELECT * FROM data_NPM_5channels ORDER BY timestamp DESC LIMIT 6")
|
||||
rows = cursor.fetchall()
|
||||
# Exclude the timestamp column (assuming first column is timestamp)
|
||||
|
||||
Reference in New Issue
Block a user