From 4653fe44e34fa0f59e384fe34608114fa71ce762 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 28 Mar 2025 15:59:54 +0100 Subject: [PATCH] update --- README.md | 2 +- boot_hotspot.sh | 21 +++--- html/database.html | 28 +++++--- html/matrix_led.html | 144 ++++++++++++++++++++++++++++++++++++++ html/sidebar.html | 6 ++ loop/SARA_send_data_v2.py | 2 +- matrix/test_forms.cc | 3 + sensirion/SFA30_read.py | 85 ++++++++++++++++------ 8 files changed, 247 insertions(+), 44 deletions(-) create mode 100644 html/matrix_led.html diff --git a/README.md b/README.md index eeb1d44..76a88a5 100755 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Version Pro du ModuleAir avec CM4, SaraR4 et ecran Matrix LED p2 64x64. ## General ``` sudo apt update -sudo apt install git gh apache2 php php-sqlite3 python3 python3-pip jq g++ autossh i2c-tools python3-smbus -y +sudo apt install git gh apache2 sqlite3 php php-sqlite3 python3 python3-pip jq g++ autossh i2c-tools python3-smbus -y sudo pip3 install pyserial requests sensirion-shdlc-sfa3x RPi.GPIO adafruit-circuitpython-bme280 crcmod psutil --break-system-packages sudo git clone http://gitea.aircarto.fr/PaulVua/moduleair_pro_4g.git /var/www/moduleair_pro_4g sudo mkdir /var/www/moduleair_pro_4g/logs diff --git a/boot_hotspot.sh b/boot_hotspot.sh index a01fb42..5f354a3 100755 --- a/boot_hotspot.sh +++ b/boot_hotspot.sh @@ -6,7 +6,6 @@ # @reboot /var/www/moduleair_pro_4g/boot_hotspot.sh >> /var/www/moduleair_pro_4g/logs/app.log 2>&1 OUTPUT_FILE="/var/www/moduleair_pro_4g/wifi_list.csv" -JSON_FILE="/var/www/moduleair_pro_4g/config.json" echo "-------------------" echo "-------------------" @@ -14,16 +13,18 @@ echo "-------------------" echo "NebuleAir pro started at $(date)" -echo "getting SARA R4 serial number" +echo "getting RPI 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 -# Use jq to update the "deviceID" in the JSON file -jq --arg serial_number "$serial_number" '.deviceID = $serial_number' "$JSON_FILE" > temp.json && mv temp.json "$JSON_FILE" +# update Sqlite database +echo "Updating SQLite database with device ID: $serial_number" +sqlite3 /var/www/moduleair_pro_4g/sqlite/sensors.db "UPDATE config_table SET value='$serial_number' WHERE key='deviceID';" echo "id: $serial_number" + #get the SSH port for tunneling -SSH_TUNNEL_PORT=$(jq -r '.sshTunnel_port' "$JSON_FILE") +SSH_TUNNEL_PORT=$(sqlite3 /var/www/moduleair_pro_4g/sqlite/sensors.db "SELECT value FROM config_table WHERE key='sshTunnel_port'") #need to wait for the network manager to be ready sleep 20 @@ -39,10 +40,10 @@ if [ "$STATE" == "30 (disconnected)" ]; then nmcli -f SSID,SIGNAL,SECURITY device wifi list | awk 'BEGIN { OFS=","; print "SSID,SIGNAL,SECURITY" } NR>1 { print $1,$2,$3 }' > "$OUTPUT_FILE" # Start the hotspot echo "Starting hotspot..." - sudo nmcli device wifi hotspot ifname wlan0 ssid nebuleair_pro password nebuleaircfg + sudo nmcli device wifi hotspot ifname wlan0 ssid moduleair_pro password moduleaircfg # Update JSON to reflect hotspot mode - jq --arg status "hotspot" '.WIFI_status = $status' "$JSON_FILE" > temp.json && mv temp.json "$JSON_FILE" + sqlite3 /var/www/moduleair_pro_4g/sqlite/sensors.db "UPDATE config_table SET value='hotspot' WHERE key='WIFI_status'" else @@ -50,10 +51,8 @@ else CONN_SSID=$(nmcli -g GENERAL.CONNECTION device show wlan0) echo "Connection: $CONN_SSID" - #update config JSON file - jq --arg status "connected" '.WIFI_status = $status' "$JSON_FILE" > temp.json && mv temp.json "$JSON_FILE" - - sudo chmod 777 "$JSON_FILE" + # Update SQLite to reflect hotspot mode + sqlite3 /var/www/nebuleair_pro_4g/sqlite/sensors.db "UPDATE config_table SET value='connected' WHERE key='WIFI_status'" # Lancer le tunnel SSH #echo "Démarrage du tunnel SSH sur le port $SSH_TUNNEL_PORT..." diff --git a/html/database.html b/html/database.html index 9a8c24f..05dd6ce 100755 --- a/html/database.html +++ b/html/database.html @@ -54,7 +54,7 @@
-
+
Consulter la base de donnée
@@ -67,19 +67,20 @@
- - + + - - - - + + + + +
-
+
Télécharger les données
@@ -275,6 +276,11 @@ function get_data_sqlite(table, limit, download , startDate = "", endDate = "") Timestamp CO2 `; + }else if (table === "data_sensirionSFA30") { + tableHTML += ` + Timestamp + CH2O + `; } tableHTML += ``; @@ -331,8 +337,14 @@ function get_data_sqlite(table, limit, download , startDate = "", endDate = "") ${columns[0]} ${columns[1]} `; + }else if (table === "data_sensirionSFA30") { + tableHTML += ` + ${columns[0]} + ${columns[1]} + `; } + tableHTML += ""; }); diff --git a/html/matrix_led.html b/html/matrix_led.html new file mode 100644 index 0000000..4862d24 --- /dev/null +++ b/html/matrix_led.html @@ -0,0 +1,144 @@ + + + + + + ModuleAir + + + + + + + + + + +
+
+
NebuleAir
+ +
+ +
+ +
+
+ + +
+

