forked from Pyplate/rpi_temp_logger
-
Notifications
You must be signed in to change notification settings - Fork 1
/
devmonitor.py
executable file
·38 lines (34 loc) · 1.02 KB
/
devmonitor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
import sqlite3
import glob
import random
import commands
# global variables
dbname='/var/www/tmplog/tempdb2.db'
# store the temperature in the database
def log_temperature(iD, temp):
conn=sqlite3.connect(dbname)
curs=conn.cursor()
insertDeviceQuery = "INSERT OR IGNORE INTO sensor (sensor_id) VALUES('"+str(iD)+"');"
curs.execute(insertDeviceQuery);
insertDataQuery = "INSERT INTO sensor_data (sensor_id,value) VALUES('"+str(iD)+"','"+str(temp)+"');"
curs.execute(insertDataQuery);
# commit the changes
conn.commit()
conn.close()
# main function
# This is where the program starts
def main():
devicelist = ['device1','device2',"device321"]
if devicelist=='':
# no devices
return None
else:
for device in devicelist:
temperature = random.uniform(0.0,45.0)
deviceid = device
print temperature
print deviceid
log_temperature(deviceid, temperature)
if __name__=="__main__":
main()