Skip to content

Commit

Permalink
Merge pull request #15 from mp-se/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
mp-se authored Mar 16, 2023
2 parents c2ab7d6 + c401ff3 commit 1fd6ebc
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 16 deletions.
Binary file modified bin/firmware.bin
Binary file not shown.
Binary file modified bin/firmware32s2.bin
Binary file not shown.
96 changes: 96 additions & 0 deletions html/ws.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<title>Keg Monitor</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<style>
.row-margin-10 { margin-top: 1.0em; }
</style>
</head>

<body class="py-4">

<!-- START MENU -->

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>

<!-- START BODY -->

<div class="container row-margin-10">

<div class="accordion row-margin-10" id="accordion">
<div class="accordion-item">
<h2 class="accordion-header" id="headingTest">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTest" aria-expanded="true" aria-controls="collapseTest">
<b>Serial Log</b>
</button>
</h2>
<div id="collapseTest" class="accordion-collapse collapse show" aria-labelledby="headingTest" data-bs-parent="#accordion">
<div class="accordion-body">
<div class="collapse row-margin-10 show" id="collapseLog">
<div class="card card-body">
<pre><code class="card-text" id="logContent" data-bs-toggle="tooltip" title="Shows the serial .">Connecting to websocket, please wait...</code></pre>
</div>
</div>
</div>
</div>
</div>

</div>
</div>

<script>
let log = "";
let maxLog = 50;

connectSocket();

function connectSocket() {
console.log("Attempting to connect to websocket");
socket = new WebSocket(`ws://${location.host}/serialws`);
// socket = new WebSocket("ws://192.168.1.136/serialws");

socket.onopen = function(e) {
log = log + "Websocket established\n";
document.getElementById("logContent").innerHTML = log;
};

socket.onmessage = function(event) {
log = log + event.data;
list = log.split("\n");

while(list.length > maxLog) {
list.shift();
}

log = list.join('\n');
document.getElementById("logContent").innerHTML = log;
};

socket.onclose = function(event) {
if (event.wasClean) {
console.log(`Connection closed cleanly, code=${event.code} reason=${event.reason}`);
} else {
console.log('Connection died');
}

log = log + "Websocket closed/died\n";
document.getElementById("logContent").innerHTML = log;
setTimeout( function() { connectSocket(); }, 2000 );
};

socket.onerror = function(error) {
console.log(error);
};
}

</script>

<!-- START FOOTER -->

<div class="container themed-container bg-primary text-light row-margin-10">(C) Copyright 2023 Magnus Persson</div>
</body>
</html>
43 changes: 43 additions & 0 deletions html/ws.min.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="description" content=""><title>Keg Monitor</title><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous"><style>.row-margin-10{margin-top:1em}</style></head><body class="py-4"><!-- START MENU --><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script><!-- START BODY --><div class="container row-margin-10"><div class="accordion row-margin-10" id="accordion"><div class="accordion-item"><h2 class="accordion-header" id="headingTest"><button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTest" aria-expanded="true" aria-controls="collapseTest"><b>Serial Log</b></button></h2><div id="collapseTest" class="accordion-collapse collapse show" aria-labelledby="headingTest" data-bs-parent="#accordion"><div class="accordion-body"><div class="collapse row-margin-10 show" id="collapseLog"><div class="card card-body"><pre><code class="card-text" id="logContent" data-bs-toggle="tooltip" title="Shows the serial .">Connecting to websocket, please wait...</code></pre></div></div></div></div></div></div></div><script>let log = "";
let maxLog = 50;

connectSocket();

