Mise à jour capteur bruit: ancien I2C → NSRT MK4 USB
- Nouveau script sound_meter/read.py pour lecture à la demande (JSON) - launcher.php: appel du script Python au lieu de l'ancien binaire C - sensors.html: carte USB, suppression boutons start/stop, affichage JSON - Traductions fr/en: I2C → USB, NSRT MK4 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -23,9 +23,9 @@
|
|||||||
"press": "Pressure"
|
"press": "Pressure"
|
||||||
},
|
},
|
||||||
"noise": {
|
"noise": {
|
||||||
"title": "Decibel Meter",
|
"title": "NSRT MK4",
|
||||||
"description": "Noise sensor on I2C port.",
|
"description": "NSRT MK4 sound level meter on USB port.",
|
||||||
"headerI2c": "I2C Port"
|
"headerUsb": "USB Port"
|
||||||
},
|
},
|
||||||
"envea": {
|
"envea": {
|
||||||
"title": "Envea Probe",
|
"title": "Envea Probe",
|
||||||
|
|||||||
@@ -23,9 +23,9 @@
|
|||||||
"press": "Pression"
|
"press": "Pression"
|
||||||
},
|
},
|
||||||
"noise": {
|
"noise": {
|
||||||
"title": "Sonomètre",
|
"title": "NSRT MK4",
|
||||||
"description": "Capteur bruit sur le port I2C.",
|
"description": "Sonomètre NSRT MK4 sur port USB.",
|
||||||
"headerI2c": "Port I2C"
|
"headerUsb": "Port USB"
|
||||||
},
|
},
|
||||||
"envea": {
|
"envea": {
|
||||||
"title": "Sonde Envea",
|
"title": "Sonde Envea",
|
||||||
|
|||||||
@@ -832,7 +832,7 @@ if ($type == "envea_debug") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($type == "noise") {
|
if ($type == "noise") {
|
||||||
$command = '/var/www/nebuleair_pro_4g/sound_meter/sound_meter';
|
$command = 'sudo /usr/bin/python3 /var/www/nebuleair_pro_4g/sound_meter/read.py';
|
||||||
$output = shell_exec($command);
|
$output = shell_exec($command);
|
||||||
echo $output;
|
echo $output;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -265,35 +265,43 @@
|
|||||||
|
|
||||||
|
|
||||||
function getNoise_values() {
|
function getNoise_values() {
|
||||||
console.log("Data from I2C Noise Sensor:");
|
console.log("Data from NSRT MK4 Noise Sensor:");
|
||||||
$("#loading_noise").show();
|
$("#loading_noise").show();
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'launcher.php?type=noise',
|
url: 'launcher.php?type=noise',
|
||||||
dataType: 'text',
|
dataType: 'json',
|
||||||
method: 'GET', // Use GET or POST depending on your needs
|
method: 'GET',
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
console.log(response);
|
console.log(response);
|
||||||
const tableBody = document.getElementById("data-table-body_noise");
|
const tableBody = document.getElementById("data-table-body_noise");
|
||||||
tableBody.innerHTML = "";
|
tableBody.innerHTML = "";
|
||||||
$("#loading_noise").hide();
|
$("#loading_noise").hide();
|
||||||
|
|
||||||
// Create an array of the desired keys
|
if (response.error) {
|
||||||
const keysToShow = ["Noise"];
|
$("#data-table-body_noise").append(`
|
||||||
// Add only the specified elements to the table
|
<tr><td colspan="2" class="text-danger">${response.error}</td></tr>
|
||||||
keysToShow.forEach(key => {
|
`);
|
||||||
if (response !== undefined) { // Check if the key exists in the response
|
return;
|
||||||
const value = response;
|
}
|
||||||
|
|
||||||
|
const rows = [
|
||||||
|
{ label: "LEQ", value: response.LEQ + " dB" },
|
||||||
|
{ label: "dB(A)", value: response.dBA + " dBA" },
|
||||||
|
{ label: "Weighting", value: response.weighting },
|
||||||
|
{ label: "Tau", value: response.tau + " s" }
|
||||||
|
];
|
||||||
|
rows.forEach(row => {
|
||||||
$("#data-table-body_noise").append(`
|
$("#data-table-body_noise").append(`
|
||||||
<tr>
|
<tr>
|
||||||
<td>${key}</td>
|
<td>${row.label}</td>
|
||||||
<td>${value} DB</td>
|
<td>${row.value}</td>
|
||||||
</tr>
|
</tr>
|
||||||
`);
|
`);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
error: function (xhr, status, error) {
|
error: function (xhr, status, error) {
|
||||||
|
$("#loading_noise").hide();
|
||||||
console.error('AJAX request failed:', status, error);
|
console.error('AJAX request failed:', status, error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -496,21 +504,18 @@
|
|||||||
container.innerHTML += i2C_BME_HTML; // Add the I2C card if condition is met
|
container.innerHTML += i2C_BME_HTML; // Add the I2C card if condition is met
|
||||||
}
|
}
|
||||||
|
|
||||||
//creates i2c sound card
|
//creates NSRT MK4 noise sensor card (USB)
|
||||||
if (config.NOISE) {
|
if (config.NOISE) {
|
||||||
const i2C_HTML = `
|
const noiseHTML = `
|
||||||
<div class="col-sm-3">
|
<div class="col-sm-3">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header" data-i18n="sensors.noise.headerI2c">
|
<div class="card-header" data-i18n="sensors.noise.headerUsb">
|
||||||
Port I2C
|
Port USB
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title" data-i18n="sensors.noise.title">Decibel Meter</h5>
|
<h5 class="card-title" data-i18n="sensors.noise.title">NSRT MK4</h5>
|
||||||
<p class="card-text" data-i18n="sensors.noise.description">Capteur bruit sur le port I2C.</p>
|
<p class="card-text" data-i18n="sensors.noise.description">Sonomètre NSRT MK4 sur port USB.</p>
|
||||||
<button class="btn btn-primary mb-1" onclick="getNoise_values()" data-i18n="common.getData">Get Data</button>
|
<button class="btn btn-primary mb-1" onclick="getNoise_values()" data-i18n="common.getData">Get Data</button>
|
||||||
<br>
|
|
||||||
<button class="btn btn-success" onclick="startNoise()" data-i18n="common.startRecording">Start recording</button>
|
|
||||||
<button class="btn btn-danger" onclick="stopNoise()" data-i18n="common.stopRecording">Stop recording</button>
|
|
||||||
<div id="loading_noise" class="spinner-border spinner-border-sm" style="display: none;" role="status"></div>
|
<div id="loading_noise" class="spinner-border spinner-border-sm" style="display: none;" role="status"></div>
|
||||||
<table class="table table-striped-columns">
|
<table class="table table-striped-columns">
|
||||||
<tbody id="data-table-body_noise"></tbody>
|
<tbody id="data-table-body_noise"></tbody>
|
||||||
@@ -519,7 +524,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
container.innerHTML += i2C_HTML; // Add the I2C card if condition is met
|
container.innerHTML += noiseHTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
//creates MH-Z19 CO2 card
|
//creates MH-Z19 CO2 card
|
||||||
|
|||||||
34
sound_meter/read.py
Normal file
34
sound_meter/read.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
'''
|
||||||
|
____ ___ _ _ _ _ ____
|
||||||
|
/ ___| / _ \| | | | \ | | _ \
|
||||||
|
\___ \| | | | | | | \| | | | |
|
||||||
|
___) | |_| | |_| | |\ | |_| |
|
||||||
|
|____/ \___/ \___/|_| \_|____/
|
||||||
|
|
||||||
|
python3 /var/www/nebuleair_pro_4g/sound_meter/read.py
|
||||||
|
|
||||||
|
Read current values from NSRT MK4 Sound Level Meter (USB /dev/ttyACM0)
|
||||||
|
Used by the web interface "Get Data" button via launcher.php
|
||||||
|
'''
|
||||||
|
|
||||||
|
import json
|
||||||
|
import nsrt_mk3_dev
|
||||||
|
|
||||||
|
try:
|
||||||
|
nsrt = nsrt_mk3_dev.NsrtMk3Dev('/dev/ttyACM0')
|
||||||
|
|
||||||
|
leq_level = nsrt.read_leq()
|
||||||
|
weighted_level = nsrt.read_level()
|
||||||
|
weighting = nsrt.read_weighting()
|
||||||
|
time_constant = nsrt.read_tau()
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"LEQ": round(leq_level, 2),
|
||||||
|
"dBA": round(weighted_level, 2),
|
||||||
|
"weighting": str(weighting),
|
||||||
|
"tau": time_constant
|
||||||
|
}
|
||||||
|
print(json.dumps(data))
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(json.dumps({"error": str(e)}))
|
||||||
Reference in New Issue
Block a user