diff --git a/html/launcher.php b/html/launcher.php index 2a67916..52c603d 100755 --- a/html/launcher.php +++ b/html/launcher.php @@ -569,6 +569,12 @@ if ($type == "envea") { echo $output; } +if ($type == "envea_debug") { + $command = 'sudo /usr/bin/python3 /var/www/nebuleair_pro_4g/envea/read_value_v2.py -d 2>&1'; + $output = shell_exec($command); + echo $output; +} + if ($type == "noise") { $command = '/var/www/nebuleair_pro_4g/sound_meter/sound_meter'; $output = shell_exec($command); diff --git a/html/sensors.html b/html/sensors.html index 3a6b716..241a013 100755 --- a/html/sensors.html +++ b/html/sensors.html @@ -190,6 +190,37 @@ function getENVEA_values(port, name){ }); } +function getENVEA_debug_values(){ + console.log("Getting debug data from all Envea sensors"); + $("#loading_envea_debug").show(); + + $.ajax({ + url: 'launcher.php?type=envea_debug', + dataType: 'text', + method: 'GET', + success: function(response) { + console.log("Envea debug output:", response); + const outputDiv = document.getElementById("envea-debug-output"); + $("#loading_envea_debug").hide(); + + // Display raw output in a pre block + outputDiv.innerHTML = `
${response}
`; + }, + error: function(xhr, status, error) { + console.error('AJAX request failed:', status, error); + const outputDiv = document.getElementById("envea-debug-output"); + $("#loading_envea_debug").hide(); + + outputDiv.innerHTML = ` +
+ ❌ Error: unable to get debug data from sensors.
+ ${status}: ${error} +
+ `; + } + }); +} + function getNoise_values(){ console.log("Data from I2C Noise Sensor:"); @@ -385,55 +416,49 @@ error: function(xhr, status, error) { } //Si on a des SONDES ENVEA connectée il faut faire un deuxième call dans la table envea_sondes_table - //creates ENVEA cards + //creates ENVEA debug card if (config.envea) { console.log("Need to display ENVEA sondes"); //getting config_scripts table $.ajax({ url: 'launcher.php?type=get_envea_sondes_table_sqlite', dataType:'json', - //dataType: 'json', // Specify that you expect a JSON response - method: 'GET', // Use GET or POST depending on your needs + method: 'GET', success: function(sondes) { console.log("Getting SQLite envea sondes table:"); console.log(sondes); const ENVEA_sensors = 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; + // Only create the card if there are connected sensors + if (ENVEA_sensors.length > 0) { + // Create a single debug card for all Envea sensors const cardHTML = ` -
+
- Port UART ${port.replace('ttyAMA', '')} + Sondes Envea (Debug)
-
Sonde Envea ${name}
-

Capteur gas.

- - - - -
+
Sonde Envea
+

Capteur gaz.

+

Sondes connectées: ${ENVEA_sensors.map(s => s.name).join(', ')}

+ + +
`; - container.innerHTML += cardHTML; // Ajouter la carte au conteneur - }); + container.innerHTML += cardHTML; + } - // Apply translations to dynamically created Envea cards + // Apply translations to dynamically created Envea card i18n.applyTranslations(); - - - - }, - error: function(xhr, status, error) { - console.error('AJAX request failed:', status, error); - } - });//end AJAX envea Sondes + }, + error: function(xhr, status, error) { + console.error('AJAX request failed:', status, error); + } + });//end AJAX envea Sondes }//end if envea