v1.6.1: NSRT MK4 deconnexion — noise_status en base + ERR_NOISE dans error_flags
Meme modele que NPM: ecriture en base avec valeurs a 0 et noise_status=0xFF si capteur deconnecte, flag ERR_NOISE (bit 5) dans byte 66 UDP, messages explicites sur page capteurs et self-test. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -28,7 +28,31 @@ write_fs(frequency: int) -> sampling freq
|
||||
import nsrt_mk3_dev
|
||||
import sqlite3
|
||||
|
||||
nsrt = nsrt_mk3_dev.NsrtMk3Dev('/dev/ttyACM0')
|
||||
# noise_status: 0x00 = OK, 0xFF = disconnected
|
||||
noise_status = 0x00
|
||||
leq_level_rounded = 0
|
||||
weighted_level_rounded = 0
|
||||
|
||||
try:
|
||||
nsrt = nsrt_mk3_dev.NsrtMk3Dev('/dev/ttyACM0')
|
||||
|
||||
freq_level = nsrt.read_fs() #current sampling frequency
|
||||
time_constant = nsrt.read_tau() #reads the current time constant
|
||||
leq_level = nsrt.read_leq() #current running LEQ and starts the integration of a new LEQ.
|
||||
weighting = nsrt.read_weighting() #weighting curve that is currently selected ( A ou C)
|
||||
weighted_level = nsrt.read_level() #current running level in dB.
|
||||
|
||||
leq_level_rounded = round(leq_level, 2)
|
||||
weighted_level_rounded = round(weighted_level, 2)
|
||||
|
||||
except Exception as e:
|
||||
err_msg = str(e)
|
||||
if "No such file or directory" in err_msg or "could not open port" in err_msg:
|
||||
print(f"NSRT MK4 disconnected: {err_msg}")
|
||||
noise_status = 0xFF
|
||||
else:
|
||||
print(f"NSRT MK4 error: {err_msg}")
|
||||
noise_status = 0xFF
|
||||
|
||||
# Connect to the SQLite database
|
||||
conn = sqlite3.connect("/var/www/nebuleair_pro_4g/sqlite/sensors.db")
|
||||
@@ -39,34 +63,15 @@ 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'
|
||||
|
||||
freq_level = nsrt.read_fs() #current sampling frequency
|
||||
time_constant = nsrt.read_tau() #reads the current time constant
|
||||
leq_level = nsrt.read_leq() #current running LEQ and starts the integration of a new LEQ.
|
||||
weighting = nsrt.read_weighting() #weighting curve that is currently selected ( A ou C)
|
||||
weighted_level = nsrt.read_level() #current running level in dB.
|
||||
|
||||
#print(f'current sampling freq : {freq_level} Hz')
|
||||
#print(f'current time constant : {time_constant} s')
|
||||
#print(f'current LEQ level: {leq_level:0.2f} dB')
|
||||
#print(f'{weighting} value: {weighted_level:0.2f} dBA')
|
||||
# Round values to 2 decimal places before saving
|
||||
leq_level_rounded = round(leq_level, 2)
|
||||
weighted_level_rounded = round(weighted_level, 2)
|
||||
|
||||
#save to db
|
||||
#save to sqlite database
|
||||
try:
|
||||
cursor.execute('''
|
||||
INSERT INTO data_NOISE (timestamp,current_LEQ, DB_A_value) VALUES (?,?,?)'''
|
||||
, (rtc_time_str,leq_level_rounded,weighted_level_rounded))
|
||||
INSERT INTO data_NOISE (timestamp, current_LEQ, DB_A_value, noise_status) VALUES (?,?,?,?)'''
|
||||
, (rtc_time_str, leq_level_rounded, weighted_level_rounded, noise_status))
|
||||
|
||||
# Commit and close the connection
|
||||
conn.commit()
|
||||
|
||||
#print("Sensor data saved successfully!")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Database error: {e}")
|
||||
|
||||
print(f"Database error: {e}")
|
||||
|
||||
conn.close()
|
||||
Reference in New Issue
Block a user