diff --git a/html/launcher.php b/html/launcher.php index e862de0..d77cbd2 100755 --- a/html/launcher.php +++ b/html/launcher.php @@ -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']; diff --git a/html/sensors.html b/html/sensors.html index 695e263..eadfeec 100755 --- a/html/sensors.html +++ b/html/sensors.html @@ -213,7 +213,48 @@ 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(` + + CO2 + ${value} ${unit} + + `); + } 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 = ` -
-
-
- Port UART ${port.replace('ttyAMA', '')} -
-
-
Sonde Envea ${name}
-

Capteur gas.

- - - - -
-
-
-
`; - 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 = ` +
+
+
+ Port UART 4 +
+
+
CO2 Sensor
+

Capteur de Dioxyde de carbone

+ +
+ + + +
+
+
+
`; + + container.innerHTML += MH_Z19; // Add the I2C card if condition is met + } + }) .catch(error => console.error('Error loading config.json:', error)); }