diff --git a/SARA/R5/setPDP.py b/SARA/R5/setPDP.py index ba3d07a..3009ca9 100644 --- a/SARA/R5/setPDP.py +++ b/SARA/R5/setPDP.py @@ -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, diff --git a/html/launcher.php b/html/launcher.php index 22d3ce2..b6de08b 100755 --- a/html/launcher.php +++ b/html/launcher.php @@ -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) diff --git a/html/saraR4.html b/html/saraR4.html index c8a6a8d..b4eb244 100755 --- a/html/saraR4.html +++ b/html/saraR4.html @@ -67,7 +67,7 @@ -->
-
+
@@ -252,6 +252,34 @@
+ +
+
+
+

Setup PSD connection.

+ + +
+
+
+
+ +
+
+ +
+

Setup Server Hostname.

+
+ Server name + +
+ + +
+
+
+
+
@@ -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
tags + const formattedResponse = response.replace(/\n/g, "
"); + $("#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
tags + const formattedResponse = response.replace(/\n/g, "
"); + $("#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();