diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2024-06-13 19:50:20 +0200 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2024-06-13 19:50:20 +0200 |
commit | 23d0d97c8e41bfad0c5f5500c25237ec3440f6e9 (patch) | |
tree | 8e40951eadebac0f181e46d5de1230c835709091 /skripti/bme280_udp_logger.py | |
parent | skripti (diff) | |
download | r-23d0d97c8e41bfad0c5f5500c25237ec3440f6e9.tar r-23d0d97c8e41bfad0c5f5500c25237ec3440f6e9.tar.gz r-23d0d97c8e41bfad0c5f5500c25237ec3440f6e9.tar.bz2 r-23d0d97c8e41bfad0c5f5500c25237ec3440f6e9.tar.lz r-23d0d97c8e41bfad0c5f5500c25237ec3440f6e9.tar.xz r-23d0d97c8e41bfad0c5f5500c25237ec3440f6e9.tar.zst r-23d0d97c8e41bfad0c5f5500c25237ec3440f6e9.zip |
Diffstat (limited to '')
-rwxr-xr-x | skripti/bme280_udp_logger.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/skripti/bme280_udp_logger.py b/skripti/bme280_udp_logger.py new file mode 100755 index 0000000..1debe6c --- /dev/null +++ b/skripti/bme280_udp_logger.py @@ -0,0 +1,28 @@ +#!/usr/bin/python3 +import socket +import struct +import sqlite3 +sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM); +sock.bind(("::", 3232)) +conn = sqlite3.connect('db') +cur = conn.cursor() +cur.execute(''' +CREATE TABLE IF NOT EXISTS meritve ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + temp REAL NOT NULL, + humid REAL NOT NULL, + pres REAL NOT NULL, + datetime DATETIME DEFAULT CURRENT_TIMESTAMP +) +''') +conn.commit() +while True: + data, addr = sock.recvfrom(1024) + if len(data) != 16: + print(f"Received malformed from {addr}: {data}") + continue + info = struct.unpack("ffff", data) + print(f"Received from {addr}: {info}") + cur = conn.cursor() + cur.execute('INSERT INTO meritve (temp, humid, pres) VALUES (?, ?, ?)', (info[1], info[2], info[3])) + conn.commit() |