Ecran LED

+

Votre capteur est équipé d'un écran LED.

+ +
+ + + +
+ +
+
+
+ + + + + + + + + + + + diff --git a/html/sidebar.html b/html/sidebar.html index d65d396..80fc041 100755 --- a/html/sidebar.html +++ b/html/sidebar.html @@ -13,6 +13,12 @@ Capteurs + + + + + Matrix LED + diff --git a/loop/SARA_send_data_v2.py b/loop/SARA_send_data_v2.py index 06515bc..57d826e 100755 --- a/loop/SARA_send_data_v2.py +++ b/loop/SARA_send_data_v2.py @@ -523,7 +523,7 @@ try: rows = cursor.fetchall() # Exclude the timestamp column (assuming first column is timestamp) - data_values = [row[1:] for row in rows] # Exclude timestamp + data_values = [row[2:] for row in rows] # Exclude timestamp # Compute column-wise average num_columns = len(data_values[0]) averages = [round(sum(col) / len(col),1) for col in zip(*data_values)] diff --git a/matrix/test_forms.cc b/matrix/test_forms.cc index f9d0317..6ee7576 100755 --- a/matrix/test_forms.cc +++ b/matrix/test_forms.cc @@ -12,6 +12,9 @@ sudo /var/www/moduleair_pro_4g/matrix/test_forms --led-no-hardware-pulse Pour compiler: g++ -Iinclude -Llib test_forms.cc -o test_forms -lrgbmatrix + +Pour le lancer: +sudo /var/www/moduleair_pro_4g/matrix/test_forms */ #include "led-matrix.h" diff --git a/sensirion/SFA30_read.py b/sensirion/SFA30_read.py index 5d965b9..857ac84 100755 --- a/sensirion/SFA30_read.py +++ b/sensirion/SFA30_read.py @@ -1,38 +1,77 @@ ''' + ____ _____ _ _____ ___ + / ___|| ___/ \ |___ / / _ \ + \___ \| |_ / _ \ |_ \| | | | + ___) | _/ ___ \ ___) | |_| | + |____/|_|/_/ \_\____/ \___/ + Read data from sensor (only once) /usr/bin/python3 /var/www/moduleair_pro_4g/sensirion/SFA30_read.py ''' import time import json +import sqlite3 from sensirion_shdlc_driver import ShdlcSerialPort, ShdlcConnection from sensirion_shdlc_sfa3x import Sfa3xShdlcDevice -# Connect to the device with default settings: -# - baudrate: 115200 -# - slave address: 0 -with ShdlcSerialPort(port='/dev/ttyAMA5', baudrate=115200) as port: - device = Sfa3xShdlcDevice(ShdlcConnection(port), slave_address=0) - device.device_reset() +# Connect to the SQLite database +DB_PATH = "/var/www/moduleair_pro_4g/sqlite/sensors.db" +SERIAL_PORT = '/dev/ttyAMA5' - # Print device information - #print("Device Marking: {}".format(device.get_device_marking())) - # Start measurement - device.start_measurement() - #print("Measurement started... ") - - time.sleep(5.) - hcho, humidity, temperature = device.read_measured_values() +try: + # Connect to the SQLite database + #print("Connecting to database...") + conn = sqlite3.connect(DB_PATH) + cursor = conn.cursor() + # Connect to the device with default settings: + # - baudrate: 115200 + # - slave address: 0 + #print(f"Connecting to Sensirion SFA3X on {SERIAL_PORT}...") + with ShdlcSerialPort(port=SERIAL_PORT, baudrate=115200) as port: + device = Sfa3xShdlcDevice(ShdlcConnection(port), slave_address=0) + device.device_reset() - # Prepare data as a JSON object - data = { - "formaldehyde_ppb": hcho.ppb, - "humidity_percent": humidity.percent_rh, - "temperature_celsius": temperature.degrees_celsius, - } + # Print device information + #print("Device Marking: {}".format(device.get_device_marking())) + + # Start measurement + device.start_measurement() + #print("Measurement started... ") - # Convert the dictionary to a JSON string - json_output = json.dumps(data, indent=4) - print(json_output) + time.sleep(5.) + hcho, humidity, temperature = device.read_measured_values() + + # Prepare data as a JSON object + data = { + "formaldehyde_ppb": hcho.ppb, + "humidity_percent": humidity.percent_rh, + "temperature_celsius": temperature.degrees_celsius, + } + + # Convert the dictionary to a JSON string + json_output = json.dumps(data, indent=4) + #print(json_output) + + #print("Getting RTC time...") + cursor.execute("SELECT * FROM timestamp_table LIMIT 1") + row = cursor.fetchone() + rtc_time_str = row[1] if row else time.strftime("%Y-%m-%d %H:%M:%S") + + # Save to database + #print(f"Saving readings to database: HCHO={hcho.ppb} ppb, Time={rtc_time_str}") + cursor.execute(''' + INSERT INTO data_sensirionSFA30 (timestamp, CH2O) VALUES (?, ?) + ''', (rtc_time_str, hcho.ppb)) + conn.commit() + + +except Exception as e: + print(f"Error: {e}") +finally: + # Close database connection if it exists + if 'conn' in locals(): + conn.close() + #print("Database connection closed") \ No newline at end of file