update
This commit is contained in:
22
sqlite/create_db.py
Normal file → Executable file
22
sqlite/create_db.py
Normal file → Executable file
@@ -2,6 +2,8 @@
|
||||
Script to create a sqlite database
|
||||
/usr/bin/python3 /var/www/nebuleair_pro_4g/sqlite/create_db.py
|
||||
|
||||
|
||||
|
||||
'''
|
||||
|
||||
import sqlite3
|
||||
@@ -13,10 +15,22 @@ cursor = conn.cursor()
|
||||
# Create a table for storing sensor data
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS data (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
sensor TEXT,
|
||||
value REAL
|
||||
timestamp TEXT,
|
||||
sensor_id TEXT,
|
||||
PM1 REAL,
|
||||
PM25 REAL,
|
||||
PM10 REAL,
|
||||
temp REAL,
|
||||
hum REAL,
|
||||
press REAL,
|
||||
no2 REAL,
|
||||
h2s REAL,
|
||||
o3 REAL,
|
||||
PM_ch1 INTEGER,
|
||||
PM_ch2 INTEGER,
|
||||
PM_ch3 INTEGER,
|
||||
PM_ch4 INTEGER,
|
||||
PM_ch5 INTEGER
|
||||
)
|
||||
""")
|
||||
|
||||
|
||||
0
sqlite/read.py
Normal file → Executable file
0
sqlite/read.py
Normal file → Executable file
11
sqlite/write.py
Normal file → Executable file
11
sqlite/write.py
Normal file → Executable file
@@ -11,10 +11,15 @@ conn = sqlite3.connect("/var/www/nebuleair_pro_4g/sqlite/sensors.db")
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Insert a sample temperature reading
|
||||
sensor_name = "temperature"
|
||||
sensor_value = 25.3
|
||||
timestamp = "2025-10-11"
|
||||
sensor_name = "NebuleAir-pro020"
|
||||
PM1 = 25.3
|
||||
PM25 = 18.3
|
||||
PM10 = 9.3
|
||||
|
||||
cursor.execute("INSERT INTO data (sensor, value) VALUES (?, ?)", (sensor_name, sensor_value))
|
||||
cursor.execute('''
|
||||
INSERT INTO data (timestamp, sensor_id, PM1, PM25, PM10) VALUES (?,?,?,?,?)'''
|
||||
, (timestamp, sensor_name,PM1,PM25,PM10))
|
||||
|
||||
# Commit and close the connection
|
||||
conn.commit()
|
||||
|
||||
Reference in New Issue
Block a user