update
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -13,3 +13,4 @@ envea/data/*.json
|
||||
NPM/data/*.txt
|
||||
NPM/data/*.json
|
||||
*.lock
|
||||
sqlite/*.db
|
||||
27
sqlite/create_db.py
Normal file
27
sqlite/create_db.py
Normal file
@@ -0,0 +1,27 @@
|
||||
'''
|
||||
Script to create a sqlite database
|
||||
/usr/bin/python3 /var/www/nebuleair_pro_4g/sqlite/create_db.py
|
||||
|
||||
'''
|
||||
|
||||
import sqlite3
|
||||
|
||||
# Connect to (or create) the database
|
||||
conn = sqlite3.connect("/var/www/nebuleair_pro_4g/sqlite/sensors.db")
|
||||
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
|
||||
)
|
||||
""")
|
||||
|
||||
# Commit and close the connection
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
print("Database and table created successfully!")
|
||||
23
sqlite/read.py
Normal file
23
sqlite/read.py
Normal file
@@ -0,0 +1,23 @@
|
||||
'''
|
||||
Script to read data from a sqlite database
|
||||
/usr/bin/python3 /var/www/nebuleair_pro_4g/sqlite/read.py
|
||||
|
||||
'''
|
||||
|
||||
import sqlite3
|
||||
|
||||
# Connect to the SQLite database
|
||||
conn = sqlite3.connect("/var/www/nebuleair_pro_4g/sqlite/sensors.db")
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Retrieve the last 10 sensor readings
|
||||
cursor.execute("SELECT * FROM data ORDER BY timestamp DESC LIMIT 10")
|
||||
|
||||
rows = cursor.fetchall()
|
||||
|
||||
# Display the results
|
||||
for row in rows:
|
||||
print(row)
|
||||
|
||||
# Close the database connection
|
||||
conn.close()
|
||||
23
sqlite/write.py
Normal file
23
sqlite/write.py
Normal file
@@ -0,0 +1,23 @@
|
||||
'''
|
||||
Script to write data to a sqlite database
|
||||
/usr/bin/python3 /var/www/nebuleair_pro_4g/sqlite/write.py
|
||||
|
||||
'''
|
||||
|
||||
import sqlite3
|
||||
|
||||
# Connect to the SQLite database
|
||||
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
|
||||
|
||||
cursor.execute("INSERT INTO data (sensor, value) VALUES (?, ?)", (sensor_name, sensor_value))
|
||||
|
||||
# Commit and close the connection
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
print("Sensor data saved successfully!")
|
||||
Reference in New Issue
Block a user