diff --git a/html/config.htm b/html/config.htm index 6bc5fa9..dac4386 100644 --- a/html/config.htm +++ b/html/config.htm @@ -93,6 +93,7 @@
+
@@ -134,7 +135,7 @@
- +
@@ -464,9 +465,34 @@ $('#modal-http').on('hide.bs.modal', function (event) { window.location.href = "/format.htm"; }); + function estimateBatteryLife(interval) { + // ESP8266 consumes between 140-170mA when WIFI is on. Deep sleep is 20uA. + // MPU-6050 consumes 4mA + // DS18B20 consumes 1mA + // For this estimation we use an average of 160mA + + var pwr = 160; // mA + var batt = 2200; // mA + var rt = parseInt($("#runtime-average").val()); + + if(rt<1) rt = 2; + + // The deep sleep will consume approx 1mA per day. + var powerPerDay = (24*3600)/(interval+rt)*(rt/3600)*pwr + 1; + return batt/powerPerDay; + } + function updateSleepInfo() { - var i = $("#sleep-interval").val() - $("#sleep-interval-info").text( Math.floor(i/60) + " m " + (i%60) + " s" ) + var i = parseInt($("#sleep-interval").val()); + + var j = estimateBatteryLife(i); + + var t1 = Math.floor(i/60) + " m " + (i%60) + " s"; + var t2 = Math.floor(j/7) + " weeks " + (i%7) + " days"; + + $("#sleep-interval-info").text(t1); + //$("#sleep-interval-info").text( t1 + " - Estimated life: " + t2); + console.log( "Estimated life: " + t2); hideWarningGyro(); if(i>0 && i<300) { @@ -535,6 +561,7 @@ $('#modal-http').on('hide.bs.modal', function (event) { $("#gyro-calibration-data").text( cfg["gyro-calibration-data"]["ax"] + "," + cfg["gyro-calibration-data"]["ay"] + "," + cfg["gyro-calibration-data"]["az"] + "," + cfg["gyro-calibration-data"]["gx"] + "," + cfg["gyro-calibration-data"]["gy"] + "," + cfg["gyro-calibration-data"]["gz"] ); $("#battery").text(cfg["battery"] + " V"); $("#angle").text(cfg["angle"]); + $("#runtime-average").val(cfg["runtime-average"]); //$("#gravity").text(cfg["gravity"] + " SG"); }) .fail(function () { diff --git a/html/config.min.htm b/html/config.min.htm index df5e584..5a5e869 100644 --- a/html/config.min.htm +++ b/html/config.min.htm @@ -1 +1 @@ -Beer Gravity Monitor

Temperature Format:





Gravity Format:


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

Temperature Format:





Gravity Format:


(C) Copyright 2021-22 Magnus Persson
\ No newline at end of file diff --git a/html/device.htm b/html/device.htm index 7c56397..32397e5 100644 --- a/html/device.htm +++ b/html/device.htm @@ -128,7 +128,7 @@ function getConfig() { var url = "/api/device"; - var url = "/test/device.json"; + //var url = "/test/device.json"; $('#spinner').show(); $.getJSON(url, function (cfg) { console.log( cfg ); diff --git a/html/device.min.htm b/html/device.min.htm index 405a388..04c2d57 100644 --- a/html/device.min.htm +++ b/html/device.min.htm @@ -1 +1 @@ -Beer Gravity Monitor

Current version:
Loading...
Host name:
Loading...
Device ID:
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...
Average runtime:
Loading...

(C) Copyright 2021-22 Magnus Persson
\ No newline at end of file diff --git a/src/webserver.cpp b/src/webserver.cpp index 3c1e0f5..9539244 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -96,6 +96,9 @@ void WebServerHandler::webHandleConfig() { doc[PARAM_BATTERY] = reduceFloatPrecision(myBatteryVoltage.getVoltage()); + FloatHistoryLog runLog(RUNTIME_FILENAME); + doc[PARAM_RUNTIME_AVERAGE] = reduceFloatPrecision(runLog.getAverage()?runLog.getAverage()/1000:0, 1); + #if LOG_LEVEL == 6 && !defined(WEB_DISABLE_LOGGING) serializeJson(doc, Serial); Serial.print(CR); diff --git a/src_docs/source/api.rst b/src_docs/source/api.rst index f574d48..68b04eb 100644 --- a/src_docs/source/api.rst +++ b/src_docs/source/api.rst @@ -55,7 +55,8 @@ Other parameters are the same as in the configuration guide. }, "angle": 90.93, "gravity": 1.105, - "battery": 0.04 + "battery": 0.04, + "runtime-average": 3.12 } diff --git a/test/config.json b/test/config.json index ed87f78..b0cf88d 100644 --- a/test/config.json +++ b/test/config.json @@ -36,5 +36,6 @@ }, "angle": 90.93, "gravity": 1.105, - "battery": 0.04 + "battery": 0.04, + "runtime-average": 2.0 } \ No newline at end of file