Added download of html via ota function

This commit is contained in:
Magnus
2021-03-28 08:47:37 +02:00
parent 230955d456
commit f56ef0c56f
19 changed files with 54 additions and 16 deletions

2
.gitignore vendored
View File

@ -2,3 +2,5 @@
.vscode/*
*.map
test/*.md
test/env/*
test/*.py

View File

@ -1 +1,17 @@
TODO: Write the documentation for this project
# Gravity Monitor for Beer Brewing
I started this project out of curiosity for how a motion sensor is working and since I like to brew beer this was the result. This software can be used with iSpindle hardware and utilizes the same hardware configuration. No part of this software has been copied from that project.
This is still in early testing and has not the same range of external integrations as the standard software, so far only standard HTTP and Brewfather endpoints have been implemented.
Gravity formulas are compatible with the standard software so switching is easy.
Main differences towards in the design is:
* Web GUI for configuration that can be accessed when connected to network and the device is connected to power.
* Sleep mode can be disabled so angles/tilt can be easily viewed.
* Temperature sensor adjustment values.
* Temperature correcton of calculated gravity value.
* OTA support from local webserver when connected to power.
More documentation will come when I have more time...

File diff suppressed because one or more lines are too long

View File

@ -14,4 +14,4 @@
<button type="button" class="btn btn-warning" id="wifi-reset-btn">Factory default settings</button>
</div>
</div>
--><hr class="my-4"></div><script type="text/javascript">function getConfig(){var n="/api/device";$("#spinner").show(),$.getJSON(n,function(n){console.log(n),$("#app-ver").text(n["app-ver"]),$("#mdns").text(n.mdns),$("#id").text(n.id)}).fail(function(){showError("Unable to get data from the device.")}).always(function(){$("#spinner").hide()})}window.onload=getConfig</script><!-- START FOOTER --><div class="container-fluid themed-container bg-primary text-light">(C) Copyright 2021 Magnus Persson</div></body></html>
--><hr class="my-4"></div><script type="text/javascript">function getConfig(){var n="/api/device";$("#spinner").show(),$.getJSON(n,function(n){console.log(n),$("#app-ver").text(n["app-ver"]+" (html 0.2.1)"),$("#mdns").text(n.mdns),$("#id").text(n.id)}).fail(function(){showError("Unable to get data from the device.")}).always(function(){$("#spinner").hide()})}window.onload=getConfig</script><!-- START FOOTER --><div class="container-fluid themed-container bg-primary text-light">(C) Copyright 2021 Magnus Persson</div></body></html>

Binary file not shown.

Binary file not shown.

View File

@ -1 +1 @@
{ "project":"gravmon", "version":"0.2.0", "html": [ "index.min.htm", "device.min.htm", "config.min.htm", "about.min.htm" ] }
{ "project":"gravmon", "version":"0.2.1", "html": [ "index.min.htm", "device.min.htm", "config.min.htm", "about.min.htm" ] }

View File

@ -138,11 +138,17 @@
<form action="/api/config/push" method="post">
<input type="text" name="id" id="id2" hidden>
<div class="form-group row">
<label for="http-push" class="col-sm-4 col-form-label">Http:</label>
<label for="http-push" class="col-sm-4 col-form-label">Http 1:</label>
<div class="col-sm-8">
<input type="url" maxlength="90" class="form-control" name="http-push" id="http-push">
</div>
</div>
<div class="form-group row">
<label for="http-push2" class="col-sm-4 col-form-label">Http 2:</label>
<div class="col-sm-8">
<input type="url" maxlength="90" class="form-control" name="http-push2" id="http-push2">
</div>
</div>
<div class="form-group row">
<label for="inputBrewfatherPush" class="col-sm-4 col-form-label">Brewfather:</label>
<div class="col-sm-8">
@ -302,6 +308,7 @@
$("#temp-format-f").click();
$("#ota-url").val(cfg["ota-url"]);
$("#http-push").val(cfg["http-push"]);
$("#http-push2").val(cfg["http-push2"]);
$("#brewfather-push").val(cfg["brewfather-push"]);
$("#push-interval").val(cfg["push-interval"]);
$("#voltage-factor").val(cfg["voltage-factor"]);

File diff suppressed because one or more lines are too long

View File

@ -118,7 +118,7 @@
$('#spinner').show();
$.getJSON(url, function (cfg) {
console.log( cfg );
$("#app-ver").text(cfg["app-ver"]);
$("#app-ver").text(cfg["app-ver"] + " (html 0.2.1)");
$("#mdns").text(cfg["mdns"]);
$("#id").text(cfg["id"]);
})

View File

@ -14,4 +14,4 @@
<button type="button" class="btn btn-warning" id="wifi-reset-btn">Factory default settings</button>
</div>
</div>
--><hr class="my-4"></div><script type="text/javascript">function getConfig(){var n="/api/device";$("#spinner").show(),$.getJSON(n,function(n){console.log(n),$("#app-ver").text(n["app-ver"]),$("#mdns").text(n.mdns),$("#id").text(n.id)}).fail(function(){showError("Unable to get data from the device.")}).always(function(){$("#spinner").hide()})}window.onload=getConfig</script><!-- START FOOTER --><div class="container-fluid themed-container bg-primary text-light">(C) Copyright 2021 Magnus Persson</div></body></html>
--><hr class="my-4"></div><script type="text/javascript">function getConfig(){var n="/api/device";$("#spinner").show(),$.getJSON(n,function(n){console.log(n),$("#app-ver").text(n["app-ver"]+" (html 0.2.1)"),$("#mdns").text(n.mdns),$("#id").text(n.id)}).fail(function(){showError("Unable to get data from the device.")}).always(function(){$("#spinner").hide()})}window.onload=getConfig</script><!-- START FOOTER --><div class="container-fluid themed-container bg-primary text-light">(C) Copyright 2021 Magnus Persson</div></body></html>

View File

@ -26,7 +26,7 @@ build_flags = #-O0 -Wl,-Map,output.map
#-D SKIP_SLEEPMODE
-D USE_LITTLEFS=true
#-D EMBED_HTML
-D CFG_APPVER="\"0.2.0\""
-D CFG_APPVER="\"0.2.1\""
lib_deps =
# https://github.com/jrowberg/i2cdevlib.git # Using local copy of this library
https://github.com/codeplea/tinyexpr

View File

@ -53,6 +53,7 @@ void Config::createJson(DynamicJsonDocument& doc) {
doc[ CFG_PARAM_TEMPFORMAT ] = String( getTempFormat() );
doc[ CFG_PARAM_PUSH_BREWFATHER ] = getBrewfatherPushTarget();
doc[ CFG_PARAM_PUSH_HTTP ] = getHttpPushTarget();
doc[ CFG_PARAM_PUSH_HTTP2 ] = getHttpPushTarget2();
doc[ CFG_PARAM_PUSH_INTERVAL ] = getPushInterval();
doc[ CFG_PARAM_VOLTAGEFACTOR ] = getVoltageFactor();
doc[ CFG_PARAM_GRAVITY_FORMULA ] = getGravityFormula();
@ -154,6 +155,8 @@ bool Config::loadFile() {
setBrewfatherPushTarget( doc[ CFG_PARAM_PUSH_BREWFATHER ] );
if( !doc[ CFG_PARAM_PUSH_HTTP ].isNull() )
setHttpPushTarget( doc[ CFG_PARAM_PUSH_HTTP ] );
if( !doc[ CFG_PARAM_PUSH_HTTP2 ].isNull() )
setHttpPushTarget2( doc[ CFG_PARAM_PUSH_HTTP2 ] );
if( !doc[ CFG_PARAM_PUSH_INTERVAL ].isNull() )
setPushInterval( doc[ CFG_PARAM_PUSH_INTERVAL ].as<int>() );
if( !doc[ CFG_PARAM_VOLTAGEFACTOR ].isNull() )
@ -223,6 +226,7 @@ void Config::debug() {
Log.verbose(F("CFG : Gravity formula; '%s'." CR), getGravityFormula() );
Log.verbose(F("CFG : Push brewfather; '%s'." CR), getBrewfatherPushTarget() );
Log.verbose(F("CFG : Push http; '%s'." CR), getHttpPushTarget() );
Log.verbose(F("CFG : Push http2; '%s'." CR), getHttpPushTarget2() );
Log.verbose(F("CFG : Push interval; %d." CR), getPushInterval() );
// Log.verbose(F("CFG : Accel offset\t%d\t%d\t%d" CR), gyroCalibration.ax, gyroCalibration.ay, gyroCalibration.az );
// Log.verbose(F("CFG : Gyro offset \t%d\t%d\t%d" CR), gyroCalibration.gx, gyroCalibration.gy, gyroCalibration.gz );

View File

@ -47,6 +47,7 @@ SOFTWARE.
#define CFG_PARAM_OTA "ota-url" // Base URL for OTA
#define CFG_PARAM_PUSH_BREWFATHER "brewfather-push" // URL (brewfather format)
#define CFG_PARAM_PUSH_HTTP "http-push" // URL (iSpindle format)
#define CFG_PARAM_PUSH_HTTP2 "http-push2" // URL (iSpindle format)
#define CFG_PARAM_PUSH_INTERVAL "push-interval" // Time between push
#define CFG_PARAM_TEMPFORMAT "temp-format" // C or F
#define CFG_PARAM_VOLTAGEFACTOR "voltage-factor" // Factor to calculate the battery voltage
@ -95,6 +96,7 @@ class Config {
// Push target settings
char brewfatherPushTarget[200];
char httpPushTarget[200];
char httpPushTarget2[200];
int pushInterval;
// Gravity and temperature calculations
@ -127,6 +129,10 @@ class Config {
void setHttpPushTarget( const char* s ) { strncpy(&httpPushTarget[0], s, sizeof(httpPushTarget)-1); saveNeeded = true; }
bool isHttpActive() { return strlen(&httpPushTarget[0])>0?true:false; }
const char* getHttpPushTarget2() { return &httpPushTarget2[0]; }
void setHttpPushTarget2( const char* s ) { strncpy(&httpPushTarget2[0], s, sizeof(httpPushTarget2)-1); saveNeeded = true; }
bool isHttpActive2() { return strlen(&httpPushTarget2[0])>0?true:false; }
int getPushInterval() { return pushInterval; }
void setPushInterval( int v ) { pushInterval = v; saveNeeded = true; }
void setPushInterval( const char* s ) { pushInterval = atoi(s); saveNeeded = true; }

View File

@ -38,7 +38,7 @@ SOFTWARE.
#define MRD_TIMES 3
#define MRD_TIMEOUT 10
#define MRD_ADDRESS 0
#define MULTIRESETDETECTOR_DEBUG true
//#define MULTIRESETDETECTOR_DEBUG true
#include <ESP_MultiResetDetector.h>
MultiResetDetector *mrd;

View File

@ -51,7 +51,10 @@ void PushTarget::send(float angle, float gravity, float temp, float runTime, boo
sendBrewfather( angle, gravity, temp );
if( myConfig.isHttpActive() )
sendHttp( angle, gravity, temp, runTime );
sendHttp( myConfig.getHttpPushTarget(), angle, gravity, temp, runTime );
if( myConfig.isHttpActive2() )
sendHttp( myConfig.getHttpPushTarget2(), angle, gravity, temp, runTime );
}
//
@ -123,7 +126,7 @@ void PushTarget::sendBrewfather(float angle, float gravity, float temp ) {
//
// Send data to http target
//
void PushTarget::sendHttp(float angle, float gravity, float temp, float runTime ) {
void PushTarget::sendHttp( String serverPath, float angle, float gravity, float temp, float runTime ) {
Log.notice(F("PUSH: Sending values to http angle=%F, gravity=%F, temp=%F." CR), angle, gravity, temp );
DynamicJsonDocument doc(256);
@ -141,7 +144,6 @@ void PushTarget::sendHttp(float angle, float gravity, float temp, float runTime
WiFiClient client;
HTTPClient http;
String serverPath = myConfig.getHttpPushTarget();
// Your Domain name with URL path or IP address with path
http.begin( client, serverPath);

View File

@ -38,7 +38,7 @@ class PushTarget {
unsigned long ms; // Used to check that we do not post to often
void sendBrewfather(float angle, float gravity, float temp );
void sendHttp(float angle, float gravity, float temp, float runTime );
void sendHttp(String serverPath, float angle, float gravity, float temp, float runTime );
public:
PushTarget() { ms = millis(); }

View File

@ -314,6 +314,7 @@ void webHandleConfigPush() {
Log.verbose(F("WEB : http=%s, bf=%s interval=%s." CR), server.arg( CFG_PARAM_PUSH_HTTP ).c_str(), server.arg( CFG_PARAM_PUSH_BREWFATHER ).c_str(), server.arg( CFG_PARAM_PUSH_INTERVAL ).c_str() );
#endif
myConfig.setHttpPushTarget( server.arg( CFG_PARAM_PUSH_HTTP ).c_str() );
myConfig.setHttpPushTarget2( server.arg( CFG_PARAM_PUSH_HTTP2 ).c_str() );
myConfig.setBrewfatherPushTarget( server.arg( CFG_PARAM_PUSH_BREWFATHER ).c_str() );
myConfig.setPushInterval( server.arg( CFG_PARAM_PUSH_INTERVAL ).c_str() );
myConfig.saveFile();

View File

@ -1 +1 @@
{"mdns":"gravitymon2","id":"ee1bfc","ota-url":"","temp-format":"C","brewfather-push":"","http-push":"http://192.168.1.16:9090/api/v1/V7s7vRXLqnsW3HdxxRuD/telemetry","push-interval":30,"voltage-factor":1.59,"gravity-formula":"0.0*tilt^3+0.0*tilt^2+0.0017978*tilt+0.9436","temp-adjustment-value":0,"gravity-temp-adjustment":false,"gyro-calibration-data":{"ax":-4814,"ay":1143,"az":2270,"gx":47,"gy":-25,"gz":47},"angle":90.38,"gravity":1.1106,"battery":4.24}
{"mdns":"gravitymon2","id":"ee1bfc","ota-url":"","temp-format":"C","brewfather-push":"","http-push":"http://192.168.1.16:9090/api/v1/V7s7vRXLqnsW3HdxxRuD/telemetry","http-push2":"http://192.168.1.16:9090/test", "push-interval":30,"voltage-factor":1.59,"gravity-formula":"0.0*tilt^3+0.0*tilt^2+0.0017978*tilt+0.9436","temp-adjustment-value":0,"gravity-temp-adjustment":false,"gyro-calibration-data":{"ax":-4814,"ay":1143,"az":2270,"gx":47,"gy":-25,"gz":47},"angle":90.38,"gravity":1.1106,"battery":4.24}