update
This commit is contained in:
175
html/admin.html
175
html/admin.html
@@ -248,7 +248,34 @@
|
|||||||
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
|
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Envea Detection Modal -->
|
||||||
|
<div class="modal fade" id="enveaDetectionModal" tabindex="-1" aria-labelledby="enveaDetectionModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-lg">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="enveaDetectionModalLabel">Envea Sondes Detection</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<div id="detectionProgress" class="text-center" style="display: none;">
|
||||||
|
<div class="spinner-border text-primary" role="status">
|
||||||
|
<span class="visually-hidden">Loading...</span>
|
||||||
|
</div>
|
||||||
|
<p class="mt-2">Scanning ports for Envea devices...</p>
|
||||||
|
</div>
|
||||||
|
<div id="detectionResults">
|
||||||
|
<p>Click "Start Detection" to scan for connected Envea devices.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||||
|
<button type="button" class="btn btn-primary" id="startDetectionBtn" onclick="startEnveaDetection()">Start Detection</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
@@ -706,7 +733,7 @@ function add_sondeEnveaContainer() {
|
|||||||
$('#advanced_options').append('<div id="sondes_envea_div" class="input-group mt-4 border p-3 rounded"><legend>Sondes Envea</legend><p>Plouf</p></div>');
|
$('#advanced_options').append('<div id="sondes_envea_div" class="input-group mt-4 border p-3 rounded"><legend>Sondes Envea</legend><p>Plouf</p></div>');
|
||||||
} else {
|
} else {
|
||||||
// Clear existing content if container exists
|
// Clear existing content if container exists
|
||||||
$('#sondes_envea_div').html('<legend>Sondes Envea</legend>');
|
$('#sondes_envea_div').html('<legend>Sondes Envea <button type="button" class="btn btn-sm btn-info ms-2" onclick="detectEnveaSondes()">Detect Devices</button></legend>');
|
||||||
$('#envea_table').html('<table class="table table-striped table-bordered">'+
|
$('#envea_table').html('<table class="table table-striped table-bordered">'+
|
||||||
'<thead><tr><th scope="col">Software</th><th scope="col">Hardware (PCB)</th></tr></thead>'+
|
'<thead><tr><th scope="col">Software</th><th scope="col">Hardware (PCB)</th></tr></thead>'+
|
||||||
'<tbody>' +
|
'<tbody>' +
|
||||||
@@ -738,7 +765,7 @@ function add_sondeEnveaContainer() {
|
|||||||
<option value="ttyAMA5" ${sonde.port === 'ttyAMA5' ? 'selected' : ''}>ttyAMA5</option>
|
<option value="ttyAMA5" ${sonde.port === 'ttyAMA5' ? 'selected' : ''}>ttyAMA5</option>
|
||||||
</select>
|
</select>
|
||||||
<input type="number" class="form-control" placeholder="Coefficient" value="${sonde.coefficient}"
|
<input type="number" class="form-control" placeholder="Coefficient" value="${sonde.coefficient}"
|
||||||
id="${sondeId}_coefficient" readonly style="background-color: #f8f9fa;">
|
id="${sondeId}_coefficient" onchange="updateSondeCoefficientWithConfirm(${sonde.id}, this.value, this)">
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@@ -936,6 +963,23 @@ function updateSondePort(id, port) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateSondeCoefficientWithConfirm(id, coefficient, inputElement) {
|
||||||
|
// Store the previous value in case user cancels
|
||||||
|
const previousValue = inputElement.getAttribute('data-previous-value') || inputElement.defaultValue;
|
||||||
|
|
||||||
|
// Show confirmation dialog
|
||||||
|
const confirmed = confirm(`Are you sure you want to change the coefficient to ${coefficient}?\n\nThis will affect sensor calibration and data accuracy.`);
|
||||||
|
|
||||||
|
if (confirmed) {
|
||||||
|
// Store the new value as previous for next time
|
||||||
|
inputElement.setAttribute('data-previous-value', coefficient);
|
||||||
|
updateSondeCoefficient(id, coefficient);
|
||||||
|
} else {
|
||||||
|
// Revert to previous value
|
||||||
|
inputElement.value = previousValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function updateSondeCoefficient(id, coefficient) {
|
function updateSondeCoefficient(id, coefficient) {
|
||||||
console.log(`Updating sonde ${id} coefficient to: ${coefficient}`);
|
console.log(`Updating sonde ${id} coefficient to: ${coefficient}`);
|
||||||
const toastLiveExample = document.getElementById('liveToast');
|
const toastLiveExample = document.getElementById('liveToast');
|
||||||
@@ -1242,6 +1286,131 @@ function toggleService(serviceName, enable) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
_____ ____ _ _ _
|
||||||
|
| ____|_ ____ _____ __ _ | _ \ ___| |_ ___ ___| |_(_) ___ _ __
|
||||||
|
| _| | '_ \ \ / / _ \/ _` | | | | |/ _ \ __/ _ \/ __| __| |/ _ \| '_ \
|
||||||
|
| |___| | | \ V / __/ (_| | | |_| | __/ || __/ (__| |_| | (_) | | | |
|
||||||
|
|_____|_| |_|\_/ \___|\__,_| |____/ \___|\__\___|\___|\__|_|\___/|_| |_|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
function detectEnveaSondes() {
|
||||||
|
console.log("Opening Envea detection modal");
|
||||||
|
const modal = new bootstrap.Modal(document.getElementById('enveaDetectionModal'));
|
||||||
|
modal.show();
|
||||||
|
|
||||||
|
// Reset modal content
|
||||||
|
document.getElementById('detectionProgress').style.display = 'none';
|
||||||
|
document.getElementById('detectionResults').innerHTML = '<p>Click "Start Detection" to scan for connected Envea devices.</p>';
|
||||||
|
document.getElementById('startDetectionBtn').style.display = 'inline-block';
|
||||||
|
}
|
||||||
|
|
||||||
|
function startEnveaDetection() {
|
||||||
|
console.log("Starting Envea device detection");
|
||||||
|
|
||||||
|
// Show progress spinner
|
||||||
|
document.getElementById('detectionProgress').style.display = 'block';
|
||||||
|
document.getElementById('detectionResults').innerHTML = '';
|
||||||
|
document.getElementById('startDetectionBtn').style.display = 'none';
|
||||||
|
|
||||||
|
// Test the three ports: ttyAMA3, ttyAMA4, ttyAMA5
|
||||||
|
const ports = ['ttyAMA3', 'ttyAMA4', 'ttyAMA5'];
|
||||||
|
let completedTests = 0;
|
||||||
|
let results = [];
|
||||||
|
|
||||||
|
ports.forEach(function(port, index) {
|
||||||
|
$.ajax({
|
||||||
|
url: `launcher.php?type=detect_envea_device&port=${port}`,
|
||||||
|
dataType: 'json',
|
||||||
|
method: 'GET',
|
||||||
|
cache: false,
|
||||||
|
timeout: 10000, // 10 second timeout per port
|
||||||
|
success: function(response) {
|
||||||
|
console.log(`Detection result for ${port}:`, response);
|
||||||
|
|
||||||
|
results[index] = {
|
||||||
|
port: port,
|
||||||
|
success: response.success,
|
||||||
|
data: response.data || '',
|
||||||
|
error: response.error || '',
|
||||||
|
detected: response.detected || false,
|
||||||
|
device_info: response.device_info || ''
|
||||||
|
};
|
||||||
|
|
||||||
|
completedTests++;
|
||||||
|
if (completedTests === ports.length) {
|
||||||
|
displayDetectionResults(results);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(xhr, status, error) {
|
||||||
|
console.error(`Detection failed for ${port}:`, error);
|
||||||
|
|
||||||
|
results[index] = {
|
||||||
|
port: port,
|
||||||
|
success: false,
|
||||||
|
data: '',
|
||||||
|
error: `Request failed: ${error}`,
|
||||||
|
detected: false,
|
||||||
|
device_info: ''
|
||||||
|
};
|
||||||
|
|
||||||
|
completedTests++;
|
||||||
|
if (completedTests === ports.length) {
|
||||||
|
displayDetectionResults(results);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function displayDetectionResults(results) {
|
||||||
|
console.log("Displaying detection results:", results);
|
||||||
|
|
||||||
|
// Hide progress spinner
|
||||||
|
document.getElementById('detectionProgress').style.display = 'none';
|
||||||
|
|
||||||
|
let htmlContent = '<h6>Detection Results:</h6>';
|
||||||
|
htmlContent += '<div class="table-responsive">';
|
||||||
|
htmlContent += '<table class="table table-sm table-striped">';
|
||||||
|
htmlContent += '<thead><tr><th>Port</th><th>Status</th><th>Device Info</th><th>Raw Data</th></tr></thead>';
|
||||||
|
htmlContent += '<tbody>';
|
||||||
|
|
||||||
|
results.forEach(function(result) {
|
||||||
|
const statusBadge = result.detected ?
|
||||||
|
'<span class="badge bg-success">Device Detected</span>' :
|
||||||
|
result.success ?
|
||||||
|
'<span class="badge bg-warning">No Device</span>' :
|
||||||
|
'<span class="badge bg-danger">Error</span>';
|
||||||
|
|
||||||
|
const deviceInfo = result.device_info || (result.detected ? 'Envea Device' : 'None');
|
||||||
|
const rawData = result.data ? result.data.substring(0, 50) + (result.data.length > 50 ? '...' : '') : 'No data';
|
||||||
|
|
||||||
|
htmlContent += `<tr>
|
||||||
|
<td><strong>${result.port}</strong></td>
|
||||||
|
<td>${statusBadge}</td>
|
||||||
|
<td>${deviceInfo}</td>
|
||||||
|
<td><small class="text-muted">${rawData}</small></td>
|
||||||
|
</tr>`;
|
||||||
|
|
||||||
|
if (result.error) {
|
||||||
|
htmlContent += `<tr><td colspan="4"><small class="text-danger">Error: ${result.error}</small></td></tr>`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
htmlContent += '</tbody></table></div>';
|
||||||
|
|
||||||
|
// Add summary
|
||||||
|
const detectedCount = results.filter(r => r.detected).length;
|
||||||
|
htmlContent += `<div class="alert alert-info mt-3">
|
||||||
|
<strong>Summary:</strong> ${detectedCount} device(s) detected out of ${results.length} ports tested.
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
document.getElementById('detectionResults').innerHTML = htmlContent;
|
||||||
|
document.getElementById('startDetectionBtn').style.display = 'inline-block';
|
||||||
|
document.getElementById('startDetectionBtn').textContent = 'Scan Again';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -71,9 +71,16 @@ if deleted_count > 0:
|
|||||||
print(f"Deleted {deleted_count} duplicate envea sonde entries")
|
print(f"Deleted {deleted_count} duplicate envea sonde entries")
|
||||||
|
|
||||||
# Insert envea sondes (only if they don't already exist)
|
# Insert envea sondes (only if they don't already exist)
|
||||||
|
# Attention pour le H2S il y a plusieurs sondes
|
||||||
|
# H2S 1ppm -> coef 4
|
||||||
|
# H2S 20ppm -> coef 1
|
||||||
|
# H2S 200ppm -> coef 10
|
||||||
|
|
||||||
envea_sondes = [
|
envea_sondes = [
|
||||||
(False, "ttyAMA4", "h2s", 4),
|
(False, "ttyAMA4", "h2s", 4), #H2S
|
||||||
(False, "ttyAMA3", "no2", 1),
|
(False, "ttyAMA3", "no2", 1),
|
||||||
|
(False, "ttyAMA3", "nh3", 100),
|
||||||
|
(False, "ttyAMA3", "so2", 4),
|
||||||
(False, "ttyAMA2", "o3", 1)
|
(False, "ttyAMA2", "o3", 1)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user