From 79a3274286b48203df2677d5ad8092bdee5bdb99 Mon Sep 17 00:00:00 2001 From: Magnus Persson Date: Sun, 3 Jul 2022 23:46:44 +0200 Subject: [PATCH] Made config voltage configurable --- html/config.htm | 10 +++++++++- html/config.min.htm | 2 +- src/config.cpp | 9 ++++++--- src/config.hpp | 11 +++++++++++ src/main.cpp | 14 +++++++++----- src/resources.hpp | 3 ++- src/webserver.cpp | 9 ++++++--- src_docs/source/configuration.rst | 11 +++++++++++ src_docs/source/releases.rst | 7 +++++++ test/config.json | 2 ++ 10 files changed, 64 insertions(+), 14 deletions(-) diff --git a/html/config.htm b/html/config.htm index 1add46f..6a7814e 100644 --- a/html/config.htm +++ b/html/config.htm @@ -390,11 +390,18 @@
- +
+
+ +
+ +
+
+
@@ -865,6 +872,7 @@ $("#mqtt-pass").val(cfg["mqtt-pass"]); $("#sleep-interval").val(cfg["sleep-interval"]); $("#voltage-factor").val(cfg["voltage-factor"]); + $("#voltage-config").val(cfg["voltage-config"]); $("#gravity-formula").val(cfg["gravity-formula"]); $("#temp-adjustment-value").val(cfg["temp-adjustment-value"]); $("#gravity-temp-adjustment").prop( "checked", cfg["gravity-temp-adjustment"] ); diff --git a/html/config.min.htm b/html/config.min.htm index 5536388..dba3000 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