function connectSocket() {
console.log("Attempting to connect to websocket");
socket = new WebSocket(`ws://${location.host}/serialws`);
// socket = new WebSocket("ws://192.168.1.136/serialws");

socket.onopen = function(e) {
log = log + "Websocket established\n";
document.getElementById("logContent").innerHTML = log;
};

socket.onmessage = function(event) {
log = log + event.data;
list = log.split("\n");

while(list.length > maxLog) {
list.shift();
}

log = list.join('\n');
document.getElementById("logContent").innerHTML = log;
};

socket.onclose = function(event) {
if (event.wasClean) {
console.log(`Connection closed cleanly, code=${event.code} reason=${event.reason}`);
} else {
console.log('Connection died');
}

log = log + "Websocket closed/died\n";
document.getElementById("logContent").innerHTML = log;
setTimeout( function() { connectSocket(); }, 2000 );
};

socket.onerror = function(error) {
console.log(error);
};
}</script><!-- START FOOTER --><div class="container themed-container bg-primary text-light row-margin-10">(C) Copyright 2023 Magnus Persson</div></body></html>
14 changes: 7 additions & 7 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ build_flags =
-D PUSH_INFLUX_BUCKET=\""\""
-D PUSH_INFLUX_ORG=\""\""
-D PUSH_INFLUX_TOKEN=\""\""
-D CFG_GITREV=\""beta1\""
-D CFG_GITREV=\""beta3\""
#!python script/git_rev.py
lib_deps =
https://github.com/mp-se/SimpleKalmanFilter#v0.2
https://github.com/mp-se/Statistic#1.0.1
#https://github.com/mp-se/HX711#0.7.5 Moved to lib due to incompatibility with esp8266 fwk 4.1.0
https://github.com/mp-se/esp8266-oled-ssd1306#4.3.0
https://github.com/mp-se/DHT-sensor-library#1.4.4
https://github.com/mp-se/Adafruit_Sensor#1.1.7
Expand Down Expand Up @@ -70,7 +69,7 @@ build_flags =
${common_env_data.build_flags}
-D LOG_LEVEL=6
lib_deps =
https://github.com/mp-se/espframework#0.5.1
https://github.com/mp-se/espframework#0.6.0
${common_env_data.lib_deps}
board = d1_mini
build_type = release
Expand All @@ -90,7 +89,7 @@ build_flags =
-D LOG_LEVEL=5
-D USE_ASYNC_WEB
lib_deps =
https://github.com/mp-se/espframework#0.5.1
https://github.com/mp-se/espframework#0.6.0
https://github.com/mp-se/ESPAsyncWebServer
https://github.com/mp-se/ESPAsyncTCP
${common_env_data.lib_deps}
Expand All @@ -109,7 +108,7 @@ build_flags =
${common_env_data.build_flags}
-D LOG_LEVEL=5
lib_deps =
https://github.com/mp-se/espframework#0.5.1
https://github.com/mp-se/espframework#0.6.0
${common_env_data.lib_deps}
board = d1_mini
build_type = release
Expand All @@ -126,7 +125,7 @@ build_flags =
${common_env_data.build_flags}
-D LOG_LEVEL=6
lib_deps =
https://github.com/mp-se/espframework#0.5.1
https://github.com/mp-se/espframework#0.6.0
https://github.com/bxparks/AUnit#v1.6.1
${common_env_data.lib_deps}
board = d1_mini
Expand All @@ -152,7 +151,7 @@ build_flags =
#-D CORE_DEBUG_LEVEL=2
${common_env_data.build_flags}
lib_deps =
https://github.com/mp-se/espframework#0.5.1
https://github.com/mp-se/espframework#0.6.0
https://github.com/mp-se/ESPAsyncWebServer
https://github.com/mp-se/AsyncTCP
${common_env_data.lib_deps}
Expand All @@ -168,3 +167,4 @@ board_build.embed_txtfiles =
html/graph.min.htm
html/stability.min.htm
html/backup.min.htm
html/ws.min.htm
2 changes: 1 addition & 1 deletion src/kegconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SOFTWARE.
#include <utils.hpp>

KegConfig::KegConfig(String baseMDNS, String fileName)
: BaseConfig(baseMDNS, fileName) {}
: BaseConfig(baseMDNS, fileName, JSON_BUFFER) {}

