fix
This commit is contained in:
1 parent
05be334f8f
commit
72e71c94be
1 file changed
+10
-10
+10
-10
@@ -27,21 +27,21 @@ try:
|
||||
except ImportError:
|
||||
_PYMYSQL_AVAILABLE = False
|
||||
|
||||
import readSerial
|
||||
import serial
|
||||
from flask import Flask, jsonify, render_template, request
|
||||
|
||||
# ── Konfiguration aus Umgebungsvariablen ───────────────────────────────────────
|
||||
SERIAL_PORT = "/dev/ttyACM0"
|
||||
BAUD_RATE = 9600
|
||||
HOST = "0.0.0.0"
|
||||
PORT = "5000"
|
||||
PORT = 5000
|
||||
|
||||
DB_HOST = "10.233.1.244"
|
||||
DB_PORT = "3306"
|
||||
DB_PORT = 3306
|
||||
DB_USER = "worker"
|
||||
DB_PASSWORD = "bBHofurUJWKzPE8Z"
|
||||
DB_NAME = "HEIZUNG"
|
||||
DB_WRITE_INTERVAL = "60"
|
||||
DB_WRITE_INTERVAL = 60
|
||||
|
||||
HISTORY_LEN = 120 # letzte 120 Datenpunkte im Live-Chart
|
||||
|
||||
@@ -59,7 +59,7 @@ latest_data: dict = {}
|
||||
history: deque = deque(maxlen=HISTORY_LEN)
|
||||
data_lock = threading.Lock()
|
||||
serial_lock = threading.Lock()
|
||||
ser: readSerial.Serial | None = None
|
||||
ser: serial.Serial | None = None
|
||||
serial_connected = False
|
||||
|
||||
db_connected = False
|
||||
@@ -93,7 +93,7 @@ def _db_connect():
|
||||
cursorclass=pymysql.cursors.DictCursor,
|
||||
)
|
||||
return conn
|
||||
except pymysql.Error as e:
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
|
||||
@@ -192,10 +192,10 @@ def serial_reader():
|
||||
while True:
|
||||
if ser is None or not ser.is_open:
|
||||
try:
|
||||
ser = readSerial.Serial(SERIAL_PORT, BAUD_RATE, timeout=2)
|
||||
ser = serial.Serial(SERIAL_PORT, BAUD_RATE, timeout=2)
|
||||
serial_connected = True
|
||||
log.info("Serial verbunden: %s", SERIAL_PORT)
|
||||
except readSerial.SerialException as e:
|
||||
except serial.SerialException as e:
|
||||
serial_connected = False
|
||||
log.warning("Serial nicht verfügbar: %s – retry in 5s", e)
|
||||
time.sleep(5)
|
||||
@@ -204,7 +204,7 @@ def serial_reader():
|
||||
try:
|
||||
with serial_lock:
|
||||
raw = ser.readline().decode("utf-8", errors="replace").strip()
|
||||
except readSerial.SerialException as e:
|
||||
except serial.SerialException as e:
|
||||
log.warning("Serial-Lesefehler: %s", e)
|
||||
serial_connected = False
|
||||
ser = None
|
||||
@@ -245,7 +245,7 @@ def send_command(key: str, value) -> bool:
|
||||
return False
|
||||
ser.write(cmd.encode())
|
||||
return True
|
||||
except (readSerial.SerialException, AttributeError) as e:
|
||||
except (serial.SerialException, AttributeError) as e:
|
||||
log.error("Sendefehler: %s", e)
|
||||
return False
|
||||
|
||||
|
||||
Reference in new issue
Block a user