v1.5.2: page capteurs NPM via get_data_modbus_v3.py --dry-run
- NPM: mode --dry-run (print JSON sans ecriture en base) - launcher.php: endpoint npm appelle get_data_modbus_v3.py --dry-run - sensors.html: affichage PM + temp + humidite + status NPM decode - Suppression unite ug/m3 sur le champ status Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -40,6 +40,9 @@ import crcmod
|
||||
import sqlite3
|
||||
import time
|
||||
|
||||
# Dry-run mode: print JSON output without writing to database
|
||||
dry_run = "--dry-run" in sys.argv
|
||||
|
||||
# Connect to the SQLite database
|
||||
conn = sqlite3.connect("/var/www/nebuleair_pro_4g/sqlite/sensors.db")
|
||||
cursor = conn.cursor()
|
||||
@@ -207,15 +210,29 @@ except Exception as e:
|
||||
# Variables already set to -1 at the beginning
|
||||
|
||||
finally:
|
||||
# Always save data to database, even if all values are -1
|
||||
cursor.execute('''
|
||||
INSERT INTO data_NPM_5channels (timestamp,PM_ch1, PM_ch2, PM_ch3, PM_ch4, PM_ch5) VALUES (?,?,?,?,?,?)'''
|
||||
, (rtc_time_str, channel_1, channel_2, channel_3, channel_4, channel_5))
|
||||
if dry_run:
|
||||
# Print JSON output without writing to database
|
||||
result = {
|
||||
"PM1": pm1_10s,
|
||||
"PM25": pm25_10s,
|
||||
"PM10": pm10_10s,
|
||||
"temperature": temperature,
|
||||
"humidity": relative_humidity,
|
||||
"npm_status": npm_status,
|
||||
"npm_status_hex": f"0x{npm_status:02X}"
|
||||
}
|
||||
print(json.dumps(result))
|
||||
else:
|
||||
# Always save data to database, even if all values are 0
|
||||
cursor.execute('''
|
||||
INSERT INTO data_NPM_5channels (timestamp,PM_ch1, PM_ch2, PM_ch3, PM_ch4, PM_ch5) VALUES (?,?,?,?,?,?)'''
|
||||
, (rtc_time_str, channel_1, channel_2, channel_3, channel_4, channel_5))
|
||||
|
||||
cursor.execute('''
|
||||
INSERT INTO data_NPM (timestamp,PM1, PM25, PM10, temp_npm, hum_npm, npm_status) VALUES (?,?,?,?,?,?,?)'''
|
||||
, (rtc_time_str, pm1_10s, pm25_10s, pm10_10s, temperature, relative_humidity, npm_status))
|
||||
cursor.execute('''
|
||||
INSERT INTO data_NPM (timestamp,PM1, PM25, PM10, temp_npm, hum_npm, npm_status) VALUES (?,?,?,?,?,?,?)'''
|
||||
, (rtc_time_str, pm1_10s, pm25_10s, pm10_10s, temperature, relative_humidity, npm_status))
|
||||
|
||||
# Commit and close the connection
|
||||
conn.commit()
|
||||
|
||||
# Commit and close the connection
|
||||
conn.commit()
|
||||
conn.close()
|
||||
Reference in New Issue
Block a user