Compare commits
1 Commits
6c14800a02
...
6ead6853df
Author | SHA1 | Date |
---|---|---|
0xee | 6ead6853df |
10
mqtt-collect
10
mqtt-collect
|
@ -10,14 +10,6 @@ import datetime
|
|||
|
||||
def init_db(path, topics):
|
||||
db = sqlite3.connect(path)
|
||||
c = db.cursor()
|
||||
for topic in topics:
|
||||
table = topic.replace('/', '_')
|
||||
c.execute(
|
||||
f'CREATE TABLE IF NOT EXISTS {table} (timestamp timestamp, value real)'
|
||||
)
|
||||
|
||||
db.commit()
|
||||
return db
|
||||
|
||||
|
||||
|
@ -45,6 +37,8 @@ def main():
|
|||
table = msg.topic.replace("/", "_")
|
||||
ts = datetime.datetime.now()
|
||||
value = float(msg.payload)
|
||||
c.execute(f'CREATE TABLE IF NOT EXISTS {table} '
|
||||
'(timestamp timestamp, value real)')
|
||||
c.execute(f'INSERT INTO {table} VALUES (?, ?)', (ts, value))
|
||||
c.execute(f'SELECT * from {table}')
|
||||
db.commit()
|
||||
|
|
Loading…
Reference in New Issue