update
This commit is contained in:
@@ -3,10 +3,10 @@ Check if the main loop is running
|
||||
/usr/bin/python3 /var/www/nebuleair_pro_4g/tests/check_running.py
|
||||
'''
|
||||
import psutil
|
||||
import subprocess
|
||||
import json
|
||||
|
||||
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']):
|
||||
if process.info['cmdline'] and script_name in " ".join(process.info['cmdline']):
|
||||
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"
|
||||
|
||||
if is_script_running(script_to_check):
|
||||
print(f"{script_to_check} is still running.❌❌❌")
|
||||
else:
|
||||
print(f"{script_to_check} is NOT running.✅✅✅")
|
||||
# Determine script status
|
||||
is_running = is_script_running(script_to_check)
|
||||
|
||||
# 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
|
||||
|
||||
@@ -44,6 +44,12 @@ if ($type == "update_config") {
|
||||
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") {
|
||||
$time = shell_exec("date '+%d/%m/%Y %H:%M:%S'");
|
||||
echo $time;
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
<div class="card" style="height: 80vh;">
|
||||
<div class="card-header">
|
||||
Master logs <button type="submit" class="btn btn-secondary btn-sm" onclick="clear_loopLogs()">Clear</button>
|
||||
|
||||
<span id="script_running"></span>
|
||||
</div>
|
||||
<div class="card-body overflow-auto" id="card_loop_content">
|
||||
|
||||
@@ -166,6 +166,9 @@
|
||||
|
||||
|
||||
window.onload = function() {
|
||||
getModem_busy_status();
|
||||
setInterval(getModem_busy_status, 2000);
|
||||
|
||||
fetch('../config.json') // Replace 'deviceID.txt' with 'config.json'
|
||||
.then(response => response.json()) // Parse response as JSON
|
||||
.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>
|
||||
|
||||
</body>
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
<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>
|
||||
<p>Verification utilisation du Modem:</p>
|
||||
<span id="modem_status_message"></span>
|
||||
<h3>
|
||||
Status
|
||||
<span id="modem-status" class="badge">Loading...</span>
|
||||
@@ -391,7 +391,7 @@ function getData_saraR4(port, command, timeout){
|
||||
});
|
||||
}
|
||||
|
||||
function connectNetwork_saraR4(port, networkID, timeout){
|
||||
function connectNetwork_saraR4(port, networkID, timeout){
|
||||
console.log(" Connect to network (port "+port+" and network id "+networkID+"):");
|
||||
$("#loading_"+port+"_AT_COPS_Connect").show();
|
||||
$.ajax({
|
||||
@@ -413,7 +413,7 @@ function getData_saraR4(port, command, timeout){
|
||||
});
|
||||
}
|
||||
|
||||
function mqtt_getConfig_saraR4(port, timeout){
|
||||
function mqtt_getConfig_saraR4(port, timeout){
|
||||
console.log("GET MQTT config (port "+port+"):");
|
||||
$("#loading_mqtt_getConfig").show();
|
||||
$.ajax({
|
||||
@@ -434,7 +434,7 @@ function getData_saraR4(port, command, timeout){
|
||||
});
|
||||
}
|
||||
|
||||
function mqtt_login_logout(port, login_logout, timeout){
|
||||
function mqtt_login_logout(port, login_logout, timeout){
|
||||
console.log("GET MQTT login / logout (port "+port+"):");
|
||||
$("#loading_mqtt_login_logout").show();
|
||||
$.ajax({
|
||||
@@ -473,7 +473,7 @@ function getData_saraR4(port, command, timeout){
|
||||
|
||||
} else {
|
||||
console.log("No matching line found");
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
@@ -482,7 +482,7 @@ function getData_saraR4(port, command, timeout){
|
||||
});
|
||||
}
|
||||
|
||||
function mqtt_publish(port, message, timeout){
|
||||
function mqtt_publish(port, message, timeout){
|
||||
console.log(" MQTT publish (port "+port+"):");
|
||||
$("#loading_mqtt_publish").show();
|
||||
$.ajax({
|
||||
@@ -503,7 +503,7 @@ function getData_saraR4(port, command, timeout){
|
||||
});
|
||||
}
|
||||
|
||||
function setURL_saraR4(port, url){
|
||||
function setURL_saraR4(port, url){
|
||||
console.log("Set URL for HTTP (port "+port+" and URL "+url+"):");
|
||||
$("#loading_"+port+"_setURL").show();
|
||||
$.ajax({
|
||||
@@ -524,7 +524,7 @@ function getData_saraR4(port, command, timeout){
|
||||
});
|
||||
}
|
||||
|
||||
function writeMessage_saraR4(port, message, type){
|
||||
function writeMessage_saraR4(port, message, type){
|
||||
console.log(type +" message to SARA R4 memory (port "+port+" and message "+message+"):");
|
||||
$("#loading_"+port+"_message_write").show();
|
||||
$.ajax({
|
||||
@@ -545,7 +545,7 @@ function getData_saraR4(port, command, timeout){
|
||||
});
|
||||
}
|
||||
|
||||
function sendMessage_saraR4(port, endpoint){
|
||||
function sendMessage_saraR4(port, endpoint){
|
||||
|
||||
console.log("Send message from SaraR4 (port "+port+" and endpoint "+endpoint+"):");
|
||||
|
||||
@@ -569,7 +569,7 @@ function getData_saraR4(port, command, timeout){
|
||||
});
|
||||
}
|
||||
|
||||
function connectAPN_saraR4(port, APN_address, timeout){
|
||||
function connectAPN_saraR4(port, APN_address, timeout){
|
||||
|
||||
console.log(" Set APN (port "+port+" and adress "+APN_address+"):");
|
||||
|
||||
@@ -592,10 +592,47 @@ function getData_saraR4(port, command, timeout){
|
||||
console.error('AJAX request failed:', status, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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() {
|
||||
getModem_busy_status();
|
||||
setInterval(getModem_busy_status, 1000);
|
||||
|
||||
fetch('../config.json') // Replace 'deviceID.txt' with 'config.json'
|
||||
.then(response => response.json()) // Parse response as JSON
|
||||
.then(data => {
|
||||
|
||||
Reference in New Issue
Block a user