From bedbda4662da4354e1e192b584cc64b393da91d8 Mon Sep 17 00:00:00 2001 From: Magnus Persson Date: Thu, 7 Jul 2022 11:11:45 +0200 Subject: [PATCH] Made cal temp adjustable in UI --- html/config.htm | 14 +++++++++-- html/config.min.htm | 2 +- platformio.ini | 2 +- src/calc.hpp | 5 ++-- src/config.cpp | 4 +-- src/config.hpp | 12 ++++----- src/main.cpp | 3 ++- src/webserver.cpp | 48 ++++++++++++++++++++++-------------- src_docs/source/releases.rst | 7 ++++-- test/adv.json | 8 +++--- 10 files changed, 64 insertions(+), 41 deletions(-) diff --git a/html/config.htm b/html/config.htm index 5ed546c..5c95a67 100644 --- a/html/config.htm +++ b/html/config.htm @@ -521,6 +521,14 @@
+
+ +
+ +
+
(0 - 100) - default 20C/68F
+
+
@@ -780,6 +788,7 @@ $("#formula-max-deviation").prop("disabled", b); $("#wifi-portal-timeout").prop("disabled", b); $("#wifi-connect-timeout").prop("disabled", b); + $("#formula-calibration-temp").prop("disabled", b); $("#int-http1").prop("disabled", b); $("#int-http2").prop("disabled", b); $("#int-http3").prop("disabled", b); @@ -794,7 +803,7 @@ setButtonDisabled( true ); var url = "/api/config/advanced"; - //var url = "/test/adv.json"; + var url = "/test/adv.json"; $('#spinner').show(); $.getJSON(url, function (cfg) { console.log( cfg ); @@ -806,6 +815,7 @@ $("#wifi-connect-timeout").val(cfg["wifi-connect-timeout"]); $("#tempsensor-resolution").val(cfg["tempsensor-resolution"]); $("#ignore-low-angles").prop( "checked", cfg["ignore-low-angles"] ); + $("#formula-calibration-temp").val(cfg["formula-calibration-temp"]); $("#int-http1").val(cfg["int-http1"]); $("#int-http2").val(cfg["int-http2"]); $("#int-http3").val(cfg["int-http3"]); @@ -813,7 +823,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["ignore-low-angles"] != false ) { + 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 || (cfg["formula-calibration-temp"] != 20 && cfg["formula-calibration-temp"] != 68)) { $("#adv-config").attr("checked", false ); } }) diff --git a/html/config.min.htm b/html/config.min.htm index 2de0b19..58c1aed 100644 --- a/html/config.min.htm +++ b/html/config.min.htm @@ -1 +1 @@ -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 +Beer Gravity Monitor

Temperature Format


(10-100) - default 50
(50-1000) - default 500
(1 - 10) - default 1.6 SG
(0 - 100) - default 20C/68F

