diff --git a/NPM/get_data_v2.py b/NPM/get_data_v2.py index fa9797c..ab7321e 100644 --- a/NPM/get_data_v2.py +++ b/NPM/get_data_v2.py @@ -1,11 +1,12 @@ ''' - _ _ ____ __ __ - | \ | | _ \| \/ | - | \| | |_) | |\/| | - | |\ | __/| | | | - |_| \_|_| |_| |_| + ____ _____ _ _ ____ ___ ____ ____ + / ___|| ____| \ | / ___| / _ \| _ \/ ___| + \___ \| _| | \| \___ \| | | | |_) \___ \ + ___) | |___| |\ |___) | |_| | _ < ___) | + |____/|_____|_| \_|____/ \___/|_| \_\____/ + -Script to get NPM values +Script to get SENSORS values And store them inside sqlite database Uses RTC module for timing /usr/bin/python3 /var/www/nebuleair_pro_4g/NPM/get_data_v2.py @@ -73,6 +74,7 @@ ser.write(b'\x81\x12\x6D') #data60s while True: try: + #print("Start get_data_v2.py script") byte_data = ser.readline() #print(byte_data) stateByte = int.from_bytes(byte_data[2:3], byteorder='big') @@ -86,8 +88,6 @@ while True: #print(f"PM10: {PM10}") #create JSON data = { - 'capteurID': 'nebuleairpro1', - 'sondeID':'USB2', 'PM1': PM1, 'PM25': PM25, 'PM10': PM10, @@ -101,7 +101,7 @@ while True: 'laserError' : Statebits[7] } json_data = json.dumps(data) - print(json_data) + #print(json_data) #GET RTC TIME # Read RTC time @@ -111,7 +111,7 @@ while True: if rtc_time: rtc_time_str = rtc_time.strftime('%Y-%m-%d %H:%M:%S') - print(rtc_time_str) + #print(rtc_time_str) else: print("Error! RTC module not connected") rtc_time_str = "1970-01-01 00:00:00" # Default fallback time @@ -125,7 +125,7 @@ while True: # Commit and close the connection conn.commit() - print("Sensor data saved successfully!") + #print("Sensor data saved successfully!") break # Exit loop after successful execution except KeyboardInterrupt: diff --git a/html/index.html b/html/index.html index fe1aa80..581b30d 100755 --- a/html/index.html +++ b/html/index.html @@ -308,9 +308,36 @@ window.onload = function() { data: { labels: labels, datasets: [ - { label: "PM1", data: PM1, borderColor: "red", fill: false }, - { label: "PM2.5", data: PM25, borderColor: "blue", fill: false }, - { label: "PM10", data: PM10, borderColor: "green", fill: false } + { + label: "PM1", + data: PM1, + borderColor: "rgba(0, 51, 153, 1)", + backgroundColor: "rgba(0, 51, 153, 0.2)", // Very light blue background + fill: true, + tension: 0.4, // Smooth curves + pointRadius: 2, // Larger points + pointHoverRadius: 6 // Bigger hover points + }, + { + label: "PM2.5", + data: PM25, + borderColor: "rgba(30, 144, 255, 1)", + backgroundColor: "rgba(30, 144, 255, 0.2)", // Very light medium blue background + fill: true, + tension: 0.4, + pointRadius: 2, + pointHoverRadius: 6 + }, + { + label: "PM10", + data: PM10, + borderColor: "rgba(135, 206, 250, 1)", + backgroundColor: "rgba(135, 206, 250, 0.2)", // Very light blue background + fill: true, + tension: 0.4, + pointRadius: 2, + pointHoverRadius: 6 + } ] }, options: { @@ -325,11 +352,17 @@ window.onload = function() { x: { title: { display: true, - text: 'Time' + text: 'Time (UTC)', + font: { + size: 16, + family: 'Arial, sans-serif' + }, + color: '#4A4A4A' }, ticks: { autoSkip: true, maxTicksLimit: 5, + color: '#4A4A4A', callback: function(value, index) { // Access the correct label from the `labels` array const label = labels[index]; // Use the original `labels` array @@ -338,6 +371,9 @@ window.onload = function() { } return value; // Fallback for invalid labels } + }, + grid: { + display: false // Remove gridlines for a cleaner look } @@ -345,7 +381,12 @@ window.onload = function() { y: { title: { display: true, - text: 'Values (µg/m³)' + text: 'Values (µg/m³)', + font: { + size: 16, + family: 'Arial, sans-serif' + }, + color: '#4A4A4A' } } } diff --git a/html/launcher.php b/html/launcher.php index 2352be6..b5b7a04 100755 --- a/html/launcher.php +++ b/html/launcher.php @@ -16,8 +16,10 @@ if ($type == "get_npm_sqlite_data") { // Fetch the last 30 records $stmt = $db->query("SELECT timestamp, PM1, PM25, PM10 FROM data ORDER BY timestamp DESC LIMIT 30"); $data = $stmt->fetchAll(PDO::FETCH_ASSOC); + $reversedData = array_reverse($data); // Reverse the order + - echo json_encode($data); + echo json_encode($reversedData); } catch (PDOException $e) { echo json_encode(["error" => $e->getMessage()]); } @@ -94,50 +96,50 @@ if ($type == "clear_loopLogs") { if ($type == "database_size") { -// Path to the SQLite database file -$databasePath = '/var/www/nebuleair_pro_4g/sqlite/sensors.db'; + // Path to the SQLite database file + $databasePath = '/var/www/nebuleair_pro_4g/sqlite/sensors.db'; -// Check if the file exists -if (file_exists($databasePath)) { - try { - // Connect to the SQLite database - $db = new PDO("sqlite:$databasePath"); + // Check if the file exists + if (file_exists($databasePath)) { + try { + // Connect to the SQLite database + $db = new PDO("sqlite:$databasePath"); - // Get the file size in bytes - $fileSizeBytes = filesize($databasePath); + // Get the file size in bytes + $fileSizeBytes = filesize($databasePath); - // Convert the file size to human-readable formats - $fileSizeKilobytes = $fileSizeBytes / 1024; // KB - $fileSizeMegabytes = $fileSizeKilobytes / 1024; // MB + // Convert the file size to human-readable formats + $fileSizeKilobytes = $fileSizeBytes / 1024; // KB + $fileSizeMegabytes = $fileSizeKilobytes / 1024; // MB - // Query the number of records in the `data` table - $query = "SELECT COUNT(*) AS total_records FROM data"; - $result = $db->query($query); - $recordCount = $result ? $result->fetch(PDO::FETCH_ASSOC)['total_records'] : 0; + // Query the number of records in the `data` table + $query = "SELECT COUNT(*) AS total_records FROM data"; + $result = $db->query($query); + $recordCount = $result ? $result->fetch(PDO::FETCH_ASSOC)['total_records'] : 0; - // Prepare the JSON response - $data = [ - 'path' => $databasePath, - 'size_bytes' => $fileSizeBytes, - 'size_kilobytes' => round($fileSizeKilobytes, 2), - 'size_megabytes' => round($fileSizeMegabytes, 2), - 'data_table_records' => $recordCount - ]; + // Prepare the JSON response + $data = [ + 'path' => $databasePath, + 'size_bytes' => $fileSizeBytes, + 'size_kilobytes' => round($fileSizeKilobytes, 2), + 'size_megabytes' => round($fileSizeMegabytes, 2), + 'data_table_records' => $recordCount + ]; - // Output the JSON response - echo json_encode($data, JSON_PRETTY_PRINT); - } catch (PDOException $e) { - // Handle database connection errors + // Output the JSON response + echo json_encode($data, JSON_PRETTY_PRINT); + } catch (PDOException $e) { + // Handle database connection errors + echo json_encode([ + 'error' => 'Database query failed: ' . $e->getMessage() + ]); + } + } else { + // Handle error if the file doesn't exist echo json_encode([ - 'error' => 'Database query failed: ' . $e->getMessage() + 'error' => 'Database file not found', + 'path' => $databasePath ]); - } -} else { - // Handle error if the file doesn't exist - echo json_encode([ - 'error' => 'Database file not found', - 'path' => $databasePath - ]); } diff --git a/html/logs.html b/html/logs.html index 454dd14..d73fdcf 100755 --- a/html/logs.html +++ b/html/logs.html @@ -56,7 +56,7 @@
') + print(response2) + print("
") + match = re.search(r'\+CSQ:\s*(\d+),', response2) + if match: + signal_quality = int(match.group(1)) + payload_csv[12]=signal_quality + time.sleep(0.1) + + # On vérifie si le signal n'est pas à 99 pour déconnexion + # si c'est le cas on essaie de se reconnecter + if signal_quality == 99: + print('⚠️ATTENTION: Signal Quality indicates no signal (99)⚠️') + print("TRY TO RECONNECT:") + command = f'AT+COPS=1,2,"{selected_networkID}"\r' + ser_sara.write(command.encode('utf-8')) + responseReconnect = read_complete_response(ser_sara, timeout=20, end_of_response_timeout=20) + print('') + print(responseReconnect) + print("
") + + print('🛑STOP LOOP🛑') + print("