This commit is contained in:
PaulVua
2025-02-10 15:41:52 +01:00
parent 1cb1b05b51
commit e609c38ca0
8 changed files with 210 additions and 25 deletions

View File

@@ -57,12 +57,9 @@
<div class="col-sm-4">
<div class="card text-dark bg-light">
<div class="card-body">
<h5 class="card-title">Consulter Base de donnée</h5>
<p class="card-text">General information.</p>
<button class="btn btn-primary" onclick="get_internet()">Get Data</button>
<table class="table table-striped-columns">
<tbody id="data-table-body_internet_general"></tbody>
</table>
<h5 class="card-title">Consulter la base de donnée</h5>
<button class="btn btn-primary" onclick="get_data_sqlite('data_NPM',10,false)">Mesures PM</button>
<button class="btn btn-primary" onclick="get_data_sqlite('data_BME280',10,false)">Mesures Temp/Hum</button>
</div>
</div>
</div>
@@ -71,19 +68,19 @@
<div class="card text-dark bg-light">
<div class="card-body">
<h5 class="card-title">Télécharger les données</h5>
<p class="card-text">Scan des réseaux WIFI disponibles.</p>
<button class="btn btn-primary" onclick="wifi_scan()">Download</button>
<table class="table">
<tbody id="data-table-body_wifi_scan"></tbody>
</table>
<button class="btn btn-primary" onclick="get_data_sqlite('data_NPM',10,true)">Mesures PM</button>
<button class="btn btn-primary" onclick="get_data_sqlite('data_BME280',10,true)">Mesures Temp/Hum</button>
</table>
</div>
</div>
</div>
<div>
<div class="row mt-2">
<div id="table_data"></div>
</div>
</main>
</div>
@@ -164,11 +161,125 @@
}
});
})
.catch(error => console.error('Error loading config.json:', error));
}
// TABLE PM
function get_data_sqlite(table, limit, download) {
console.log("Getting data for table mesure PM");
$.ajax({
url: 'launcher.php?type=table_mesurePM&table='+table+'&limit='+limit+'&download='+download,
dataType: 'text', // Specify that you expect a JSON response
method: 'GET', // Use GET or POST depending on your needs
success: function(response) {
console.log(response);
// If download is true, generate and trigger CSV download
if (download) {
downloadCSV(response, table);
return; // Exit function after triggering download
}
let rows = response.trim().split("\n");
// Generate Bootstrap table
let tableHTML = `<table class="table table-striped table-bordered">
<thead class="table-dark"><tr>`;
// Define column headers dynamically based on the table type
if (table === "data_NPM") {
tableHTML += `
<th>Timestamp</th>
<th>PM1</th>
<th>PM2.5</th>
<th>PM10</th>
<th>Temperature (°C)</th>
<th>Humidity (%)</th>
`;
} else if (table === "data_BME280") {
tableHTML += `
<th>Timestamp</th>
<th>Temperature (°C)</th>
<th>Humidity (%)</th>
<th>Pressure (hPa)</th>
`;
}
tableHTML += `</tr></thead><tbody>`;
// Loop through rows and create table rows
rows.forEach(row => {
let columns = row.replace(/[()]/g, "").split(", "); // Remove parentheses and split
tableHTML += "<tr>";
if (table === "data_NPM") {
tableHTML += `
<td>${columns[0]}</td>
<td>${columns[1]}</td>
<td>${columns[2]}</td>
<td>${columns[3]}</td>
<td>${columns[4]}</td>
<td>${columns[5]}</td>
`;
} else if (table === "data_BME280") {
tableHTML += `
<td>${columns[0]}</td>
<td>${columns[1]}</td>
<td>${columns[2]}</td>
<td>${columns[3]}</td>
`;
}
tableHTML += "</tr>";
});
tableHTML += `</tbody></table>`;
// Update the #table_data div with the generated table
document.getElementById("table_data").innerHTML = tableHTML;
},
error: function(xhr, status, error) {
console.error('AJAX request failed:', status, error);
}
});
}
function downloadCSV(response, table) {
let rows = response.trim().split("\n");
let csvContent = "";
// Add headers based on table type
if (table === "data_NPM") {
csvContent += "Timestamp,PM1,PM2.5,PM10,Temperature (°C),Humidity (%)\n";
} else if (table === "data_BME280") {
csvContent += "Timestamp,Temperature (°C),Humidity (%),Pressure (hPa)\n";
}
// Format rows as CSV
rows.forEach(row => {
let columns = row.replace(/[()]/g, "").split(", ");
csvContent += columns.join(",") + "\n";
});
// Create a downloadable file
let blob = new Blob([csvContent], { type: "text/csv" });
let url = window.URL.createObjectURL(blob);
let a = document.createElement("a");
a.href = url;
a.download = table + "_data.csv"; // File name
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
</script>
</body>

View File

@@ -84,9 +84,9 @@
</div>
<!--
<div class="row mb-3">
<!-- Card BME values -->
<div class="col-sm-4 mt-2">
<div class="card">
<div class="card-body">
@@ -97,7 +97,7 @@
</div>
</div>
-->
</main>
</div>
</div>

View File

@@ -202,6 +202,17 @@ if ($type == "BME280") {
echo $output;
}
if ($type == "table_mesurePM") {
$table=$_GET['table'];
$limit=$_GET['limit'];
$download=$_GET['download'];
$command = 'sudo /usr/bin/python3 /var/www/nebuleair_pro_4g/sqlite/read.py '.$table.' '.$limit;
$output = shell_exec($command);
echo $output;
}
# SARA R4 COMMANDS
if ($type == "sara") {
$port=$_GET['port'];

View File

@@ -226,7 +226,7 @@ function clear_loopLogs(){
}
function getModem_busy_status() {
console.log("Getting modem busy status");
//console.log("Getting modem busy status");
const script_is_running = document.getElementById("script_running");
@@ -235,7 +235,7 @@ function getModem_busy_status() {
dataType: 'json', // Expecting JSON response
method: 'GET',
success: function(response) {
console.log(response);
//console.log(response);
if (response.running) {
// Script is running → Show the Bootstrap spinner

View File

@@ -51,6 +51,12 @@
<main class="col-md-10 ms-sm-auto col-lg-11 offset-md-2 offset-lg-1 px-md-4">
<h1 class="mt-4">Modem 4G</h1>
<p>Votre capteur est équipé d'un modem 4G et d'une carte SIM afin d'envoyer les mesures sur internet.</p>
<div class="form-check form-switch mb-2">
<input class="form-check-input" type="checkbox" role="switch" id="check_modem_configMode" onchange="update_modem_configMode('modem_config_mode',this.checked)">
<label class="form-check-label" for="check_modem_configMode">Mode configuration</label>
</div>
<span id="modem_status_message"></span>
<h3>
Status
@@ -298,6 +304,17 @@
})
.catch(error => console.error(`Error loading ${file}:`, error));
});
fetch('../config.json') // Replace 'deviceID.txt' with 'config.json'
.then(response => response.json()) // Parse response as JSON
.then(data => {
console.log("Getting config file (onload)");
//modem config mode
const check_modem_configMode = document.getElementById("check_modem_configMode");
check_modem_configMode.checked = data.modem_config_mode;
console.log("Modem configuration: " + data.modem_config_mode);
})
});
function getData_saraR4(port, command, timeout){
@@ -595,7 +612,7 @@ function connectAPN_saraR4(port, APN_address, timeout){
}
function getModem_busy_status() {
console.log("Getting modem busy status");
//console.log("Getting modem busy status");
const SARA_busy_message = document.getElementById("modem_status_message");
@@ -604,19 +621,20 @@ function getModem_busy_status() {
dataType: 'json', // Expecting JSON response
method: 'GET',
success: function(response) {
console.log(response);
//console.log(response);
if (response.running) {
// Script is running → Red button, "Modem is busy"
SARA_busy_message.innerHTML= ` <div class="alert alert-warning" role="alert">
Le modem 4G est en cours d'utilisation. L'utilisation des boutons ci-dessous peut entrainer des erreurs. Veuillez désactiver le modem avant de continuer.
Le modem 4G est en cours d'utilisation! L'utilisation des boutons ci-dessous peut entrainer des erreurs. Veuillez mettre le modem en mode configuration.
</div>`
} else {
// Script is NOT running → Green button, "Modem is available"
SARA_busy_message.innerHTML= ` <div class="alert alert-primary" role="alert">
Le modem 4G est disponible.
Veuillez vous assurer de mettre le modem en mode configuration avant de cliquer sur les boutons ci-dessous. <br>
Une fois terminé veillez à bien désactiver le mode configuration.
</div>`
}
},
@@ -628,6 +646,23 @@ function getModem_busy_status() {
});
}
function update_modem_configMode(param, checked){
console.log("updating modem config mode to :" + checked);
$.ajax({
url: 'launcher.php?type=update_config&param='+param+'&value='+checked,
dataType: 'text', // Specify that you expect a JSON response
method: 'GET', // Use GET or POST depending on your needs
cache: false, // Prevent AJAX from caching
success: function(response) {
console.log(response);
},
error: function(xhr, status, error) {
console.error('AJAX request failed:', status, error);
}
});
}
window.onload = function() {
getModem_busy_status();