Compare commits
1 Commits
6ead6853df
...
6c14800a02
Author | SHA1 | Date |
---|---|---|
0xee | 6c14800a02 |
10
mqtt-collect
10
mqtt-collect
|
@ -10,6 +10,14 @@ 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
|
||||
|
||||
|
||||
|
@ -37,8 +45,6 @@ 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