update
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -60,22 +60,22 @@
|
||||
<form>
|
||||
|
||||
<div class="form-check form-switch mb-2">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="flex_loop" onchange="update_config(this.checked)">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="flex_loop" onchange="update_config('loop_activation',this.checked)">
|
||||
<label class="form-check-label" for="flex_loop">Loop activation</label>
|
||||
</div>
|
||||
|
||||
<div class="form-check form-switch mb-2">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="flex_loop_log">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="flex_loop_log" onchange="update_config('loop_log', this.checked)">
|
||||
<label class="form-check-label" for="flex_loop_log">Loop Logs</label>
|
||||
</div>
|
||||
|
||||
<div class="form-check form-switch mb-2">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="flex_start_log">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="flex_start_log" onchange="update_config('boot_log', this.checked)">
|
||||
<label class="form-check-label" for="flex_start_log">Boot Logs</label>
|
||||
</div>
|
||||
|
||||
<div class="form-check mb-3">
|
||||
<input class="form-check-input" type="checkbox" value="" id="check_bme280s">
|
||||
<input class="form-check-input" type="checkbox" value="" id="check_bme280" onchange="update_config('i2c_BME', this.checked)">
|
||||
<label class="form-check-label" for="check_bme280">
|
||||
Sonde temp/hum (BME280)
|
||||
</label>
|
||||
@@ -83,7 +83,7 @@
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="device_name" class="form-label">Device Name</label>
|
||||
<input type="text" class="form-control" id="device_name">
|
||||
<input type="text" class="form-control" id="device_name" onchange="update_config('deviceName', this.value)">
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
@@ -91,7 +91,7 @@
|
||||
<input type="text" class="form-control" id="device_ID" disabled>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
<!--<button type="submit" class="btn btn-primary">Submit</button>-->
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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!";
|
||||
}
|
||||
|
||||
@@ -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('<span style="color: red;font-weight: bold;">ATTENTION: HTTP operation failed</span>')
|
||||
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('<span class="badge text-bg-success">HTTP operation successful.</span>')
|
||||
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')
|
||||
|
||||
Reference in New Issue
Block a user