update
This commit is contained in:
@@ -40,7 +40,7 @@ CSV PAYLOAD (AirCarto Servers)
|
||||
8 -> min_noise
|
||||
9 -> envea_no2
|
||||
10 -> envea_h2s
|
||||
11 -> envea_o3
|
||||
11 -> envea_nh3
|
||||
12 -> 4G signal quality,
|
||||
13 -> PM 0.2μm to 0.5μm quantity (Nb/L)
|
||||
14 -> PM 0.5μm to 1.0μm quantity (Nb/L)
|
||||
@@ -202,10 +202,13 @@ config_file = '/var/www/nebuleair_pro_4g/config.json'
|
||||
config = load_config(config_file)
|
||||
baudrate = config.get('SaraR4_baudrate', 115200) #baudrate du sara R4
|
||||
device_id = config.get('deviceID', '').upper() #device ID en maj
|
||||
need_to_log = config.get('loop_log', False) #inscription des logs
|
||||
bme_280_config = config.get('BME280/get_data_v2.py', False) #présence du BME280
|
||||
envea_cairsens= config.get('envea/read_value_v2.py', False)
|
||||
send_aircarto = config.get('send_aircarto', True) #envoi sur AirCarto (data.nebuleair.fr)
|
||||
send_uSpot = config.get('send_uSpot', False) #envoi sur MicroSpot ()
|
||||
selected_networkID = config.get('SARA_R4_neworkID', '')
|
||||
npm_5channel = config.get('NPM/get_data_modbus.py', False) #5 canaux du NPM
|
||||
|
||||
modem_config_mode = config.get('modem_config_mode', False) #modem 4G en mode configuration
|
||||
|
||||
#update device id in the payload json
|
||||
@@ -279,8 +282,9 @@ try:
|
||||
|
||||
'''
|
||||
print('<h3>START LOOP</h3>')
|
||||
print("Getting NPM values")
|
||||
# Retrieve the last sensor readings
|
||||
|
||||
#NEXTPM
|
||||
print("➡️Getting NPM values")
|
||||
cursor.execute("SELECT * FROM data_NPM ORDER BY timestamp DESC LIMIT 1")
|
||||
last_row = cursor.fetchone()
|
||||
# Display the result
|
||||
@@ -313,6 +317,74 @@ try:
|
||||
else:
|
||||
print("No data available in the database.")
|
||||
|
||||
#NextPM 5 channels
|
||||
if npm_5channel:
|
||||
print("➡️Getting NextPM 5 channels values")
|
||||
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)
|
||||
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)]
|
||||
|
||||
# Store averages in specific indices
|
||||
payload_csv[13] = averages[0] # Channel 1
|
||||
payload_csv[14] = averages[1] # Channel 2
|
||||
payload_csv[15] = averages[2] # Channel 3
|
||||
payload_csv[16] = averages[3] # Channel 4
|
||||
payload_csv[17] = averages[4] # Channel 5
|
||||
|
||||
#BME280
|
||||
if bme_280_config:
|
||||
print("➡️Getting BME280 values")
|
||||
cursor.execute("SELECT * FROM data_BME280 ORDER BY timestamp DESC LIMIT 1")
|
||||
last_row = cursor.fetchone()
|
||||
if last_row:
|
||||
print("SQLite DB last available row:", last_row)
|
||||
BME280_temperature = last_row[1]
|
||||
BME280_humidity = last_row[2]
|
||||
BME280_pressure = last_row[3]
|
||||
|
||||
#Add data to payload CSV
|
||||
payload_csv[3] = BME280_temperature
|
||||
payload_csv[4] = BME280_humidity
|
||||
payload_csv[5] = BME280_pressure
|
||||
|
||||
#Add data to payload JSON
|
||||
payload_json["sensordatavalues"].append({"value_type": "BME280_temperature", "value": str(BME280_temperature)})
|
||||
payload_json["sensordatavalues"].append({"value_type": "BME280_humidity", "value": str(BME280_humidity)})
|
||||
payload_json["sensordatavalues"].append({"value_type": "BME280_pressure", "value": str(BME280_pressure)})
|
||||
else:
|
||||
print("No data available in the database.")
|
||||
|
||||
#envea
|
||||
if envea_cairsens:
|
||||
print("➡️Getting envea cairsens values")
|
||||
cursor.execute("SELECT * FROM data_envea 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, ignoring 0 values
|
||||
averages = []
|
||||
for col in zip(*data_values): # Iterate column-wise
|
||||
filtered_values = [val for val in col if val != 0] # Remove zeros
|
||||
if filtered_values:
|
||||
avg = round(sum(filtered_values) / len(filtered_values)) # Compute average
|
||||
else:
|
||||
avg = 0 # If all values were zero, store 0
|
||||
averages.append(avg)
|
||||
|
||||
# Store averages in specific indices
|
||||
payload_csv[9] = averages[0] # envea_no2
|
||||
payload_csv[10] = averages[1] # envea_h2s
|
||||
payload_csv[11] = averages[2] # envea_nh3
|
||||
|
||||
#Add data to payload JSON
|
||||
payload_json["sensordatavalues"].append({"value_type": "CAIRSENS_NO2", "value": str(averages[0])})
|
||||
payload_json["sensordatavalues"].append({"value_type": "CAIRSENS_NO2", "value": str(averages[1])})
|
||||
payload_json["sensordatavalues"].append({"value_type": "CAIRSENS_NH3", "value": str(averages[2])})
|
||||
|
||||
|
||||
print("Verify SARA R4 connection")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user