From 23d0d97c8e41bfad0c5f5500c25237ec3440f6e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Thu, 13 Jun 2024 19:50:20 +0200 Subject: vremenska postaja --- skripti/bme280_udp_logger.py | 28 ++++++++++++++++++++++++++++ "skripti/\305\276" | 36 ------------------------------------ 2 files changed, 28 insertions(+), 36 deletions(-) create mode 100755 skripti/bme280_udp_logger.py delete mode 100644 "skripti/\305\276" 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() diff --git "a/skripti/\305\276" "b/skripti/\305\276" deleted file mode 100644 index d18de36..0000000 --- "a/skripti/\305\276" +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash -# $1 naj bo icecast host kruljo.radiostudent.si -# $2 naj bo icecast http port 8000 -# $3 naj bo icecast endpoint /ehiq -# $4 naj bo končnica datotek .mp3 -# v CWD delam imenike in datoteke in sem glede tega kompatibilen z earhornom: -# Posnetek 2024/06/03/202136.mp3 se začne 2024-06-03T20:21:36 vedno UTC. -# Posnetkov ne splittam na uro. Posnetek se splitta le takrat, ko se zgodi napaka (stream crkne) -- takrat začnem pisati v novo datoteko -# požvižgam se na vsebino datotek. zame so to le bajti. v tem nisem earhornski. -host=$1 -port=$2 -endpoint=$3 -kon=$4 -mistakes=0 -set -xeuo pipefail -while : -do - filename=`date --utc +%Y/%m/%d/%H%m%S$kon` - mkdir -p `cut -d/ -f1-3 <<<$filename` - start=$SECONDS - set +e - nc $host $port <<<"GET $endpoint HTTP/1.0"$'\r\n\r' > $filename - koda=$? - set -e - echo TCP PREKINJEN! ZAČENJAM NOV POSNETEK! IZHODNA KODA nc je $koda, datum je `date` - if [ $(($SECONDS-$start)) -lt 300 ] - then - mistakes=$(($mistakes+1)) - if [ $mistakes -gt 3 ] - then - sleep $((2**($mistakes-3))) - fi - else - mistakes=0 - fi -done -- cgit v1.2.3