This commit is contained in:
Your Name
2025-11-05 14:44:30 +01:00
parent 26ee893a96
commit 65beead82b
3 changed files with 94 additions and 47 deletions

View File

@@ -17,55 +17,10 @@ import sys
import json
import re
#get data from config
def load_config(config_file):
try:
with open(config_file, 'r') as file:
config_data = json.load(file)
return config_data
except Exception as e:
print(f"Error loading config file: {e}")
return {}
#Fonction pour mettre à jour le JSON de configuration
def update_json_key(file_path, key, value):
"""
Updates a specific key in a JSON file with a new value.
:param file_path: Path to the JSON file.
:param key: The key to update in the JSON file.
:param value: The new value to assign to the key.
"""
try:
# Load the existing data
with open(file_path, "r") as file:
data = json.load(file)
# Check if the key exists in the JSON file
if key in data:
data[key] = value # Update the key with the new value
else:
print(f"Key '{key}' not found in the JSON file.")
return
# Write the updated data back to the file
with open(file_path, "w") as file:
json.dump(data, file, indent=2) # Use indent for pretty printing
print(f"💾 updating '{key}' to '{value}'.")
except Exception as e:
print(f"Error updating the JSON file: {e}")
# Define the config file path
config_file = '/var/www/nebuleair_pro_4g/config.json'
# Load the configuration data
config = load_config(config_file)
baudrate = config.get('SaraR4_baudrate', 115200) #baudrate du sara R4
device_id = config.get('deviceID', '').upper() #device ID en maj
ser_sara = serial.Serial(
port='/dev/ttyAMA2',
baudrate=baudrate, #115200 ou 9600
baudrate=115200, #115200 ou 9600
parity=serial.PARITY_NONE, #PARITY_NONE, PARITY_EVEN or PARITY_ODD
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,

View File

@@ -343,6 +343,13 @@ if ($type == "sara_ping") {
echo $output;
}
if ($type == "sara_psd_setup") {
$command = 'sudo /usr/bin/python3 /var/www/nebuleair_pro_4g/SARA/R5/setPDP.py';
$output = shell_exec($command);
echo $output;
}
if ($type == "git_pull") {
$command = 'sudo git pull';
$output = shell_exec($command);
@@ -656,6 +663,20 @@ if ($type == "sara_connectNetwork") {
echo $output;
}
#Setup Hostnmae
if ($type == "sara_setupHostname") {
$port=$_GET['port'];
$server_hostname=$_GET['networkID'];
$profileID=$_GET['profileID'];
//echo "connecting to network... please wait...";
$command = 'sudo /usr/bin/python3 /var/www/nebuleair_pro_4g/SARA/sara_setURL.py ' . $port . ' ' . $server_hostname . ' ' . $profileID;
$output = shell_exec($command);
echo $output;
}
#SET THE URL for messaging (profile id 2)

View File

@@ -67,7 +67,7 @@
-->
<div class="row mb-3">
<div class="col-sm-3">
<div class="col-sm-2">
<div class="card">
<div class="card-body">
@@ -252,6 +252,34 @@
</div>
</div>
</div>
<div class="col-sm-4">
<div class="card">
<div class="card-body">
<p class="card-text">Setup PSD connection.</p>
<button class="btn btn-primary" onclick="PSD_setup()">Start</button>
<div id="loading_PSD" class="spinner-border spinner-border-sm" style="display: none;" role="status"></div>
<div id="response_psd_setup"></div>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="card">
<div class="card-body">
<p class="card-text">Setup Server Hostname.</p>
<div class="input-group input-group-sm mb-3">
<span class="input-group-text" id="inputGroup-sizing-sm">Server name</span>
<input type="text" id="messageInput_server" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-sm">
</div>
<button class="btn btn-primary" onclick="setupServerHostname('ttyAMA2', document.getElementById('messageInput_server').value, 0)">Set</button>
<div id="loading_serverHostname" class="spinner-border spinner-border-sm" style="display: none;" role="status"></div>
<div id="response_serverHostname"></div>
</div>
</div>
</div>
</div>
@@ -558,6 +586,28 @@ function connectNetwork_saraR4(port, networkID, timeout){
});
}
function setupServerHostname(port, serverName, timeout){
console.log(" Setupt server hostname "+serverName+"):");
$("#loading_serverHostname").show();
$.ajax({
url: 'launcher.php?type=sara_setupHostname&port='+port+'&networkID='+encodeURIComponent(serverName)+'&profileID=0',
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_serverHostname").hide();
// Replace newline characters with <br> tags
const formattedResponse = response.replace(/\n/g, "<br>");
$("#response_serverHostname").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();
@@ -690,6 +740,27 @@ function ping_test(port, url){
});
}
function PSD_setup(port, url){
console.log("Setup PSD connection:");
$("#loading_PSD").show();
$.ajax({
url: 'launcher.php?type=sara_psd_setup',
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_PSD").hide();
// Replace newline characters with <br> tags
const formattedResponse = response.replace(/\n/g, "<br>");
$("#response_psd_setup").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();