From ddbd85a03571cd7a1459885ad149ddaf01a3eed1 Mon Sep 17 00:00:00 2001 From: PaulVua Date: Sun, 12 Jan 2025 17:12:58 +0100 Subject: [PATCH] update --- html/index.html | 74 ++++++++++++++++- html/launcher.php | 6 ++ loop/1_NPM/send_data.py | 178 +++++++++++++++++++++------------------- 3 files changed, 169 insertions(+), 89 deletions(-) diff --git a/html/index.html b/html/index.html index 07d658e..32c7583 100755 --- a/html/index.html +++ b/html/index.html @@ -59,8 +59,11 @@
Linux stats
-

Disk space

+

Disk usage (total size Gb)

+ +

Memory usage (total size Mb)

+
@@ -130,14 +133,19 @@ window.onload = function() { method: 'GET', // Use GET or POST depending on your needs success: function(response) { console.log("Linux disk space: " + response); + //1. disk size + const disk_size = document.getElementById("disk_size"); + const firstNumber = response.match(/(? console.error('Error loading config.json:', error)); - } + } diff --git a/html/launcher.php b/html/launcher.php index 4697416..378fd56 100755 --- a/html/launcher.php +++ b/html/launcher.php @@ -18,6 +18,12 @@ if ($type == "linux_disk") { echo $output; } +if ($type == "linux_memory") { + $command = 'free -h'; + $output = shell_exec($command); + echo $output; +} + if ($type == "sshTunnel") { $ssh_port=$_GET['ssh_port']; $command = 'sudo ssh -i /var/www/.ssh/id_rsa -f -N -R "'.$ssh_port.':localhost:22" -p 50221 -o StrictHostKeyChecking=no "airlab_server1@aircarto.fr"'; diff --git a/loop/1_NPM/send_data.py b/loop/1_NPM/send_data.py index 8bd8306..fa4d7af 100755 --- a/loop/1_NPM/send_data.py +++ b/loop/1_NPM/send_data.py @@ -115,6 +115,7 @@ config_file = '/var/www/nebuleair_pro_4g/config.json' # Load the configuration data config = load_config(config_file) + # Access the shared variables baudrate = config.get('SaraR4_baudrate', 115200) #baudrate du sara R4 device_id = config.get('deviceID', '').upper() #device ID en maj @@ -123,6 +124,7 @@ bme_280_config = config.get('i2c_BME', False) #présence du BME280 i2C_sound_config = config.get('i2C_sound', False) #présence du capteur son envea_sondes = config.get('envea_sondes', []) connected_envea_sondes = [sonde for sonde in envea_sondes if sonde.get('connected', False)] +selected_networkID = config.get('SARA_R4_neworkID', '') ser_sara = serial.Serial( port='/dev/ttyAMA2', @@ -293,103 +295,109 @@ try: command= f'AT+UHTTPC=0,4,"/pro_4G/data.php?sensor_id={device_id}","server_response.txt","sensordata.json",4\r' ser_sara.write((command + '\r').encode('utf-8')) response_SARA_3 = read_complete_response(ser_sara) - if need_to_log: - print("Send data:") - print(response_SARA_3) + + print("Send data:") + print(response_SARA_3) - # Les types de réponse + # Les types de réponse - # 1.La commande n'a pas fonctionné - # +CME ERROR: No connection to phone - # +CME ERROR: Operation not allowed + # 1.La commande n'a pas fonctionné + # +CME ERROR: No connection to phone + # +CME ERROR: Operation not allowed - # 2.La commande fonctionne: elle renvoie un code - # +UUHTTPCR: ,, - # : 1 pour sucess et 0 pour fail - # +UUHTTPCR: 0,4,1 -> OK - # +UUHTTPCR: 0,4,0 -> error + # 2.La commande fonctionne: elle renvoie un code + # +UUHTTPCR: ,, + # : 1 pour sucess et 0 pour fail + # +UUHTTPCR: 0,4,1 -> OK + # +UUHTTPCR: 0,4,0 -> error - # Split response into lines - lines = response_SARA_3.strip().splitlines() + # Split response into lines + lines = response_SARA_3.strip().splitlines() - # 1.Vérifier si la réponse contient un message d'erreur CME - if "+CME ERROR" in lines[-1]: + # 1.Vérifier si la réponse contient un message d'erreur CME + if "+CME ERROR" in lines[-1]: + print("*****") + print('ATTENTION: CME ERROR') + print("error:", lines[-1]) + print("*****") + #update status + update_json_key(config_file, "SARA_R4_network_status", "disconnected") + + # Gestion de l'erreur spécifique + if "No connection to phone" in lines[-1]: + print("No connection to the phone. Retrying or reset may be required.") + # Actions spécifiques pour ce type d'erreur (par exemple, réinitialiser ou tenter de reconnecter) + # need to reconnect to network + # and reset HTTP profile (AT+UHTTP=0) -> ne fonctionne pas.. + # tester un reset avec CFUN 15 + # 1.Reconnexion au réseau (AT+COPS) + command = f'AT+COPS=1,2,{selected_networkID}\r' + ser_sara.write((command + '\r').encode('utf-8')) + responseReconnect = read_complete_response(ser_sara) + print("Response:") + print(responseReconnect) + + elif "Operation not allowed" in lines[-1]: + print("Operation not allowed. This may require a different configuration.") + # Actions spécifiques pour ce type d'erreur + + # Clignotement LED en cas d'erreur + GPIO.output(23, GPIO.LOW) # Éteindre la LED définitivement + for _ in range(4): + GPIO.output(23, GPIO.HIGH) # Allumer la LED + time.sleep(0.1) + GPIO.output(23, GPIO.LOW) # Éteindre la LED + time.sleep(0.1) + GPIO.output(23, GPIO.LOW) # Turn off the LED + + else: + # 2.Si la réponse contient une réponse HTTP valide + # Extract HTTP response code from the last line + # ATTENTION: lines[-1] renvoie l'avant dernière ligne et il peut y avoir un soucis avec le OK + # rechercher plutot + http_response = lines[-1] # "+UUHTTPCR: 0,4,0" + parts = http_response.split(',') + + # 2.1 code 0 (HTTP failed) + if len(parts) == 3 and parts[-1] == '0': # The third value indicates success print("*****") - print('ATTENTION: CME ERROR') - print("error:", lines[-1]) - print("*****") - #update status + print('ATTENTION: HTTP operation failed') update_json_key(config_file, "SARA_R4_network_status", "disconnected") - - # Gestion de l'erreur spécifique - if "No connection to phone" in lines[-1]: - print("No connection to the phone. Retrying or reset may be required.") - # Actions spécifiques pour ce type d'erreur (par exemple, réinitialiser ou tenter de reconnecter) - # need to reconnect to network - # and reset HTTP profile (AT+UHTTP=0) -> ne fonctionne pas.. - # tester un reset avec CFUN 15 - - elif "Operation not allowed" in lines[-1]: - print("Operation not allowed. This may require a different configuration.") - # Actions spécifiques pour ce type d'erreur - - # Clignotement LED en cas d'erreur - GPIO.output(23, GPIO.LOW) # Éteindre la LED définitivement - for _ in range(4): + print("*****") + print("resetting the URL (domain name):") + print("Turning off the blue LED...") + for _ in range(4): # Faire clignoter 4 fois GPIO.output(23, GPIO.HIGH) # Allumer la LED - time.sleep(0.1) + time.sleep(0.1) # Attendre 100 ms GPIO.output(23, GPIO.LOW) # Éteindre la LED - time.sleep(0.1) + time.sleep(0.1) # Attendre 100 ms GPIO.output(23, GPIO.LOW) # Turn off the LED + command = f'AT+UHTTP=0,1,"{url}"\r' + ser_sara.write((command + '\r').encode('utf-8')) + response_SARA_31 = read_complete_response(ser_sara) + if need_to_log: + print(response_SARA_31) + # 2.2 code 1 (HHTP succeded) else: - # 2.Si la réponse contient une réponse HTTP valide - # Extract HTTP response code from the last line - # ATTENTION: lines[-1] renvoie l'avant dernière ligne et il peut y avoir un soucis avec le OK - # rechercher plutot - http_response = lines[-1] # "+UUHTTPCR: 0,4,0" - parts = http_response.split(',') - - # 2.1 code 0 (HTTP failed) - if len(parts) == 3 and parts[-1] == '0': # The third value indicates success - print("*****") - print('ATTENTION: HTTP operation failed') - update_json_key(config_file, "SARA_R4_network_status", "disconnected") - print("*****") - print("resetting the URL (domain name):") - print("Turning off the blue LED...") - for _ in range(4): # Faire clignoter 4 fois - GPIO.output(23, GPIO.HIGH) # Allumer la LED - time.sleep(0.1) # Attendre 100 ms - GPIO.output(23, GPIO.LOW) # Éteindre la LED - time.sleep(0.1) # Attendre 100 ms - GPIO.output(23, GPIO.LOW) # Turn off the LED - command = f'AT+UHTTP=0,1,"{url}"\r' - ser_sara.write((command + '\r').encode('utf-8')) - response_SARA_31 = read_complete_response(ser_sara) - if need_to_log: - print(response_SARA_31) - - # 2.2 code 1 (HHTP succeded) - else: - # Si la commande HTTP a réussi - print('HTTP operation successful.') - update_json_key(config_file, "SARA_R4_network_status", "connected") - print("Turning on the blue LED...") - for _ in range(4): # Faire clignoter 4 fois - GPIO.output(23, GPIO.HIGH) # Allumer la LED - time.sleep(0.1) # Attendre 100 ms - GPIO.output(23, GPIO.LOW) # Éteindre la LED - time.sleep(0.1) # Attendre 100 ms - GPIO.output(23, GPIO.HIGH) # Turn on the LED - #4. Read reply from server - ser_sara.write(b'AT+URDFILE="server_response.txt"\r') - response_SARA_4 = read_complete_response(ser_sara) - if need_to_log: - print("Reply from server:") - print('

') - print(response_SARA_4) - print('

') + # Si la commande HTTP a réussi + print('HTTP operation successful.') + update_json_key(config_file, "SARA_R4_network_status", "connected") + print("Turning on the blue LED...") + for _ in range(4): # Faire clignoter 4 fois + GPIO.output(23, GPIO.HIGH) # Allumer la LED + time.sleep(0.1) # Attendre 100 ms + GPIO.output(23, GPIO.LOW) # Éteindre la LED + time.sleep(0.1) # Attendre 100 ms + GPIO.output(23, GPIO.HIGH) # Turn on the LED + #4. Read reply from server + ser_sara.write(b'AT+URDFILE="server_response.txt"\r') + response_SARA_4 = read_complete_response(ser_sara) + if need_to_log: + print("Reply from server:") + print('

') + print(response_SARA_4) + print('

') #5. empty json ser_sara.write(b'AT+UDELFILE="sensordata.json"\r')