From 833ed458a7c485cf4e6f5cc5855a1d664c14bb9f Mon Sep 17 00:00:00 2001 From: PaulVua Date: Fri, 24 Jan 2025 10:43:34 +0100 Subject: [PATCH] update --- boot_hotspot.sh | 17 ++++++++++- html/admin.html | 20 ++++++------ html/launcher.php | 12 +++++++- loop/1_NPM/send_data.py | 68 +++++++++++++++++++++++++---------------- 4 files changed, 79 insertions(+), 38 deletions(-) diff --git a/boot_hotspot.sh b/boot_hotspot.sh index 0e2e0c7..2ecc460 100755 --- a/boot_hotspot.sh +++ b/boot_hotspot.sh @@ -5,12 +5,27 @@ OUTPUT_FILE="/var/www/nebuleair_pro_4g/wifi_list.csv" JSON_FILE="/var/www/nebuleair_pro_4g/config.json" + + echo "-------------------" echo "-------------------" echo "NebuleAir pro started at $(date)" -echo "getting SARA R4 serial number" +# Blink GPIO 23 and 24 five times +for i in {1..5}; do + # Turn GPIO 23 and 24 ON + gpioset gpiochip0 23=1 24=1 + echo "LEDs ON" + sleep 1 + + # Turn GPIO 23 and 24 OFF + gpioset gpiochip0 23=0 24=0 + echo "LEDs OFF" + sleep 1 +done + +echo "getting SARA R4 serial number" # Get the last 8 characters of the serial number and write to text file serial_number=$(cat /proc/cpuinfo | grep Serial | awk '{print substr($3, length($3) - 7)}') # Define the JSON file path diff --git a/html/admin.html b/html/admin.html index f00bb1b..715ac02 100755 --- a/html/admin.html +++ b/html/admin.html @@ -60,22 +60,22 @@
- +
- +
- +
- + @@ -83,7 +83,7 @@
- +
@@ -91,7 +91,7 @@
- +
@@ -153,7 +153,7 @@ window.onload = function() { }); //get BME check - const checkbox = document.getElementById("check_bme280s"); + const checkbox = document.getElementById("check_bme280"); checkbox.checked = data.i2c_BME; //loop activation @@ -196,10 +196,10 @@ window.onload = function() { } -function update_config(isChecked){ - console.log("Updated flex_loop:", isChecked); +function update_config(param, value){ + console.log("Updating ",param," : ", value); $.ajax({ - url: 'launcher.php?type=update_config', + url: 'launcher.php?type=update_config¶m='+param+'&value='+value, dataType: 'text', // Specify that you expect a JSON response method: 'GET', // Use GET or POST depending on your needs success: function(response) { diff --git a/html/launcher.php b/html/launcher.php index dd64f65..12d6837 100755 --- a/html/launcher.php +++ b/html/launcher.php @@ -3,9 +3,19 @@ $type=$_GET['type']; if ($type == "update_config") { echo "updating...."; + $param=$_GET['param']; + $value=$_GET['value']; $configFile = '../config.json'; + // Convert value to boolean, integer, or string + if ($value === "true") { + $value = true; // Convert "true" string to boolean true + } elseif ($value === "false") { + $value = false; // Convert "false" string to boolean false + } elseif (is_numeric($value)) { + $value = $value + 0; // Convert numeric strings to int or float + } $configData = json_decode(file_get_contents($configFile), true); - $configData['loop_activation'] = true; + $configData[$param] = $value; file_put_contents($configFile, json_encode($configData, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); echo "Config updated!"; } diff --git a/loop/1_NPM/send_data.py b/loop/1_NPM/send_data.py index 093d9c8..ed6f868 100755 --- a/loop/1_NPM/send_data.py +++ b/loop/1_NPM/send_data.py @@ -72,6 +72,7 @@ import re import os import traceback import sys +from threading import Thread import RPi.GPIO as GPIO from adafruit_bme280 import basic as adafruit_bme280 @@ -98,10 +99,32 @@ payload_json = { aircarto_profile_id = 0 uSpot_profile_id = 1 -# Set up GPIO mode (for Blue LED: network status) -GPIO.setwarnings(False) -GPIO.setmode(GPIO.BCM) # Use Broadcom pin numbering -GPIO.setup(23, GPIO.OUT) # Set GPIO23 as an output pin + +def blink_led(pin, blink_count, delay=1): + """ + Blink an LED on a specified GPIO pin. + + Args: + pin (int): GPIO pin number (BCM mode) to which the LED is connected. + blink_count (int): Number of times the LED should blink. + delay (float): Time in seconds for the LED to stay ON or OFF (default is 1 second). + """ + # GPIO setup + GPIO.setwarnings(False) + GPIO.setmode(GPIO.BCM) # Use BCM numbering + GPIO.setup(pin, GPIO.OUT) # Set the specified pin as an output + + try: + for _ in range(blink_count): + GPIO.output(pin, GPIO.HIGH) # Turn the LED on + #print(f"LED on GPIO {pin} is ON") + time.sleep(delay) # Wait for the specified delay + GPIO.output(pin, GPIO.LOW) # Turn the LED off + #print(f"LED on GPIO {pin} is OFF") + time.sleep(delay) # Wait for the specified delay + finally: + GPIO.cleanup(pin) # Clean up the specific pin to reset its state + print(f"GPIO {pin} cleaned up") #get data from config def load_config(config_file): @@ -147,6 +170,7 @@ config_file = '/var/www/nebuleair_pro_4g/config.json' # Load the configuration data config = load_config(config_file) +loop_activation = config.get('loop_activation', True) #activation de la loop principale baudrate = config.get('SaraR4_baudrate', 115200) #baudrate du sara R4 device_id = config.get('deviceID', '').upper() #device ID en maj need_to_log = config.get('loop_log', False) #inscription des logs @@ -162,6 +186,10 @@ selected_networkID = config.get('SARA_R4_neworkID', '') #update device id in the payload json payload_json["nebuleairid"] = device_id +if loop_activation == False: + print("Loop activation is False , skipping execution.") + sys.exit() + ser_sara = serial.Serial( port='/dev/ttyAMA2', baudrate=baudrate, #115200 ou 9600 @@ -469,14 +497,9 @@ try: 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 + # Clignotement LED rouge en cas d'erreur + led_thread = Thread(target=blink_led, args=(24, 5, 0.5)) + led_thread.start() else: # 2.Si la réponse contient une réponse HTTP valide @@ -492,13 +515,10 @@ try: print('ATTENTION: HTTP operation failed') update_json_key(config_file, "SARA_R4_network_status", "disconnected") print("*****") - 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 + print("Blink red LED") + # Run LED blinking in a separate thread + led_thread = Thread(target=blink_led, args=(24, 5, 0.5)) + led_thread.start() # Get error code print("Getting error code (11->Server connection error, 73->Secure socket connect error)") @@ -535,13 +555,9 @@ try: # 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 + print("Blink blue LED") + led_thread = Thread(target=blink_led, args=(23, 5, 0.5)) + led_thread.start() #4. Read reply from server print("Reply from server:") ser_sara.write(b'AT+URDFILE="server_response.txt"\r')