update
This commit is contained in:
@@ -177,6 +177,12 @@ if ($type == "npm") {
|
||||
echo $output;
|
||||
}
|
||||
|
||||
if ($type == "mhz19") {
|
||||
$command = '/usr/bin/python3 /var/www/moduleair_pro_4g/MH-Z19/get_data.py ttyAMA4';
|
||||
$output = shell_exec($command);
|
||||
echo $output;
|
||||
}
|
||||
|
||||
if ($type == "envea") {
|
||||
$port=$_GET['port'];
|
||||
$name=$_GET['name'];
|
||||
|
||||
@@ -214,6 +214,47 @@ function getNoise_values(){
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function getco2_values() {
|
||||
console.log("Data from UART 4:");
|
||||
$("#loading_co2").show();
|
||||
|
||||
$.ajax({
|
||||
url: 'launcher.php?type=mhz19',
|
||||
dataType: 'JSON',
|
||||
method: 'GET',
|
||||
success: function(data) { // No need to parse JSON manually
|
||||
console.log(data); // Debugging: Check if data is received correctly
|
||||
|
||||
const tableBody = document.getElementById("data-table-body_co2");
|
||||
tableBody.innerHTML = ""; // Clear previous data
|
||||
$("#loading_co2").hide();
|
||||
|
||||
// Ensure "CO2" exists in the response
|
||||
if (data.hasOwnProperty("CO2")) {
|
||||
const value = data["CO2"];
|
||||
const unit = "ppm"; // CO2 is always in ppm
|
||||
|
||||
// Append the data row to the table
|
||||
$("#data-table-body_co2").append(`
|
||||
<tr>
|
||||
<td>CO2</td>
|
||||
<td>${value} ${unit}</td>
|
||||
</tr>
|
||||
`);
|
||||
} else {
|
||||
console.error("CO2 data not found in response:", data);
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
$("#loading_co2").hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
function getBME280_values(){
|
||||
console.log("Data from I2C BME280:");
|
||||
$("#loading_BME280").show();
|
||||
@@ -318,32 +359,7 @@ window.onload = function() {
|
||||
container.innerHTML += cardHTML; // Ajouter la carte au conteneur
|
||||
});
|
||||
|
||||
//creates ENVEA cards
|
||||
const ENVEA_sensors = data.envea_sondes.filter(sonde => sonde.connected); // Filter only connected sondes
|
||||
|
||||
ENVEA_sensors.forEach((sensor, index) => {
|
||||
const port = sensor.port; // Port from the sensor object
|
||||
const name = sensor.name; // Port from the sensor object
|
||||
const coefficient = sensor.coefficient;
|
||||
const cardHTML = `
|
||||
<div class="col-sm-3">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Port UART ${port.replace('ttyAMA', '')}
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Sonde Envea ${name}</h5>
|
||||
<p class="card-text">Capteur gas.</p>
|
||||
<button class="btn btn-primary" onclick="getENVEA_values('${port}','${name}','${coefficient}')">Get Data</button>
|
||||
<div id="loading_envea${name}" class="spinner-border spinner-border-sm" style="display: none;" role="status"></div>
|
||||
<table class="table table-striped-columns">
|
||||
<tbody id="data-table-body_envea${name}"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
container.innerHTML += cardHTML; // Ajouter la carte au conteneur
|
||||
});
|
||||
|
||||
//creates i2c BME280 card
|
||||
if (data.i2c_BME) {
|
||||
@@ -395,6 +411,30 @@ window.onload = function() {
|
||||
container.innerHTML += i2C_HTML; // Add the I2C card if condition is met
|
||||
}
|
||||
|
||||
//creates CO2 card
|
||||
if (data.CO2_serial) {
|
||||
const MH_Z19 = `
|
||||
<div class="col-sm-3">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Port UART 4
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">CO2 Sensor</h5>
|
||||
<p class="card-text">Capteur de Dioxyde de carbone</p>
|
||||
<button class="btn btn-primary mb-1" onclick="getco2_values()">Get Data</button>
|
||||
<br>
|
||||
<div id="loading_co2" class="spinner-border spinner-border-sm" style="display: none;" role="status"></div>
|
||||
<table class="table table-striped-columns">
|
||||
<tbody id="data-table-body_co2"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
container.innerHTML += MH_Z19; // Add the I2C card if condition is met
|
||||
}
|
||||
|
||||
})
|
||||
.catch(error => console.error('Error loading config.json:', error));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user