From a3cd3217ab9a21e14839c484d048dadc1fec9adc Mon Sep 17 00:00:00 2001 From: Magnus Persson Date: Sun, 1 May 2022 18:07:16 +0200 Subject: [PATCH] #63 tilt validation --- html/config.htm | 117 +++++++++++++++++++---------------- html/config.min.htm | 2 +- html/index.htm | 4 +- html/index.min.htm | 2 +- src/config.cpp | 3 + src/config.hpp | 6 ++ src/main.cpp | 5 ++ src/resources.hpp | 1 + src/webserver.cpp | 12 ++++ src_docs/source/api.rst | 6 +- src_docs/source/releases.rst | 2 + test/adv.json | 1 + test/config.json | 22 +++++++ 13 files changed, 126 insertions(+), 57 deletions(-) diff --git a/html/config.htm b/html/config.htm index 03830d6..c5aaa8f 100644 --- a/html/config.htm +++ b/html/config.htm @@ -105,7 +105,7 @@
- +
@@ -113,7 +113,7 @@
- Temperature Format: + Temperature Format
@@ -128,7 +128,7 @@
- +
@@ -145,7 +145,7 @@
- +
@@ -174,7 +174,7 @@
- +
@@ -184,7 +184,7 @@
- +
@@ -194,21 +194,21 @@
- +
- +
- +
@@ -246,28 +246,28 @@
- +
- +
- +
- +
@@ -276,28 +276,28 @@
- +
- +
- +
- +
@@ -335,7 +335,7 @@
- Gravity Format: +
@@ -357,7 +357,7 @@
-
+
@@ -388,7 +388,7 @@
- +
@@ -396,7 +396,7 @@
- +
@@ -429,7 +429,7 @@
- +
@@ -459,38 +459,57 @@
+
+
+
+ + +
+
+
+
-
+
(10-100) - default 50
- -
+ +
(50-1000) - default 500
- -
+ +
(1 - 10) - default 1.6 SG
+
+
+
+ + +
+
+
+
+
- -
+ +
(9 - 12) - default 9 bits
@@ -499,16 +518,16 @@
- -
+ +
(1 - 60) - default 20 s
- -
+ +
(10 - 240) - default 120 s
@@ -518,39 +537,39 @@
-
+
(0 - 5) - default 0
- -
+ +
(0 - 5) - default 0
- -
+ +
(0 - 5) - default 0
- -
+ +
(0 - 5) - default 0
- -
+ +
(0 - 5) - default 0
@@ -563,15 +582,6 @@
-
-
-
- - -
-
-
-
@@ -760,6 +770,7 @@ $("#int-influx").prop("disabled", b); $("#int-mqtt").prop("disabled", b); $("#tempsensor-resolution").prop("disabled", b); + $("#ignore-low-angles").prop("disabled", b); } // Get the advanced values from the API @@ -778,6 +789,7 @@ $("#wifi-portal-timeout").val(cfg["wifi-portal-timeout"]); $("#wifi-connect-timeout").val(cfg["wifi-connect-timeout"]); $("#tempsensor-resolution").val(cfg["tempsensor-resolution"]); + $("#ignore-low-angles").prop( "checked", cfg["ignore-low-angles"] ); $("#int-http1").val(cfg["int-http1"]); $("#int-http2").val(cfg["int-http2"]); $("#int-http3").val(cfg["int-http3"]); @@ -785,7 +797,7 @@ $("#int-mqtt").val(cfg["int-mqtt"]); if ( cfg["gyro-read-count"] != 50 || cfg["gyro-moving-threashold"] != 500 || cfg["formula-max-deviation"] != 1.6 || cfg["wifi-portal-timeout"] != 120 || cfg["wifi-connect-timeout"] != 20 || cfg["tempsensor-resolution"] != 9 || - cfg["int-http1"] != 0 || cfg["int-http2"] != 0 || cfg["int-http3"] != 0 || cfg["int-influx"] != 0 || cfg["int-mqtt"] != 0 ) { + cfg["int-http1"] != 0 || cfg["int-http2"] != 0 || cfg["int-http3"] != 0 || cfg["int-influx"] != 0 || cfg["int-mqtt"] != 0 || cfg["ignore-low-angles"] != false ) { $("#adv-config").attr("checked", false ); } }) @@ -852,6 +864,7 @@ $("#battery").text(cfg["battery"] + " V"); $("#angle").text(cfg["angle"]); $("#runtime-average").val(cfg["runtime-average"]); + $("#water-angle").text( "(Water angle: " + cfg["formula-calculation-data"]["a1"] + ") - default off"); //$("#gravity").text(cfg["gravity"] + " SG"); }) .fail(function () { diff --git a/html/config.min.htm b/html/config.min.htm index e30c101..e73401a 100644 --- a/html/config.min.htm +++ b/html/config.min.htm @@ -1 +1 @@ -Beer Gravity Monitor

