update
This commit is contained in:
@@ -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>
|
||||
|
||||
413
html/saraR4.html
413
html/saraR4.html
@@ -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,211 +391,248 @@ function getData_saraR4(port, command, 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({
|
||||
url: 'launcher.php?type=sara_connectNetwork&port='+port+'&networkID='+encodeURIComponent(networkID)+'&timeout='+timeout,
|
||||
dataType:'text',
|
||||
//dataType: 'json', // Specify that you expect a JSON response
|
||||
method: 'GET', // Use GET or POST depending on your needs
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
$("#loading_"+port+"_AT_COPS_Connect").hide();
|
||||
// Replace newline characters with <br> tags
|
||||
const formattedResponse = response.replace(/\n/g, "<br>");
|
||||
$("#response_"+port+"_AT_COPS_Connect").html(formattedResponse);
|
||||
function connectNetwork_saraR4(port, networkID, timeout){
|
||||
console.log(" Connect to network (port "+port+" and network id "+networkID+"):");
|
||||
$("#loading_"+port+"_AT_COPS_Connect").show();
|
||||
$.ajax({
|
||||
url: 'launcher.php?type=sara_connectNetwork&port='+port+'&networkID='+encodeURIComponent(networkID)+'&timeout='+timeout,
|
||||
dataType:'text',
|
||||
//dataType: 'json', // Specify that you expect a JSON response
|
||||
method: 'GET', // Use GET or POST depending on your needs
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
$("#loading_"+port+"_AT_COPS_Connect").hide();
|
||||
// Replace newline characters with <br> tags
|
||||
const formattedResponse = response.replace(/\n/g, "<br>");
|
||||
$("#response_"+port+"_AT_COPS_Connect").html(formattedResponse);
|
||||
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function mqtt_getConfig_saraR4(port, timeout){
|
||||
console.log("GET MQTT config (port "+port+"):");
|
||||
$("#loading_mqtt_getConfig").show();
|
||||
$.ajax({
|
||||
url: 'launcher.php?type=sara_getMQTT_config&port='+port+'&timeout='+timeout,
|
||||
dataType:'text',
|
||||
//dataType: 'json', // Specify that you expect a JSON response
|
||||
method: 'GET', // Use GET or POST depending on your needs
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
$("#loading_mqtt_getConfig").hide();
|
||||
// Replace newline characters with <br> tags
|
||||
const formattedResponse = response.replace(/\n/g, "<br>");
|
||||
$("#response_mqtt_getConfig").html(formattedResponse);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
function mqtt_getConfig_saraR4(port, timeout){
|
||||
console.log("GET MQTT config (port "+port+"):");
|
||||
$("#loading_mqtt_getConfig").show();
|
||||
$.ajax({
|
||||
url: 'launcher.php?type=sara_getMQTT_config&port='+port+'&timeout='+timeout,
|
||||
dataType:'text',
|
||||
//dataType: 'json', // Specify that you expect a JSON response
|
||||
method: 'GET', // Use GET or POST depending on your needs
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
$("#loading_mqtt_getConfig").hide();
|
||||
// Replace newline characters with <br> tags
|
||||
const formattedResponse = response.replace(/\n/g, "<br>");
|
||||
$("#response_mqtt_getConfig").html(formattedResponse);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function mqtt_login_logout(port, login_logout, timeout){
|
||||
console.log("GET MQTT login / logout (port "+port+"):");
|
||||
$("#loading_mqtt_login_logout").show();
|
||||
$.ajax({
|
||||
url: 'launcher.php?type=sara_getMQTT_login_logout&port='+port+'&login_logout='+login_logout+'&timeout='+timeout,
|
||||
dataType:'text',
|
||||
//dataType: 'json', // Specify that you expect a JSON response
|
||||
method: 'GET', // Use GET or POST depending on your needs
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
$("#loading_mqtt_login_logout").hide();
|
||||
const formattedResponse = response.replace(/\n/g, "<br>");
|
||||
$("#response_mqtt_login_logout").html(formattedResponse);
|
||||
function mqtt_login_logout(port, login_logout, timeout){
|
||||
console.log("GET MQTT login / logout (port "+port+"):");
|
||||
$("#loading_mqtt_login_logout").show();
|
||||
$.ajax({
|
||||
url: 'launcher.php?type=sara_getMQTT_login_logout&port='+port+'&login_logout='+login_logout+'&timeout='+timeout,
|
||||
dataType:'text',
|
||||
//dataType: 'json', // Specify that you expect a JSON response
|
||||
method: 'GET', // Use GET or POST depending on your needs
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
$("#loading_mqtt_login_logout").hide();
|
||||
const formattedResponse = response.replace(/\n/g, "<br>");
|
||||
$("#response_mqtt_login_logout").html(formattedResponse);
|
||||
|
||||
const regex = /^\+UMQTTC:\s*(\d+),(\d+)/m; // Match "+UMQTTC:", followed by two numbers separated by a comma
|
||||
const match = response.match(regex);
|
||||
const regex = /^\+UMQTTC:\s*(\d+),(\d+)/m; // Match "+UMQTTC:", followed by two numbers separated by a comma
|
||||
const match = response.match(regex);
|
||||
|
||||
if (match) {
|
||||
const firstNumber = match[1]; // The first number after ":"
|
||||
const secondNumber = match[2]; // The second number after the ","
|
||||
if (firstNumber == 0) {
|
||||
console.log("MQTT LOGOUT:");
|
||||
$("#response_mqtt_login_logout").append("<p>logout</p>");
|
||||
}
|
||||
if (firstNumber == 1) {
|
||||
console.log("MQTT LOGIN:");
|
||||
$("#response_mqtt_login_logout").append("<p>login</p>");
|
||||
}
|
||||
if (secondNumber == 0) {
|
||||
console.log("ERROR");
|
||||
$("#response_mqtt_login_logout").append("<p>error</p>");
|
||||
}
|
||||
if (secondNumber == 1) {
|
||||
console.log("SUCCESS");
|
||||
$("#response_mqtt_login_logout").append("<p>success</p>");
|
||||
}
|
||||
if (match) {
|
||||
const firstNumber = match[1]; // The first number after ":"
|
||||
const secondNumber = match[2]; // The second number after the ","
|
||||
if (firstNumber == 0) {
|
||||
console.log("MQTT LOGOUT:");
|
||||
$("#response_mqtt_login_logout").append("<p>logout</p>");
|
||||
}
|
||||
if (firstNumber == 1) {
|
||||
console.log("MQTT LOGIN:");
|
||||
$("#response_mqtt_login_logout").append("<p>login</p>");
|
||||
}
|
||||
if (secondNumber == 0) {
|
||||
console.log("ERROR");
|
||||
$("#response_mqtt_login_logout").append("<p>error</p>");
|
||||
}
|
||||
if (secondNumber == 1) {
|
||||
console.log("SUCCESS");
|
||||
$("#response_mqtt_login_logout").append("<p>success</p>");
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log("No matching line found");
|
||||
}
|
||||
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
console.log("No matching line found");
|
||||
}
|
||||
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function mqtt_publish(port, message, timeout){
|
||||
console.log(" MQTT publish (port "+port+"):");
|
||||
$("#loading_mqtt_publish").show();
|
||||
$.ajax({
|
||||
url: 'launcher.php?type=sara_MQTT_publish&port='+port+'&timeout='+timeout+'&message='+message,
|
||||
dataType: 'text',
|
||||
//dataType: 'json', // Specify that you expect a JSON response
|
||||
method: 'GET', // Use GET or POST depending on your needs
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
$("#loading_mqtt_publish").hide();
|
||||
// Replace newline characters with <br> tags
|
||||
const formattedResponse = response.replace(/\n/g, "<br>");
|
||||
$("#response_mqtt_publish").html(formattedResponse);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
function mqtt_publish(port, message, timeout){
|
||||
console.log(" MQTT publish (port "+port+"):");
|
||||
$("#loading_mqtt_publish").show();
|
||||
$.ajax({
|
||||
url: 'launcher.php?type=sara_MQTT_publish&port='+port+'&timeout='+timeout+'&message='+message,
|
||||
dataType: 'text',
|
||||
//dataType: 'json', // Specify that you expect a JSON response
|
||||
method: 'GET', // Use GET or POST depending on your needs
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
$("#loading_mqtt_publish").hide();
|
||||
// Replace newline characters with <br> tags
|
||||
const formattedResponse = response.replace(/\n/g, "<br>");
|
||||
$("#response_mqtt_publish").html(formattedResponse);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function setURL_saraR4(port, url){
|
||||
console.log("Set URL for HTTP (port "+port+" and URL "+url+"):");
|
||||
$("#loading_"+port+"_setURL").show();
|
||||
$.ajax({
|
||||
url: 'launcher.php?type=sara_setURL&port='+port+'&url='+encodeURIComponent(url),
|
||||
dataType: 'text',
|
||||
//dataType: 'json', // Specify that you expect a JSON response
|
||||
method: 'GET', // Use GET or POST depending on your needs
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
$("#loading_"+port+"_setURL").hide();
|
||||
// Replace newline characters with <br> tags
|
||||
const formattedResponse = response.replace(/\n/g, "<br>");
|
||||
$("#response_"+port+"_setURL").html(formattedResponse);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
function setURL_saraR4(port, url){
|
||||
console.log("Set URL for HTTP (port "+port+" and URL "+url+"):");
|
||||
$("#loading_"+port+"_setURL").show();
|
||||
$.ajax({
|
||||
url: 'launcher.php?type=sara_setURL&port='+port+'&url='+encodeURIComponent(url),
|
||||
dataType: 'text',
|
||||
//dataType: 'json', // Specify that you expect a JSON response
|
||||
method: 'GET', // Use GET or POST depending on your needs
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
$("#loading_"+port+"_setURL").hide();
|
||||
// Replace newline characters with <br> tags
|
||||
const formattedResponse = response.replace(/\n/g, "<br>");
|
||||
$("#response_"+port+"_setURL").html(formattedResponse);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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({
|
||||
url: 'launcher.php?type=sara_writeMessage&port='+port+'&message='+encodeURIComponent(message)+'&type2='+type,
|
||||
dataType: 'text',
|
||||
//dataType: 'json', // Specify that you expect a JSON response
|
||||
method: 'GET', // Use GET or POST depending on your needs
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
$("#loading_"+port+"_message_write").hide();
|
||||
// Replace newline characters with <br> tags
|
||||
const formattedResponse = response.replace(/\n/g, "<br>");
|
||||
$("#response_"+port+"_message_write").html(formattedResponse);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
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({
|
||||
url: 'launcher.php?type=sara_writeMessage&port='+port+'&message='+encodeURIComponent(message)+'&type2='+type,
|
||||
dataType: 'text',
|
||||
//dataType: 'json', // Specify that you expect a JSON response
|
||||
method: 'GET', // Use GET or POST depending on your needs
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
$("#loading_"+port+"_message_write").hide();
|
||||
// Replace newline characters with <br> tags
|
||||
const formattedResponse = response.replace(/\n/g, "<br>");
|
||||
$("#response_"+port+"_message_write").html(formattedResponse);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function sendMessage_saraR4(port, endpoint){
|
||||
|
||||
console.log("Send message from SaraR4 (port "+port+" and endpoint "+endpoint+"):");
|
||||
function sendMessage_saraR4(port, endpoint){
|
||||
|
||||
console.log("Send message from SaraR4 (port "+port+" and endpoint "+endpoint+"):");
|
||||
|
||||
$("#loading_"+port+"_message_send").show();
|
||||
$("#loading_"+port+"_message_send").show();
|
||||
|
||||
$.ajax({
|
||||
url: 'launcher.php?type=sara_sendMessage&port='+port+'&endpoint='+encodeURIComponent(endpoint),
|
||||
dataType: 'text',
|
||||
//dataType: 'json', // Specify that you expect a JSON response
|
||||
method: 'GET', // Use GET or POST depending on your needs
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
$("#loading_"+port+"_message_send").hide();
|
||||
// Replace newline characters with <br> tags
|
||||
const formattedResponse = response.replace(/\n/g, "<br>");
|
||||
$("#response_"+port+"_message_send").html(formattedResponse);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function connectAPN_saraR4(port, APN_address, timeout){
|
||||
|
||||
console.log(" Set APN (port "+port+" and adress "+APN_address+"):");
|
||||
|
||||
$("#loading_"+port+"_APN").show();
|
||||
|
||||
$.ajax({
|
||||
url: 'launcher.php?type=sara_APN&port='+port+'&APN_address='+encodeURIComponent(APN_address)+'&timeout='+timeout,
|
||||
//dataType: 'json', // Specify that you expect a JSON response
|
||||
dataType: 'text',
|
||||
method: 'GET', // Use GET or POST depending on your needs
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
$("#loading_"+port+"_APN").hide();
|
||||
// Replace newline characters with <br> tags
|
||||
const formattedResponse = response.replace(/\n/g, "<br>");
|
||||
$("#response_"+port+"_APN").html(formattedResponse);
|
||||
url: 'launcher.php?type=sara_sendMessage&port='+port+'&endpoint='+encodeURIComponent(endpoint),
|
||||
dataType: 'text',
|
||||
//dataType: 'json', // Specify that you expect a JSON response
|
||||
method: 'GET', // Use GET or POST depending on your needs
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
$("#loading_"+port+"_message_send").hide();
|
||||
// Replace newline characters with <br> tags
|
||||
const formattedResponse = response.replace(/\n/g, "<br>");
|
||||
$("#response_"+port+"_message_send").html(formattedResponse);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
}
|
||||
});
|
||||
function connectAPN_saraR4(port, APN_address, timeout){
|
||||
|
||||
console.log(" Set APN (port "+port+" and adress "+APN_address+"):");
|
||||
|
||||
$("#loading_"+port+"_APN").show();
|
||||
|
||||
$.ajax({
|
||||
url: 'launcher.php?type=sara_APN&port='+port+'&APN_address='+encodeURIComponent(APN_address)+'&timeout='+timeout,
|
||||
//dataType: 'json', // Specify that you expect a JSON response
|
||||
dataType: 'text',
|
||||
method: 'GET', // Use GET or POST depending on your needs
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
$("#loading_"+port+"_APN").hide();
|
||||
// Replace newline characters with <br> tags
|
||||
const formattedResponse = response.replace(/\n/g, "<br>");
|
||||
$("#response_"+port+"_APN").html(formattedResponse);
|
||||
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
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