From 3bb68775a76f975bd8fad550f1754ff43c336e3e Mon Sep 17 00:00:00 2001 From: Florian Glaser <58706771+Floskinner@users.noreply.github.com> Date: Thu, 29 Dec 2022 15:15:08 +0100 Subject: [PATCH] Update main (#11) * added new average calculation for the values * add everage * changed formular * updaed * fixed spelling and some other errors * added todo * Switched to poetry and venv * some linting * added pre-commit * reformatted with black * change code from index to new file * added the config menue / modal * added vscode * mocked spidev in dev mode * fixed some spelling ?? * Added blinking * updated blinking to invisable * added comment * deleted unused png * added legend bottom right * run pre-commit on all files * change to config instead of global variables * changed the AFR calculation * added error check * added pyinstaller * fixed exception if ENV not set * fixed know issue in package https://github.com/eventlet/eventlet/issues/702 * fixed exception if ENV not set * changed config and can change correction from web interface * added devcontainer * some code fixes (#7) * nachkomastellen default zu 2 (#8) * Set blinking and removed error warning (#10) * blinking is in settings * removed error checking Co-authored-by: Glaser --- .devcontainer/devcontainer.json | 30 +++++++++++++++++++++ starter.py | 11 ++++---- static/javascript/mySockets.js | 48 +++++++++++++-------------------- templates/index.html | 12 +++++++-- 4 files changed, 64 insertions(+), 37 deletions(-) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..643d5b1 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,30 @@ +{ + "image": "python:3.7.3", + "forwardPorts": [8080], + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "ms-python.python", + "njpwerner.autodocstring", + "naumovs.color-highlight", + "GitHub.copilot", + "donjayamanne.githistory", + "mhutchie.git-graph", + "oderwat.indent-rainbow", + "ms-python.vscode-pylance", + "Gruntfuggly.todo-tree", + "yzhang.markdown-all-in-one" + ] + } + }, + "features": { + "ghcr.io/devcontainers/features/git:1": {}, + "ghcr.io/devcontainers-contrib/features/poetry:1": {} + }, + "remoteEnv": { + "FLASK_ENV": "development" + }, + "postCreateCommand": "poetry config virtualenvs.in-project true && poetry install" + } \ No newline at end of file diff --git a/starter.py b/starter.py index 2115d74..4dfd252 100644 --- a/starter.py +++ b/starter.py @@ -98,6 +98,9 @@ def update_data(update_interval: float, messure_interval: float): socketio.emit("newValues", data, broadcast=True) + # Ohne warten wird emit nicht zuverlässig durchgeführt + socketio.sleep(0.01) + if IS_RECORDING: record_thread = Thread(target=write_to_db, args=(data,), daemon=True) record_thread.start() @@ -255,11 +258,6 @@ def recording(json: dict): IS_RECORDING = False write_to_systemd("stoppe Aufnahme") - -if __name__ == "__main__": - socketio.run(app, debug=True, port=8080, host="0.0.0.0") - - # Clean data from DB older than 6 Months if os.environ.get("FLASK_ENV") != "development": db_delete_time_string = (datetime.datetime.now() - datetime.timedelta(days=config.DB_DELETE_AELTER_ALS)).strftime( @@ -268,3 +266,6 @@ def recording(json: dict): query = "DELETE WHERE time < '" + db_delete_time_string + "'" write_to_systemd(f"Delete Data older than {db_delete_time_string}") result = client.query(query) + +if __name__ == "__main__": + socketio.run(app, debug=True, port=8080, host="0.0.0.0") diff --git a/static/javascript/mySockets.js b/static/javascript/mySockets.js index b44ed76..e4676ee 100644 --- a/static/javascript/mySockets.js +++ b/static/javascript/mySockets.js @@ -10,6 +10,8 @@ const MAX_ABOVE_RED = 1.20; const MAX_BELOW_ORANGE = 0.86; const MAX_BELOW_RED = 0.80; +let blinking = false; + socket.on('connect', function () { let browserTime = new Date().toISOString(); @@ -19,13 +21,26 @@ socket.on('connect', function () { }); +socket.on("connect_error", (error) => { + console.log("Error connecting to server: " + error); +}); + +socket.on("disconnect", (reason) => { + console.log("Disconnected from server: " + reason); + if (reason === "io server disconnect") { + // the disconnection was initiated by the server, you need to reconnect manually + socket.connect(); + } + // else the socket will automatically try to reconnect +}); + socket.on('disconnect', function () { socket.emit('disconnect', { data: 'User Disconnected' }); - }); + socket.on('newValues', function (values) { // console.log(JSON.stringify(values)); @@ -41,13 +56,10 @@ socket.on('newValues', function (values) { applyWarningColors($("#lamda1"), lamda1); applyWarningColors($("#lamda2"), lamda2); - checkErrors($('#bank1Label'), $('#lamda1'), $('#afr1'), voltage1); - checkErrors($('#bank2Label'), $('#lamda2'), $('#afr2'), voltage2); - - if (lamda1 >= MAX_ABOVE_RED || lamda1 <= MAX_BELOW_RED) { + if ((lamda1 >= MAX_ABOVE_RED || lamda1 <= MAX_BELOW_RED) && blinking) { applyRedBlinking($("#lamda1")); } - if (lamda2 >= MAX_ABOVE_RED || lamda2 <= MAX_BELOW_RED) { + if ((lamda2 >= MAX_ABOVE_RED || lamda2 <= MAX_BELOW_RED) && blinking) { applyRedBlinking($("#lamda2")); } }); @@ -62,30 +74,6 @@ function updateValuesOnScreen(lamda1, lamda2, afr1, afr2) { $('#afr2').html(afr2.toFixed(2) + " AFR"); } -function checkErrors(htmlBankLabel, htmlLamda, htmlAFR, voltage) { - label = htmlBankLabel.html(); - color = "#000000"; - lamda = htmlLamda.html(); - afr = htmlAFR.html(); - - if (Math.abs(voltage) <= 0.15) { - // label += " - Fehler"; - color= "#b30000"; - lamda = "Fehler"; - afr = "--------"; - } else if (Math.abs(voltage) <= 0.2) { - // label += " - Heizphase"; - color= "#b30000"; - lamda = "Heizphase"; - afr = "--------"; - } - - htmlBankLabel.html(label); - htmlBankLabel.css("color", color); - htmlLamda.html(lamda); - htmlAFR.html(afr); -} - function applyWarningColors(htmlElement, lamdaValue) { // Sind die Werte von Lamda entsprechend, wird der Text erst Orange und dann Rot if (lamdaValue >= MAX_ABOVE_ORANGE || lamdaValue <= MAX_BELOW_ORANGE) { diff --git a/templates/index.html b/templates/index.html index ae63f3f..c704d5e 100644 --- a/templates/index.html +++ b/templates/index.html @@ -77,13 +77,17 @@

Anzuzeigende Banken:


Anzuzeigende Nachkommastellen:

- +

- +
+

Blinken der Werte im roten Bereich:

+ +
+

Korrekturfaktor für Lamdaberechnung:

@@ -208,6 +212,10 @@

Korrekturfaktor für Lamdaberechnung:

$('#warning').toggle(); } + function toggle_blinking(checkbox) { + blinking = checkbox.checked; + } + \ No newline at end of file