diff --git a/html/sensors.html b/html/sensors.html index b2ff69b..7ccd120 100755 --- a/html/sensors.html +++ b/html/sensors.html @@ -273,6 +273,8 @@ function getBME280_values(){ window.onload = function() { //NEW way to get config (SQLite) + let mainConfig = {}; // Store main config for use in sensor card creation + $.ajax({ url: 'launcher.php?type=get_config_sqlite', dataType:'json', @@ -282,33 +284,32 @@ $.ajax({ console.log("Getting SQLite config table:"); console.log(response); - + mainConfig = response; // Store for later use + //device name_side bar const elements = document.querySelectorAll('.sideBar_sensorName'); elements.forEach((element) => { element.innerText = response.deviceName; }); + // After getting main config, create sensor cards + createSensorCards(mainConfig); + }, error: function(xhr, status, error) { console.error('AJAX request failed:', status, error); } });//end AJAX - //getting config_scripts table - $.ajax({ - url: 'launcher.php?type=get_config_scripts_sqlite', - dataType:'json', - //dataType: 'json', // Specify that you expect a JSON response - method: 'GET', // Use GET or POST depending on your needs - success: function(response) { - console.log("Getting SQLite config scripts table:"); - console.log(response); + //Function to create sensor cards based on config + function createSensorCards(config) { + console.log("Creating sensor cards with config:"); + console.log(config); const container = document.getElementById('card-container'); // Conteneur des cartes //creates NPM card (by default) - + const cardHTML = `
@@ -327,12 +328,12 @@ error: function(xhr, status, error) {
`; - + container.innerHTML += cardHTML; // Add the I2C card if condition is met - + //creates i2c BME280 card - if (response["BME280/get_data_v2.py"]) { + if (config.BME280) { const i2C_BME_HTML = `
@@ -356,7 +357,7 @@ error: function(xhr, status, error) { } //creates i2c sound card - if (response.i2C_sound) { + if (config.NOISE) { const i2C_HTML = `
@@ -383,7 +384,7 @@ 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 - if (response["envea/read_value_v2.py"]) { + if (config.envea) { console.log("Need to display ENVEA sondes"); //getting config_scripts table $.ajax({ @@ -429,14 +430,9 @@ error: function(xhr, status, error) { });//end AJAX envea Sondes - }//end if - + }//end if envea -}, - error: function(xhr, status, error) { - console.error('AJAX request failed:', status, error); - } - });//end AJAX (config_scripts) + } // end createSensorCards function //get local RTC $.ajax({