feat: intégration capteur CO2 MH-Z19
- Scripts MH-Z19/get_data.py (lecture standalone) et write_data.py (écriture SQLite) - Table data_MHZ19, config MHZ19, cleanup et service systemd (120s) - Web UI : carte test sensors, checkbox admin, boutons database + CSV download - SARA_send_data_v2.py non modifié (sera fait dans un second temps) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -118,6 +118,13 @@
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-check mb-3">
|
||||
<input class="form-check-input" type="checkbox" value="" id="check_mhz19" onchange="update_config_sqlite('MHZ19', this.checked)">
|
||||
<label class="form-check-label" for="check_mhz19">
|
||||
Send CO2 data (MH-Z19)
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-check mb-3">
|
||||
<input class="form-check-input" type="checkbox" value="" id="check_wifi_power_saving" onchange="update_config_sqlite('wifi_power_saving', this.checked)">
|
||||
<label class="form-check-label" for="check_wifi_power_saving">
|
||||
@@ -457,6 +464,7 @@ window.onload = function() {
|
||||
const checkbox_envea = document.getElementById("check_envea");
|
||||
const checkbox_solar = document.getElementById("check_solarBattery");
|
||||
const checkbox_noise = document.getElementById("check_NOISE");
|
||||
const checkbox_mhz19 = document.getElementById("check_mhz19");
|
||||
const checkbox_wifi_power_saving = document.getElementById("check_wifi_power_saving");
|
||||
|
||||
checkbox_bme.checked = response["BME280"];
|
||||
@@ -465,6 +473,7 @@ window.onload = function() {
|
||||
checkbox_nmp5channels.checked = response.npm_5channel;
|
||||
checkbox_wind.checked = response["windMeter"];
|
||||
checkbox_noise.checked = response["NOISE"];
|
||||
checkbox_mhz19.checked = response["MHZ19"];
|
||||
checkbox_wifi_power_saving.checked = response["wifi_power_saving"];
|
||||
|
||||
checkbox_uSpot.checked = response["send_uSpot"];
|
||||
|
||||
@@ -81,6 +81,7 @@
|
||||
<button class="btn btn-primary mb-2" onclick="get_data_sqlite('data_NOISE',getSelectedLimit(),false)" data-i18n="database.noiseProbe">Sonde bruit</button>
|
||||
<button class="btn btn-primary mb-2" onclick="get_data_sqlite('data_WIND',getSelectedLimit(),false)" data-i18n="database.windProbe">Sonde Vent</button>
|
||||
<button class="btn btn-primary mb-2" onclick="get_data_sqlite('data_MPPT',getSelectedLimit(),false)" data-i18n="database.battery">Batterie</button>
|
||||
<button class="btn btn-primary mb-2" onclick="get_data_sqlite('data_MHZ19',getSelectedLimit(),false)">Mesures CO2</button>
|
||||
<button class="btn btn-warning mb-2" onclick="get_data_sqlite('timestamp_table',getSelectedLimit(),false)" data-i18n="database.timestampTable">Timestamp Table</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -104,6 +105,7 @@
|
||||
<button class="btn btn-primary mb-2" onclick="get_data_sqlite('data_envea',10,true, getStartDate(), getEndDate())" data-i18n="database.cairsensProbe">Sonde Cairsens</button>
|
||||
<button class="btn btn-primary mb-2" onclick="get_data_sqlite('data_NOISE',10,true, getStartDate(), getEndDate())" data-i18n="database.noiseProbe">Sonde Bruit</button>
|
||||
<button class="btn btn-primary mb-2" onclick="get_data_sqlite('data_mppt',10,true, getStartDate(), getEndDate())" data-i18n="database.battery">Batterie</button>
|
||||
<button class="btn btn-primary mb-2" onclick="get_data_sqlite('data_MHZ19',10,true, getStartDate(), getEndDate())">Mesures CO2</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -358,7 +360,12 @@ function get_data_sqlite(table, limit, download , startDate = "", endDate = "")
|
||||
<th>Timestamp</th>
|
||||
<th>Curent LEQ</th>
|
||||
<th>DB_A_value</th>
|
||||
|
||||
|
||||
`;
|
||||
}else if (table === "data_MHZ19") {
|
||||
tableHTML += `
|
||||
<th>Timestamp</th>
|
||||
<th>CO2 (ppm)</th>
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -433,7 +440,12 @@ function get_data_sqlite(table, limit, download , startDate = "", endDate = "")
|
||||
<td>${columns[0]}</td>
|
||||
<td>${columns[1]}</td>
|
||||
<td>${columns[2]}</td>
|
||||
|
||||
|
||||
`;
|
||||
}else if (table === "data_MHZ19") {
|
||||
tableHTML += `
|
||||
<td>${columns[0]}</td>
|
||||
<td>${columns[1]}</td>
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -480,6 +492,9 @@ function downloadCSV(response, table) {
|
||||
else if (table === "data_NPM_5channels") {
|
||||
csvContent += "TimestampUTC,PM_ch1,PM_ch2,PM_ch3,PM_ch4,PM_ch5\n";
|
||||
}
|
||||
else if (table === "data_MHZ19") {
|
||||
csvContent += "TimestampUTC,CO2_ppm\n";
|
||||
}
|
||||
|
||||
// Format rows as CSV
|
||||
rows.forEach(row => {
|
||||
|
||||
@@ -542,7 +542,7 @@ if ($type == "db_table_stats") {
|
||||
$fileSizeMB = round($fileSizeBytes / (1024 * 1024), 2);
|
||||
|
||||
// Sensor data tables to inspect
|
||||
$tables = ['data_NPM', 'data_NPM_5channels', 'data_BME280', 'data_envea', 'data_WIND', 'data_MPPT', 'data_NOISE'];
|
||||
$tables = ['data_NPM', 'data_NPM_5channels', 'data_BME280', 'data_envea', 'data_WIND', 'data_MPPT', 'data_NOISE', 'data_MHZ19'];
|
||||
|
||||
$tableStats = [];
|
||||
foreach ($tables as $tableName) {
|
||||
@@ -589,7 +589,7 @@ if ($type == "download_full_table") {
|
||||
$table = $_GET['table'] ?? '';
|
||||
|
||||
// Whitelist of allowed tables
|
||||
$allowedTables = ['data_NPM', 'data_NPM_5channels', 'data_BME280', 'data_envea', 'data_WIND', 'data_MPPT', 'data_NOISE'];
|
||||
$allowedTables = ['data_NPM', 'data_NPM_5channels', 'data_BME280', 'data_envea', 'data_WIND', 'data_MPPT', 'data_NOISE', 'data_MHZ19'];
|
||||
|
||||
if (!in_array($table, $allowedTables)) {
|
||||
header('Content-Type: application/json');
|
||||
@@ -605,7 +605,8 @@ if ($type == "download_full_table") {
|
||||
'data_envea' => 'TimestampUTC,NO2,H2S,NH3,CO,O3,SO2',
|
||||
'data_WIND' => 'TimestampUTC,Wind_speed_kmh,Wind_direction_V',
|
||||
'data_MPPT' => 'TimestampUTC,Battery_voltage,Battery_current,Solar_voltage,Solar_power,Charger_status',
|
||||
'data_NOISE' => 'TimestampUTC,Current_LEQ,DB_A_value'
|
||||
'data_NOISE' => 'TimestampUTC,Current_LEQ,DB_A_value',
|
||||
'data_MHZ19' => 'TimestampUTC,CO2_ppm'
|
||||
];
|
||||
|
||||
try {
|
||||
@@ -741,6 +742,12 @@ if ($type == "BME280") {
|
||||
echo $output;
|
||||
}
|
||||
|
||||
if ($type == "mhz19") {
|
||||
$command = 'sudo /usr/bin/python3 /var/www/nebuleair_pro_4g/MH-Z19/get_data.py ttyAMA4';
|
||||
$output = shell_exec($command);
|
||||
echo $output;
|
||||
}
|
||||
|
||||
|
||||
if ($type == "table_mesure") {
|
||||
$table=$_GET['table'];
|
||||
@@ -1276,6 +1283,10 @@ if ($type == "get_systemd_services") {
|
||||
'description' => 'Get Data from noise sensor',
|
||||
'frequency' => 'Every minute'
|
||||
],
|
||||
'nebuleair-mhz19-data.timer' => [
|
||||
'description' => 'Reads CO2 concentration from MH-Z19 sensor',
|
||||
'frequency' => 'Every 2 minutes'
|
||||
],
|
||||
'nebuleair-db-cleanup-data.timer' => [
|
||||
'description' => 'Cleans up old data from database',
|
||||
'frequency' => 'Daily'
|
||||
@@ -1341,6 +1352,7 @@ if ($type == "restart_systemd_service") {
|
||||
'nebuleair-sara-data.timer',
|
||||
'nebuleair-bme280-data.timer',
|
||||
'nebuleair-mppt-data.timer',
|
||||
'nebuleair-mhz19-data.timer',
|
||||
'nebuleair-db-cleanup-data.timer'
|
||||
];
|
||||
|
||||
@@ -1401,6 +1413,7 @@ if ($type == "toggle_systemd_service") {
|
||||
'nebuleair-sara-data.timer',
|
||||
'nebuleair-bme280-data.timer',
|
||||
'nebuleair-mppt-data.timer',
|
||||
'nebuleair-mhz19-data.timer',
|
||||
'nebuleair-db-cleanup-data.timer'
|
||||
];
|
||||
|
||||
|
||||
@@ -285,6 +285,36 @@ function getNoise_values(){
|
||||
});
|
||||
}
|
||||
|
||||
function getMHZ19_values(){
|
||||
console.log("Data from MH-Z19 CO2 sensor:");
|
||||
$("#loading_mhz19").show();
|
||||
|
||||
$.ajax({
|
||||
url: 'launcher.php?type=mhz19',
|
||||
dataType: 'json',
|
||||
method: 'GET',
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
const tableBody = document.getElementById("data-table-body_mhz19");
|
||||
tableBody.innerHTML = "";
|
||||
$("#loading_mhz19").hide();
|
||||
|
||||
if (response.CO2 !== undefined) {
|
||||
$("#data-table-body_mhz19").append(`
|
||||
<tr>
|
||||
<td>CO2</td>
|
||||
<td>${response.CO2} ppm</td>
|
||||
</tr>
|
||||
`);
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
$("#loading_mhz19").hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getBME280_values(){
|
||||
console.log("Data from I2C BME280:");
|
||||
$("#loading_BME280").show();
|
||||
@@ -462,6 +492,29 @@ error: function(xhr, status, error) {
|
||||
container.innerHTML += i2C_HTML; // Add the I2C card if condition is met
|
||||
}
|
||||
|
||||
//creates MH-Z19 CO2 card
|
||||
if (config.MHZ19) {
|
||||
const MHZ19_HTML = `
|
||||
<div class="col-sm-3">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Port UART 4
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">MH-Z19 CO2</h5>
|
||||
<p class="card-text">Capteur de dioxyde de carbone.</p>
|
||||
<button class="btn btn-primary mb-1" onclick="getMHZ19_values()" data-i18n="common.getData">Get Data</button>
|
||||
<div id="loading_mhz19" class="spinner-border spinner-border-sm" style="display: none;" role="status"></div>
|
||||
<table class="table table-striped-columns">
|
||||
<tbody id="data-table-body_mhz19"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
container.innerHTML += MHZ19_HTML;
|
||||
}
|
||||
|
||||
//Si on a des SONDES ENVEA connectée il faut faire un deuxième call dans la table envea_sondes_table
|
||||
//creates ENVEA debug card
|
||||
if (config.envea) {
|
||||
|
||||
Reference in New Issue
Block a user