29 lines
629 B
Python
Executable File
29 lines
629 B
Python
Executable File
'''
|
|
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
|
|
timestamp = "2025-10-11"
|
|
sensor_name = "NebuleAir-pro020"
|
|
PM1 = 25.3
|
|
PM25 = 18.3
|
|
PM10 = 9.3
|
|
|
|
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()
|
|
conn.close()
|
|
|
|
print("Sensor data saved successfully!")
|