Temperature Format:


Gravity Format:

(10-100) - default 50
(50-1000) - default 500
(1 - 10) - default 1.6 SG

(9 - 12) - default 9 bits

(1 - 60) - default 20 s
(10 - 240) - default 120 s

(0 - 5) - default 0
(0 - 5) - default 0
(0 - 5) - default 0
(0 - 5) - default 0
(0 - 5) - default 0
(C) Copyright 2021-22 Magnus Persson
\ No newline at end of file +Beer Gravity Monitor

Temperature Format


(10-100) - default 50
(50-1000) - default 500
(1 - 10) - default 1.6 SG

(9 - 12) - default 9 bits

(1 - 60) - default 20 s
(10 - 240) - default 120 s

(0 - 5) - default 0
(0 - 5) - default 0
(0 - 5) - default 0
(0 - 5) - default 0
(0 - 5) - default 0
(C) Copyright 2021-22 Magnus Persson
\ No newline at end of file diff --git a/html/index.htm b/html/index.htm index f9435cf..88a26f2 100644 --- a/html/index.htm +++ b/html/index.htm @@ -253,8 +253,8 @@ var s = JSON.stringify(debug, null, 2); $("#supportContent").text( s ); $('#spinner').hide(); - navigator.clipboard.writeText(s); - alert("Support information copied to clipboard"); + //navigator.clipboard.writeText(s); + //alert("Support information copied to clipboard"); } }); }); diff --git a/html/index.min.htm b/html/index.min.htm index 0e9bafe..910b40d 100644 --- a/html/index.min.htm +++ b/html/index.min.htm @@ -1 +1 @@ -Beer Gravity Monitor

Current version:
Loading...
Host name:
Loading...
Device ID:
Loading...
Platform:
Loading...
SSID:
Loading...

Gravity:
Loading...
Temperature:
Loading...
Angle/Tilt:
Loading...
Battery:
Loading...
Average runtime:
Loading...
(C) Copyright 2021-22 Magnus Persson
\ No newline at end of file +Beer Gravity Monitor

Current version:
Loading...
Host name:
Loading...
Device ID:
Loading...
Platform:
Loading...
SSID:
Loading...