void KegConfig::createJson(DynamicJsonDocument& doc, bool skipSecrets) {
// Call base class functions
Expand Down
12 changes: 7 additions & 5 deletions src/kegwebhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ constexpr auto PARAM_LAST_POUR_VOLUME1 = "last-pour-volume1";
constexpr auto PARAM_LAST_POUR_VOLUME2 = "last-pour-volume2";

#if defined(USE_ASYNC_WEB)
KegWebHandler::KegWebHandler(KegConfig* config) : BaseAsyncWebHandler(config) {
KegWebHandler::KegWebHandler(KegConfig* config)
: BaseAsyncWebHandler(config, JSON_BUFFER) {
_config = config;
}
#else
KegWebHandler::KegWebHandler(KegConfig* config) : BaseWebHandler(config) {
KegWebHandler::KegWebHandler(KegConfig* config)
: BaseWebHandler(config, JSON_BUFFER) {
_config = config;
}
#endif
Expand Down Expand Up @@ -126,14 +128,14 @@ void KegWebHandler::webHandleBrewspy(WS_PARAM) {
void KegWebHandler::webScale(WS_PARAM) {
Log.notice(F("WEB : webServer callback /api/scale." CR));

DynamicJsonDocument doc(300);
DynamicJsonDocument doc(500);
populateScaleJson(doc);

doc[PARAM_WEIGHT_UNIT] = myConfig.getWeightUnit();
doc[PARAM_VOLUME_UNIT] = myConfig.getVolumeUnit();

String out;
out.reserve(300);
out.reserve(500);
serializeJson(doc, out);
doc.clear();
WS_SEND(200, "application/json", out.c_str());
Expand Down Expand Up @@ -388,7 +390,7 @@ void KegWebHandler::webStability(WS_PARAM) {
#endif

String out;
out.reserve(500);
out.reserve(800);
serializeJson(doc, out);
doc.clear();
WS_SEND(200, "application/json", out.c_str());
Expand Down
9 changes: 9 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ SOFTWARE.
#include <ota.hpp>
#include <perf.hpp>
#include <scale.hpp>
#include <serialws.hpp>
#include <temp.hpp>
#include <utils.hpp>
#include <wificonnection.hpp>
Expand All @@ -43,6 +44,9 @@ Display myDisplay;
Scale myScale;
LevelDetection myLevelDetection;
TempHumidity myTemp;
#if defined(USE_ASYNC_WEB)
SerialWebSocket mySerialWebSocket;
#endif

const int loopInterval = 2000;
int loopCounter = 0;
Expand Down Expand Up @@ -135,6 +139,8 @@ void setup() {
PERF_BEGIN("setup-webserver");
#if defined(USE_ASYNC_WEB)
myWebHandler.setupAsyncWebServer();
mySerialWebSocket.begin(myWebHandler.getWebServer(), &Serial);
mySerial.begin(&mySerialWebSocket);
#else
myWebHandler.setupWebServer();
#endif
Expand Down Expand Up @@ -314,6 +320,9 @@ void loop() {

myWebHandler.loop();
myWifi.loop();
#if defined(USE_ASYNC_WEB)
mySerialWebSocket.loop();
#endif
myScale.loop(UnitIndex::U1);
myScale.loop(UnitIndex::U2);

Expand Down
2 changes: 2 additions & 0 deletions src/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ constexpr auto CFG_FILENAME = "/kegmon.json"; // Name of config file
constexpr auto DISPLAY_ADR1 = 0x3c;
constexpr auto DISPLAY_ADR2 = 0x3d;

constexpr auto JSON_BUFFER = 3000;

#if defined(ESP8266)
#define ESP_RESET ESP.reset
constexpr auto PIN_LED = 2;
Expand Down
2 changes: 0 additions & 2 deletions src/scale.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ class Scale {
public:
Scale() {}

void test(UnitIndex idx) { readRawNAU7802(idx); }

void setup(bool force = false) {
switch (myConfig.getScaleSensorType()) {
case ScaleSensorType::ScaleHX711:
Expand Down
4 changes: 3 additions & 1 deletion src_docs/source/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Releases
########

v0.6.0 beta 2
v0.6.0 beta 3
=============

.. note::
Expand All @@ -12,9 +12,11 @@ v0.6.0 beta 2
.. warning::
Issues with connecting to DHT22 sensor on ESP32S2 variant over long cables. Uncertain what causes this. Recommendation is to use DS18B20 instead on ESP32S2.

* BUG: Configuration lost when JSON document became to large, increased buffer to 3kb (from 2kb)
* Added support for NAU7802 AD converter from sparkfun. Uses I2C bus. Will require ESP32S2 for two scales and different wiring. This is EXPERIMENTAL!
* Added error message to restore configuration feature in case the ID did not match.
* Added pull-up resistor to temperature sensor data line (applies to both DS18B20 and DHT22)
* Added web based serial console accessed via http://device/serial or ws://device/serialws (only works with async webserver)

v0.6.0 beta 1
=============
Expand Down

0 comments on commit 1fd6ebc

Please sign in to comment.