(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/platformio.ini b/platformio.ini index 8c09c30..0887e3f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -34,7 +34,7 @@ build_flags = -D USER_SSID=\""\"" # =\""myssid\"" -D USER_SSID_PWD=\""\"" # =\""mypwd\"" -D CFG_APPVER="\"1.1.0\"" - -D CFG_GITREV=\""beta-1\"" + -D CFG_GITREV=\""beta-2\"" #!python script/git_rev.py lib_deps = # Switched to forks for better version control. # Using local copy of these libraries diff --git a/src/calc.hpp b/src/calc.hpp index 19bd786..a79049e 100644 --- a/src/calc.hpp +++ b/src/calc.hpp @@ -32,9 +32,8 @@ SOFTWARE. double calculateGravity(double angle, double tempC, const char *tempFormula = 0); -double gravityTemperatureCorrectionC( - double gravity, double tempC, - double calTempC = myAdvancedConfig.getDefaultCalibrationTemp()); +double gravityTemperatureCorrectionC(double gravity, double tempC, + double calTempC); int createFormula(RawFormulaData &fd, char *formulaBuffer, int formulaBufferSize, int order); diff --git a/src/config.cpp b/src/config.cpp index 249c2a6..9698174 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -150,7 +150,7 @@ bool Config::saveFile() { return false; } - DynamicJsonDocument doc(CFG_JSON_BUFSIZE); + DynamicJsonDocument doc(3000); createJson(doc); #if LOG_LEVEL == 6 && !defined(DISABLE_LOGGING) @@ -192,7 +192,7 @@ bool Config::loadFile() { Log.notice(F("CFG : Size of configuration file=%d bytes." CR), configFile.size()); - DynamicJsonDocument doc(CFG_JSON_BUFSIZE); + DynamicJsonDocument doc(3000); DeserializationError err = deserializeJson(doc, configFile); #if LOG_LEVEL == 6 serializeJson(doc, Serial); diff --git a/src/config.hpp b/src/config.hpp index 65c7a32..5f9b26d 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -27,8 +27,6 @@ SOFTWARE. #include #include -#define CFG_JSON_BUFSIZE 3192 - #define CFG_APPNAME "GravityMon" // Name of firmware #define CFG_FILENAME "/gravitymon.json" // Name of config file #define CFG_HW_FILENAME "/hardware.json" // Name of config file for hw @@ -56,12 +54,12 @@ struct RawFormulaData { class AdvancedConfig { private: - int _wifiPortalTimeout = 120; - int _wifiConnectTimeout = 20; - float _maxFormulaCreationDeviation = 1.6; - float _defaultCalibrationTemp = 20.0; + int _wifiPortalTimeout = 120; // seconds + int _wifiConnectTimeout = 20; // seconds + float _maxFormulaCreationDeviation = 1.6; // SG + float _defaultCalibrationTemp = 20.0; // C int _gyroSensorMovingThreashold = 500; - int _tempSensorResolution = 9; + int _tempSensorResolution = 9; // bits int _gyroReadCount = 50; int _gyroReadDelay = 3150; // us, empirical, to hold sampling to 200 Hz int _pushTimeout = 10; // seconds diff --git a/src/main.cpp b/src/main.cpp index 147b873..4f9f836 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -279,7 +279,8 @@ bool loopReadGravity() { LOG_PERF_STOP("loop-temp-read"); float gravitySG = calculateGravity(angle, tempC); - float corrGravitySG = gravityTemperatureCorrectionC(gravitySG, tempC); + float corrGravitySG = gravityTemperatureCorrectionC( + gravitySG, tempC, myAdvancedConfig.getDefaultCalibrationTemp()); if (myConfig.isGravityTempAdj()) { gravitySG = corrGravitySG; diff --git a/src/webserver.cpp b/src/webserver.cpp index ba46947..310b74c 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -44,7 +44,7 @@ void WebServerHandler::webHandleConfig() { LOG_PERF_START("webserver-api-config"); Log.notice(F("WEB : webServer callback for /api/config(get)." CR)); - DynamicJsonDocument doc(CFG_JSON_BUFSIZE); + DynamicJsonDocument doc(2000); myConfig.createJson(doc); doc[PARAM_PASS] = ""; // dont show the wifi password @@ -69,8 +69,8 @@ void WebServerHandler::webHandleConfig() { doc[PARAM_TEMP_ADJ] = reduceFloatPrecision(myConfig.getTempSensorAdjC(), 1); if (myConfig.isGravityTempAdj()) { - gravity = - gravityTemperatureCorrectionC(gravity, tempC, myConfig.getTempFormat()); + gravity = gravityTemperatureCorrectionC( + gravity, tempC, myAdvancedConfig.getDefaultCalibrationTemp()); } if (myConfig.isGravityPlato()) { @@ -97,8 +97,9 @@ void WebServerHandler::webHandleConfig() { #endif String out; - out.reserve(CFG_JSON_BUFSIZE); + out.reserve(2000); serializeJson(doc, out); + doc.clear(); _server->send(200, "application/json", out.c_str()); LOG_PERF_STOP("webserver-api-config"); } @@ -160,6 +161,7 @@ void WebServerHandler::webHandleUpload() { String out; out.reserve(300); serializeJson(doc, out); + doc.clear(); _server->send(200, "application/json", out.c_str()); LOG_PERF_STOP("webserver-api-upload"); } @@ -325,7 +327,7 @@ void WebServerHandler::webHandleStatus() { LOG_PERF_START("webserver-api-status"); Log.notice(F("WEB : webServer callback for /api/status(get)." CR)); - DynamicJsonDocument doc(512); + DynamicJsonDocument doc(500); double angle = 0; @@ -337,7 +339,8 @@ void WebServerHandler::webHandleStatus() { doc[PARAM_ID] = myConfig.getID(); doc[PARAM_ANGLE] = reduceFloatPrecision(angle); if (myConfig.isGravityTempAdj()) { - gravity = gravityTemperatureCorrectionC(gravity, tempC); + gravity = gravityTemperatureCorrectionC( + gravity, tempC, myAdvancedConfig.getDefaultCalibrationTemp()); } if (myConfig.isGravityPlato()) { doc[PARAM_GRAVITY] = reduceFloatPrecision(convertToPlato(gravity), 1); @@ -376,8 +379,9 @@ void WebServerHandler::webHandleStatus() { #endif String out; - out.reserve(300); + out.reserve(500); serializeJson(doc, out); + doc.clear(); _server->send(200, "application/json", out.c_str()); LOG_PERF_STOP("webserver-api-status"); } @@ -671,9 +675,11 @@ void WebServerHandler::webHandleConfigAdvancedWrite() { if (_server->hasArg(PARAM_HW_FORMULA_DEVIATION)) myAdvancedConfig.setMaxFormulaCreationDeviation( _server->arg(PARAM_HW_FORMULA_DEVIATION).toFloat()); - if (_server->hasArg(PARAM_HW_FORMULA_CALIBRATION_TEMP)) - myAdvancedConfig.SetDefaultCalibrationTemp( - _server->arg(PARAM_HW_FORMULA_CALIBRATION_TEMP).toFloat()); + if (_server->hasArg(PARAM_HW_FORMULA_CALIBRATION_TEMP)) { + float t = _server->arg(PARAM_HW_FORMULA_CALIBRATION_TEMP).toFloat(); + if (myConfig.isTempF()) t = convertFtoC(t); + myAdvancedConfig.SetDefaultCalibrationTemp(t); + } if (_server->hasArg(PARAM_HW_WIFI_PORTAL_TIMEOUT)) myAdvancedConfig.setWifiPortalTimeout( _server->arg(PARAM_HW_WIFI_PORTAL_TIMEOUT).toInt()); @@ -722,7 +728,7 @@ void WebServerHandler::webHandleConfigAdvancedRead() { LOG_PERF_START("webserver-api-config-advanced"); Log.notice(F("WEB : webServer callback for /api/config/advanced(get)." CR)); - DynamicJsonDocument doc(512); + DynamicJsonDocument doc(500); doc[PARAM_HW_GYRO_READ_COUNT] = myAdvancedConfig.getGyroReadCount(); // doc[PARAM_HW_GYRO_READ_DELAY] = myAdvancedConfig.getGyroReadDelay(); @@ -733,8 +739,9 @@ void WebServerHandler::webHandleConfigAdvancedRead() { doc[PARAM_HW_WIFI_PORTAL_TIMEOUT] = myAdvancedConfig.getWifiPortalTimeout(); doc[PARAM_HW_WIFI_CONNECT_TIMEOUT] = myAdvancedConfig.getWifiConnectTimeout(); doc[PARAM_HW_PUSH_TIMEOUT] = myAdvancedConfig.getPushTimeout(); + float t = myAdvancedConfig.getDefaultCalibrationTemp(); doc[PARAM_HW_FORMULA_CALIBRATION_TEMP] = - myAdvancedConfig.getDefaultCalibrationTemp(); + myConfig.isTempC() ? t : reduceFloatPrecision(convertCtoF(t), 1); doc[PARAM_HW_PUSH_INTERVAL_HTTP1] = myAdvancedConfig.getPushIntervalHttp1(); doc[PARAM_HW_PUSH_INTERVAL_HTTP2] = myAdvancedConfig.getPushIntervalHttp2(); doc[PARAM_HW_PUSH_INTERVAL_HTTP3] = myAdvancedConfig.getPushIntervalHttp3(); @@ -750,8 +757,9 @@ void WebServerHandler::webHandleConfigAdvancedRead() { #endif String out; - out.reserve(512); + out.reserve(500); serializeJson(doc, out); + doc.clear(); _server->send(200, "application/json", out.c_str()); LOG_PERF_STOP("webserver-api-config-advanced"); } @@ -763,7 +771,7 @@ void WebServerHandler::webHandleFormulaRead() { LOG_PERF_START("webserver-api-formula-read"); Log.notice(F("WEB : webServer callback for /api/formula(get)." CR)); - DynamicJsonDocument doc(512); + DynamicJsonDocument doc(500); const RawFormulaData& fd = myConfig.getFormulaData(); #if LOG_LEVEL == 6 && !defined(WEB_DISABLE_LOGGING) @@ -832,8 +840,9 @@ void WebServerHandler::webHandleFormulaRead() { #endif String out; - out.reserve(256); + out.reserve(500); serializeJson(doc, out); + doc.clear(); _server->send(200, "application/json", out.c_str()); LOG_PERF_STOP("webserver-api-formula-read"); } @@ -908,7 +917,8 @@ void WebServerHandler::webHandleTestPush() { float angle = myGyro.getAngle(); float tempC = myTempSensor.getTempC(myConfig.isGyroTemp()); float gravitySG = calculateGravity(angle, tempC); - float corrGravitySG = gravityTemperatureCorrectionC(gravitySG, tempC); + float corrGravitySG = gravityTemperatureCorrectionC( + gravitySG, tempC, myAdvancedConfig.getDefaultCalibrationTemp()); TemplatingEngine engine; engine.initialize(angle, gravitySG, corrGravitySG, tempC, 2.1); @@ -943,6 +953,7 @@ void WebServerHandler::webHandleTestPush() { String out; out.reserve(100); serializeJson(doc, out); + doc.clear(); #if LOG_LEVEL == 6 && !defined(WEB_DISABLE_LOGGING) serializeJson(doc, Serial); @@ -1005,7 +1016,7 @@ void WebServerHandler::webHandleConfigFormatRead() { LOG_PERF_START("webserver-api-config-format-read"); Log.notice(F("WEB : webServer callback for /api/config/formula(get)." CR)); - DynamicJsonDocument doc(2048); + DynamicJsonDocument doc(3000); doc[PARAM_ID] = myConfig.getID(); @@ -1045,8 +1056,9 @@ void WebServerHandler::webHandleConfigFormatRead() { #endif String out; - out.reserve(2048); + out.reserve(3000); serializeJson(doc, out); + doc.clear(); _server->send(200, "application/json", out.c_str()); LOG_PERF_STOP("webserver-api-config-format-read"); } diff --git a/src_docs/source/releases.rst b/src_docs/source/releases.rst index 0722ef7..85de381 100644 --- a/src_docs/source/releases.rst +++ b/src_docs/source/releases.rst @@ -3,8 +3,8 @@ Releases ######## -v1.1.0 -====== +v1.1.0 - beta 2 +=============== Documentation +++++++++++++ @@ -19,6 +19,7 @@ User interface * Under format options its now possible to select brewfather ispindle format to avoid mixing endpoints. * Added brewblox as format under format options. * User can now edit the voltage level that forces the device into config mode (charging) +* (beta2) Calibration temperature (for temp adjustment) can now be set under advanced settings. Features ++++++++ @@ -36,6 +37,8 @@ Issues adressed ++++++++++++++++ * BUG: Copy format templates used an old format for iSpindle and Gravmon where the token was not used. * BUG: Gravity correction formula not calculating correctly. +* (beta2) BUG: Temp corrected gravity was not used when pushing data to removed +* (beta2) BUG: Low memory in format api which resulted in mqtt template to be set to null v1.0.0 ====== diff --git a/test/adv.json b/test/adv.json index 1c1653e..277dd6f 100644 --- a/test/adv.json +++ b/test/adv.json @@ -4,13 +4,13 @@ "formula-max-deviation": 1.6, "wifi-portal-timeout": 120, "wifi-connect-timeout": 20, - "formula-calibration-temp": 20, - "tempsensor-resolution": 9, - "ignore-low-angles": false, "push-timeout": 10, + "formula-calibration-temp": 20, "int-http1": 0, "int-http2": 0, "int-http3": 0, "int-influx": 0, - "int-mqtt": 0 + "int-mqtt": 0, + "tempsensor-resolution": 9, + "ignore-low-angles": false } \ No newline at end of file