Gravity:
Loading...
Temperature:
Loading...
Angle/Tilt:
Loading...
Battery:
Loading...
Average runtime:
Loading...
(C) Copyright 2021-22 Magnus Persson
\ No newline at end of file diff --git a/src/config.cpp b/src/config.cpp index 70d2dc9..18b12d9 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -391,6 +391,7 @@ bool AdvancedConfig::saveFile() { doc[PARAM_HW_PUSH_INTERVAL_INFLUX] = this->getPushIntervalInflux(); doc[PARAM_HW_PUSH_INTERVAL_MQTT] = this->getPushIntervalMqtt(); doc[PARAM_HW_TEMPSENSOR_RESOLUTION] = this->getTempSensorResolution(); + doc[PARAM_HW_IGNORE_LOW_ANGLES] = this->isIgnoreLowAnges(); #if LOG_LEVEL == 6 && !defined(DISABLE_LOGGING) serializeJson(doc, Serial); @@ -479,6 +480,8 @@ bool AdvancedConfig::loadFile() { this->setPushIntervalMqtt(doc[PARAM_HW_PUSH_INTERVAL_MQTT].as()); if (!doc[PARAM_HW_TEMPSENSOR_RESOLUTION].isNull()) this->setTempSensorResolution(doc[PARAM_HW_TEMPSENSOR_RESOLUTION].as()); + if (!doc[PARAM_HW_IGNORE_LOW_ANGLES].isNull()) + setIgnoreLowAnges(doc[PARAM_HW_IGNORE_LOW_ANGLES].as()); Log.notice(F("CFG : Configuration file " CFG_HW_FILENAME " loaded." CR)); return true; diff --git a/src/config.hpp b/src/config.hpp index 68f1631..9dcd885 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -70,6 +70,7 @@ class AdvancedConfig { int _pushIntervalHttp3 = 0; int _pushIntervalInflux = 0; int _pushIntervalMqtt = 0; + bool _IgnoreLowAnges = false; public: int getWifiPortalTimeout() { return _wifiPortalTimeout; } @@ -128,6 +129,11 @@ class AdvancedConfig { : true; } + const bool isIgnoreLowAnges() { return _IgnoreLowAnges; } + void setIgnoreLowAnges(bool b) { + _IgnoreLowAnges = b; + } + bool saveFile(); bool loadFile(); }; diff --git a/src/main.cpp b/src/main.cpp index 3f8e6b1..3f7b679 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -275,6 +275,11 @@ bool loopReadGravity() { bool pushExpired = (abs((int32_t)(millis() - pushMillis)) > (myConfig.getSleepInterval() * 1000)); + if (myAdvancedConfig.isIgnoreLowAnges() && (angle < myConfig.getFormulaData().a[0]) ) { + Log.warning(F("Main: Angle is lower than water, so we regard this as faulty and dont send any data." CR)); + pushExpired = false; + } + if (pushExpired || runMode == RunMode::gravityMode) { pushMillis = millis(); LOG_PERF_START("loop-push"); diff --git a/src/resources.hpp b/src/resources.hpp index fed0c41..7138933 100644 --- a/src/resources.hpp +++ b/src/resources.hpp @@ -90,6 +90,7 @@ SOFTWARE. #define PARAM_HW_PUSH_INTERVAL_HTTP3 "int-http3" #define PARAM_HW_PUSH_INTERVAL_INFLUX "int-influx" #define PARAM_HW_PUSH_INTERVAL_MQTT "int-mqtt" +#define PARAM_HW_IGNORE_LOW_ANGLES "ignore-low-angles" #define PARAM_FORMAT_HTTP1 "http-1" #define PARAM_FORMAT_HTTP2 "http-2" #define PARAM_FORMAT_HTTP3 "http-3" diff --git a/src/webserver.cpp b/src/webserver.cpp index ee2f474..e9e5c2b 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -576,6 +576,9 @@ void WebServerHandler::webHandleConfigGravity() { myConfig.setGravityTempAdj( _server->arg(PARAM_GRAVITY_TEMP_ADJ).equalsIgnoreCase("on") ? true : false); + else + myConfig.setGravityTempAdj(false); + myConfig.saveFile(); _server->sendHeader("Location", "/config.htm#collapseGravity", true); _server->send(302, "text/plain", "Gravity config updated"); @@ -619,6 +622,9 @@ void WebServerHandler::webHandleConfigHardware() { if (_server->hasArg(PARAM_GYRO_TEMP)) myConfig.setGyroTemp( _server->arg(PARAM_GYRO_TEMP).equalsIgnoreCase("on") ? true : false); + else + myConfig.setGyroTemp(false); + myConfig.saveFile(); _server->sendHeader("Location", "/config.htm#collapseHardware", true); _server->send(302, "text/plain", "Hardware config updated"); @@ -687,6 +693,11 @@ void WebServerHandler::webHandleConfigAdvancedWrite() { if (_server->hasArg(PARAM_HW_TEMPSENSOR_RESOLUTION)) myAdvancedConfig.setTempSensorResolution( _server->arg(PARAM_HW_TEMPSENSOR_RESOLUTION).toInt()); + if (_server->hasArg(PARAM_HW_IGNORE_LOW_ANGLES)) + myAdvancedConfig.setIgnoreLowAnges( + _server->arg(PARAM_HW_IGNORE_LOW_ANGLES).equalsIgnoreCase("on") ? true : false); + else + myAdvancedConfig.setIgnoreLowAnges(false); myAdvancedConfig.saveFile(); _server->sendHeader("Location", "/config.htm#collapseAdvanced", true); @@ -721,6 +732,7 @@ void WebServerHandler::webHandleConfigAdvancedRead() { doc[PARAM_HW_PUSH_INTERVAL_MQTT] = myAdvancedConfig.getPushIntervalMqtt(); doc[PARAM_HW_TEMPSENSOR_RESOLUTION] = myAdvancedConfig.getTempSensorResolution(); + doc[PARAM_HW_IGNORE_LOW_ANGLES] = myAdvancedConfig.isIgnoreLowAnges(); #if LOG_LEVEL == 6 && !defined(WEB_DISABLE_LOGGING) serializeJson(doc, Serial); diff --git a/src_docs/source/api.rst b/src_docs/source/api.rst index 91ff6dc..0025a2d 100644 --- a/src_docs/source/api.rst +++ b/src_docs/source/api.rst @@ -162,6 +162,7 @@ Used for adjusting some internal constants and other advanced settings. Should b "wifi-portal-timeout": 120, "wifi-connect-timeout": 20, "formula-calibration-temp": 20, + "ignore-low-angles": false, "int-http1": 0, "int-http2": 0, "int-http3": 0, @@ -174,8 +175,11 @@ POST: /api/config/advanced Same parameters as above. -Payload should be in standard format used for posting a form +Payload should be in standard format used for posting a form. +.. note:: + ``ignore-low-angles`` is defined as "on" or "off" when posting since this is the output values + from a checkbox, when reading data it's sent as boolean (true,false). GET: /api/clearwifi =================== diff --git a/src_docs/source/releases.rst b/src_docs/source/releases.rst index e5df889..2b87fb5 100644 --- a/src_docs/source/releases.rst +++ b/src_docs/source/releases.rst @@ -10,6 +10,8 @@ v1.0.0-beta2 * Added button on indexpage to direct to github issues. * Added button to extract important information for support requests. * Updated docs with information from beta1. +* First point in gravity formula is now reserved for water gravity, this to allow detection of angles below water that can be filtered out. +* Added advanced setting to ignore angles that are lower than water. This is disabled by default. v1.0.0-beta1 ------------ diff --git a/test/adv.json b/test/adv.json index edbb91c..1c1653e 100644 --- a/test/adv.json +++ b/test/adv.json @@ -6,6 +6,7 @@ "wifi-connect-timeout": 20, "formula-calibration-temp": 20, "tempsensor-resolution": 9, + "ignore-low-angles": false, "push-timeout": 10, "int-http1": 0, "int-http2": 0, diff --git a/test/config.json b/test/config.json index d56ecd1..746be58 100644 --- a/test/config.json +++ b/test/config.json @@ -35,6 +35,28 @@ "gy": -6, "gz": 4 }, + "formula-calculation-data": { + "a1": 25, + "a3": 35, + "a2": 45, + "a4": 55, + "a5": 30, + "a6": 30, + "a7": 30, + "a8": 30, + "a9": 30, + "a10": 30, + "g1": 1.000, + "g3": 1.010, + "g2": 1.025, + "g4": 1.040, + "g5": 1.005, + "g6": 1.005, + "g7": 1.005, + "g8": 1.005, + "g9": 1.005, + "g10": 1.005 + }, "angle": 90.93, "gravity": 1.105, "battery": 0.04,