This commit is contained in:
PaulVua
2025-02-07 15:04:11 +01:00
parent fb44b57ac1
commit 7cac769795
4 changed files with 279 additions and 195 deletions

View File

@@ -3,10 +3,10 @@ Check if the main loop is running
/usr/bin/python3 /var/www/nebuleair_pro_4g/tests/check_running.py /usr/bin/python3 /var/www/nebuleair_pro_4g/tests/check_running.py
''' '''
import psutil import psutil
import subprocess import json
def is_script_running(script_name): def is_script_running(script_name):
"""Check if a given Python script is running.""" """Check if a given Python script is currently running."""
for process in psutil.process_iter(['pid', 'cmdline']): for process in psutil.process_iter(['pid', 'cmdline']):
if process.info['cmdline'] and script_name in " ".join(process.info['cmdline']): if process.info['cmdline'] and script_name in " ".join(process.info['cmdline']):
return True # Script is running return True # Script is running
@@ -14,7 +14,14 @@ def is_script_running(script_name):
script_to_check = "/var/www/nebuleair_pro_4g/loop/SARA_send_data_v2.py" script_to_check = "/var/www/nebuleair_pro_4g/loop/SARA_send_data_v2.py"
if is_script_running(script_to_check): # Determine script status
print(f"{script_to_check} is still running.❌❌❌") is_running = is_script_running(script_to_check)
else:
print(f"{script_to_check} is NOT running.✅✅✅") # Create JSON response
response = {
"message": "The script is still running.❌❌❌" if is_running else "The script is NOT running.✅✅✅",
"running": is_running
}
# Print JSON output
print(json.dumps(response, indent=4)) # Pretty print for readability

View File

@@ -44,6 +44,12 @@ if ($type == "update_config") {
echo "Config updated!"; echo "Config updated!";
} }
if ($type == "getModem_busy") {
$command = '/usr/bin/python3 /var/www/nebuleair_pro_4g/SARA/check_running.py';
$output = shell_exec($command);
echo $output;
}
if ($type == "RTC_time") { if ($type == "RTC_time") {
$time = shell_exec("date '+%d/%m/%Y %H:%M:%S'"); $time = shell_exec("date '+%d/%m/%Y %H:%M:%S'");
echo $time; echo $time;

View File

@@ -57,7 +57,7 @@
<div class="card" style="height: 80vh;"> <div class="card" style="height: 80vh;">
<div class="card-header"> <div class="card-header">
Master logs <button type="submit" class="btn btn-secondary btn-sm" onclick="clear_loopLogs()">Clear</button> Master logs <button type="submit" class="btn btn-secondary btn-sm" onclick="clear_loopLogs()">Clear</button>
<span id="script_running"></span>
</div> </div>
<div class="card-body overflow-auto" id="card_loop_content"> <div class="card-body overflow-auto" id="card_loop_content">
@@ -166,6 +166,9 @@
window.onload = function() { window.onload = function() {
getModem_busy_status();
setInterval(getModem_busy_status, 2000);
fetch('../config.json') // Replace 'deviceID.txt' with 'config.json' fetch('../config.json') // Replace 'deviceID.txt' with 'config.json'
.then(response => response.json()) // Parse response as JSON .then(response => response.json()) // Parse response as JSON
.then(data => { .then(data => {
@@ -221,6 +224,37 @@ function clear_loopLogs(){
} }
}); });
} }
function getModem_busy_status() {
console.log("Getting modem busy status");
const script_is_running = document.getElementById("script_running");
$.ajax({
url: 'launcher.php?type=getModem_busy',
dataType: 'json', // Expecting JSON response
method: 'GET',
success: function(response) {
console.log(response);
if (response.running) {
// Script is running → Show the Bootstrap spinner
script_is_running.innerHTML = `
<div class="spinner-border text-danger" role="status">
<span class="visually-hidden">Modem is busy...</span>
</div>
`;
} else {
// Script is NOT running → Show a success message (no spinner)
script_is_running.innerHTML = ``;
}
},
error: function(xhr, status, error) {
console.error('AJAX request failed:', status, error);
script_is_running.innerHTML = `<span class="text-warning">Error checking status ⚠️</span>`;
}
});
}
</script> </script>
</body> </body>

View File

@@ -51,7 +51,7 @@
<main class="col-md-10 ms-sm-auto col-lg-11 offset-md-2 offset-lg-1 px-md-4"> <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> <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> <p>Votre capteur est équipé d'un modem 4G et d'une carte SIM afin d'envoyer les mesures sur internet.</p>
<p>Verification utilisation du Modem:</p> <span id="modem_status_message"></span>
<h3> <h3>
Status Status
<span id="modem-status" class="badge">Loading...</span> <span id="modem-status" class="badge">Loading...</span>
@@ -594,8 +594,45 @@ function getData_saraR4(port, command, timeout){
}); });
} }
function getModem_busy_status() {
console.log("Getting modem busy status");
const SARA_busy_message = document.getElementById("modem_status_message");
$.ajax({
url: 'launcher.php?type=getModem_busy',
dataType: 'json', // Expecting JSON response
method: 'GET',
success: function(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.
</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.
</div>`
}
},
error: function(xhr, status, error) {
console.error('AJAX request failed:', status, error);
SARA_busy_status.textContent = "Error checking status";
SARA_busy_status.className = "btn text-bg-warning"; // Yellow button for errors
}
});
}
window.onload = function() { window.onload = function() {
getModem_busy_status();
setInterval(getModem_busy_status, 1000);
fetch('../config.json') // Replace 'deviceID.txt' with 'config.json' fetch('../config.json') // Replace 'deviceID.txt' with 'config.json'
.then(response => response.json()) // Parse response as JSON .then(response => response.json()) // Parse response as JSON
.then(data => { .then(data => {