(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/src/config.cpp b/src/config.cpp index 47f724d..249c2a6 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -86,7 +86,8 @@ void Config::createJson(DynamicJsonDocument& doc) { doc[PARAM_PUSH_MQTT_USER] = getMqttUser(); doc[PARAM_PUSH_MQTT_PASS] = getMqttPass(); doc[PARAM_SLEEP_INTERVAL] = getSleepInterval(); - doc[PARAM_VOLTAGEFACTOR] = getVoltageFactor(); + doc[PARAM_VOLTAGE_FACTOR] = getVoltageFactor(); + doc[PARAM_VOLTAGE_CONFIG] = getVoltageConfig(); doc[PARAM_GRAVITY_FORMULA] = getGravityFormula(); doc[PARAM_GRAVITY_FORMAT] = String(getGravityFormat()); doc[PARAM_TEMP_ADJ] = getTempSensorAdjC(); @@ -254,8 +255,10 @@ bool Config::loadFile() { if (!doc[PARAM_SLEEP_INTERVAL].isNull()) setSleepInterval(doc[PARAM_SLEEP_INTERVAL].as()); - if (!doc[PARAM_VOLTAGEFACTOR].isNull()) - setVoltageFactor(doc[PARAM_VOLTAGEFACTOR].as()); + if (!doc[PARAM_VOLTAGE_FACTOR].isNull()) + setVoltageFactor(doc[PARAM_VOLTAGE_FACTOR].as()); + if (!doc[PARAM_VOLTAGE_CONFIG].isNull()) + setVoltageConfig(doc[PARAM_VOLTAGE_CONFIG].as()); if (!doc[PARAM_GRAVITY_FORMULA].isNull()) setGravityFormula(doc[PARAM_GRAVITY_FORMULA]); if (!doc[PARAM_GRAVITY_TEMP_ADJ].isNull()) diff --git a/src/config.hpp b/src/config.hpp index 278987e..65c7a32 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -146,6 +146,7 @@ class Config { String _otaURL = ""; char _tempFormat = 'C'; float _voltageFactor = 1.59; + float _voltageConfig = 4.15; float _tempSensorAdjC = 0; int _sleepInterval = 900; bool _gyroTemp = false; @@ -378,6 +379,16 @@ class Config { _saveNeeded = true; } + float getVoltageConfig() { return _voltageConfig; } + void setVoltageConfig(float f) { + _voltageConfig = f; + _saveNeeded = true; + } + void setVoltageConfig(String s) { + _voltageConfig = s.toFloat(); + _saveNeeded = true; + } + float getTempSensorAdjC() { return _tempSensorAdjC; } void setTempSensorAdjC(float f) { _tempSensorAdjC = f; diff --git a/src/main.cpp b/src/main.cpp index 4e3b81a..fc87047 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -80,7 +80,9 @@ void checkSleepMode(float angle, float volt) { Log.notice(F("MAIN: Sleep mode disabled from web interface." CR)); #endif runMode = RunMode::configurationMode; - } else if ((volt < 4.15 && (angle > 85 && angle < 95)) || (volt > 4.15)) { + } else if ((volt < myConfig.getVoltageConfig() && + (angle > 85 && angle < 95)) || + (volt > myConfig.getVoltageConfig())) { runMode = RunMode::configurationMode; } else if (angle < 5 && myConfig.isStorageSleep()) { runMode = RunMode::storageMode; @@ -193,13 +195,15 @@ void setup() { if (runMode == RunMode::storageMode) { // If we are in storage mode, just go back to sleep - Log.notice(F("Main: Storage mode entered, going to sleep for maximum time." CR)); + Log.notice(F( + "Main: Storage mode entered, going to sleep for maximum time." CR)); #if defined(ESP8266) ESP.deepSleep(ESP.deepSleepMax()); #else - #warning "Check and test the max deep sleep for esp32" - deepSleep(70*60); // quick search on internet suggest max time is 70 min -#endif +#warning "Check and test the max deep sleep for esp32" + deepSleep(70 * + 60); // quick search on internet suggest max time is 70 min +#endif } #if defined(ESP32) diff --git a/src/resources.hpp b/src/resources.hpp index 63f24d5..b736d28 100644 --- a/src/resources.hpp +++ b/src/resources.hpp @@ -53,7 +53,8 @@ SOFTWARE. #define PARAM_PUSH_MQTT_PORT "mqtt-port" #define PARAM_SLEEP_INTERVAL "sleep-interval" #define PARAM_TEMPFORMAT "temp-format" -#define PARAM_VOLTAGEFACTOR "voltage-factor" +#define PARAM_VOLTAGE_FACTOR "voltage-factor" +#define PARAM_VOLTAGE_CONFIG "voltage-config" #define PARAM_GRAVITY_FORMULA "gravity-formula" #define PARAM_GRAVITY_FORMAT "gravity-format" #define PARAM_GRAVITY_TEMP_ADJ "gravity-temp-adjustment" diff --git a/src/webserver.cpp b/src/webserver.cpp index 981f09c..ba46947 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -605,8 +605,10 @@ void WebServerHandler::webHandleConfigHardware() { Log.verbose(F("WEB : %s." CR), getRequestArguments().c_str()); #endif - if (_server->hasArg(PARAM_VOLTAGEFACTOR)) - myConfig.setVoltageFactor(_server->arg(PARAM_VOLTAGEFACTOR).toFloat()); + if (_server->hasArg(PARAM_VOLTAGE_FACTOR)) + myConfig.setVoltageFactor(_server->arg(PARAM_VOLTAGE_FACTOR).toFloat()); + if (_server->hasArg(PARAM_VOLTAGE_CONFIG)) + myConfig.setVoltageConfig(_server->arg(PARAM_VOLTAGE_CONFIG).toFloat()); if (_server->hasArg(PARAM_TEMP_ADJ)) { if (myConfig.isTempC()) { myConfig.setTempSensorAdjC(_server->arg(PARAM_TEMP_ADJ)); @@ -626,7 +628,8 @@ void WebServerHandler::webHandleConfigHardware() { myConfig.setGyroTemp(false); if (_server->hasArg(PARAM_STORAGE_SLEEP)) myConfig.setStorageSleep( - _server->arg(PARAM_STORAGE_SLEEP).equalsIgnoreCase("on") ? true : false); + _server->arg(PARAM_STORAGE_SLEEP).equalsIgnoreCase("on") ? true + : false); else myConfig.setStorageSleep(false); diff --git a/src_docs/source/configuration.rst b/src_docs/source/configuration.rst index 61eb4ef..c16990a 100644 --- a/src_docs/source/configuration.rst +++ b/src_docs/source/configuration.rst @@ -233,6 +233,10 @@ Hardware Settings Factor used to calcualate the battery voltage. If you get a too low/high voltage you can adjust this value. +* **Config voltage:** + +Defines the level of voltage when the device should enter config mode due to charging. This might vary between different battery manufacturers. + * **Temperature correction:** This value will be added to the temperature reading (negative value will reduce temperature reading). This is applied @@ -245,6 +249,13 @@ longer battery life (this is an experimental feature). The value used is the fir device is activated, since the gyro should be cool this is reflecting the surronding temperature. After it has been running the value would be totally off. +* **Enable storage mode when placed on cap** + +Enable storage mode on the device. When place on the cap (<5 degres tilt) the device will go into max sleep. In order to wake it up +you need to do a reset (or wait for the device to wake up). One option is to attach a magnetic reed switch (default open) to the reset pin +and use a magnet to force a reset without opening the tube. The reed switch is typically an electronic component of 14 mm long incapsulated +in a small glass tube. + * **Bluetooth: (Only ESP32)** If the build is using an ESP32 then you can send data over BLE, simulating a Tilt device. Choose the color that you want the device to simulate. diff --git a/src_docs/source/releases.rst b/src_docs/source/releases.rst index d4b75d8..a95e747 100644 --- a/src_docs/source/releases.rst +++ b/src_docs/source/releases.rst @@ -17,6 +17,13 @@ Documentation 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) + +Features +++++++++ +* Added storage mode which is activated under hardware setting. When place on the cap (<5 degres tilt) the device will go into +storage mode and sleep for the max allowed time. Issues adressed ++++++++++++++++ diff --git a/test/config.json b/test/config.json index 746be58..5b45815 100644 --- a/test/config.json +++ b/test/config.json @@ -20,8 +20,10 @@ "mqtt-port": 1883, "mqtt-user": "user", "mqtt-pass": "pass", + "storage-sleep": true, "sleep-interval": 30, "voltage-factor": 1.59, + "voltage-config": 4.15, "gravity-formula": "0.0*tilt^3+0.0*tilt^2+0.0017978*tilt+0.9436", "gravity-format": "G", "temp-adjustment-value": 0,