Added btn on test page

This commit is contained in:
Magnus Persson 2022-03-16 19:05:11 +01:00
parent 3717561466
commit d4452e1d59
5 changed files with 51 additions and 7 deletions

View File

@ -66,11 +66,24 @@
</div>
</div>
<div class="form-group row">
</div>
<div class="form-group row">
<div class="col-sm-8">
<button class="btn btn-primary" id="test-btn">Test</button>
</div>
</div>
<hr class="my-4">
</div>
<script type="text/javascript">
window.onload = getConfig;
$('#spinner').hide();
function clearLog() {
$("#preview").text("");
}
function appendLog(log) {
doc = $("#preview").text();
@ -79,12 +92,14 @@
}
// Get the configuration values from the API
function getConfig() {
$("#test-btn").click(function(e) {
clearLog();
appendLog( "Starting test of push targets" );
var url = "/api/status";
//var url = "/test/status.json";
$('#spinner').show();
$("#test-btn").prop("disabled", true);
$('#spinner').show();
$.getJSON(url, function (cfg) {
var id = cfg["id"];
console.log( id );
@ -95,14 +110,17 @@
testHttp( id, "brewfather" );
testInfluxdb( id );
testMqtt( id );
$('#spinner').hide();
$("#test-btn").prop("disabled", false);
})
.fail(function () {
showError('Unable to get data from the device.');
$('#spinner').hide();
$("#test-btn").prop("disabled", false);
})
.always(function() {
$('#spinner').hide();
});
}
});
function testMqtt(id) {
var url = "/api/test/push";

View File

@ -1 +1 @@
<!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>Beer Gravity Monitor</title><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous"><script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script><script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-fQybjgWLrvvRgtW6bFlB7jaZrFsaBXjsOMm/tB9LTS58ONXgqbR9W8oWht/amnpF" crossorigin="anonymous"></script></head><body class="py-4"><!-- START MENU --><nav class="navbar navbar-expand-sm navbar-dark bg-primary"><a class="navbar-brand" href="/index.htm">Beer Gravity Monitor</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button><div class="collapse navbar-collapse" id="navbar"><ul class="navbar-nav mr-auto"><li class="nav-item"><a class="nav-link" href="javascript:history.back()">Back to configuration</a></li></ul></div><div class="spinner-border text-light" id="spinner" role="status"></div></nav><!-- START MAIN INDEX --><div class="container"><hr class="my-2"><div class="alert alert-success alert-dismissible fade hide show d-none" role="alert" id="alert"><div id="alert-msg">...</div><button type="button" id="alert-btn" class="close" aria-label="Close"><span aria-hidden="true">&times;</span></button></div><script type="text/javascript">function showError(s){$("#alert").removeClass("alert-success").addClass("alert-danger").removeClass("d-none").addClass("show"),$("#alert-msg").text(s)}function showSuccess(s){$("#alert").addClass("alert-success").removeClass("alert-danger").removeClass("d-none").addClass("show"),$("#alert-msg").text(s)}$("#alert-btn").click(function(s){$("#alert").addClass("d-none").removeClass("show")})</script><div><div class="card"><div class="card-body"><pre class="card-preview" id="preview" name="preview"></pre></div></div><hr class="my-4"></div><script type="text/javascript">function appendLog(t){doc=$("#preview").text(),doc+=t+"\n",$("#preview").text(doc)}function getConfig(){appendLog("Starting test of push targets");var t="/api/status";$("#spinner").show(),$.getJSON(t,function(t){var e=t.id;console.log(e),testHttp(e,"http-1"),testHttp(e,"http-2"),testHttp(e,"http-3"),testHttp(e,"brewfather"),testInfluxdb(e),testMqtt(e)}).fail(function(){showError("Unable to get data from the device.")}).always(function(){$("#spinner").hide()})}function testMqtt(t){var e="/api/test/push";e+="?id="+t+"&format=mqtt",$.getJSON(e,function(t){var e=t.code,r=t.success,o=t.enabled;appendLog(o?r?"Push target 'mqtt' successful":-3==e?"Push target 'mqtt' failed to connect":-4==e?"Push target 'mqtt' failed with error timeout":-10==e?"Push target 'mqtt' failed with error denied":"Push target 'mqtt' failed with error code "+e:"Push target 'mqtt' is not configured/used")}).fail(function(){appendLog("Failed to test push target 'influxdb'")})}function testInfluxdb(t){var e="/api/test/push";e+="?id="+t+"&format=influxdb",$.getJSON(e,function(t){var e=t.code,r=t.success,o=t.enabled;appendLog(o?r?"Push target 'influxdb' successful":400==e?"Push target 'influxdb' failed with error code 400, bad request":401==e?"Push target 'influxdb' failed with error code 401, unauthorized":404==e?"Push target 'influxdb' failed with error code 404, url not found":"Push target 'influxdb' failed with error code "+e:"Push target 'influxdb' is not configured/used")}).fail(function(){appendLog("Failed to test push target 'influxdb'")})}function testHttp(t,i){var e="/api/test/push";e+="?id="+t+"&format="+i,$.getJSON(e,function(t){var e=t.code,r=t.success,o=t.enabled;appendLog(o?r?"Push target '"+i+"' successful":400==e?"Push target '"+i+"' failed with error code 400, bad request":401==e?"Push target '"+i+"' failed with error code 401, unauthorized":404==e?"Push target '"+i+"' failed with error code 404, url not found":"Push target '"+i+"' failed with error code "+e:"Push target '"+i+"' is not configured/used")}).fail(function(){appendLog("Failed to test push target '"+i+"'")})}window.onload=getConfig</script><!-- START FOOTER --><div class="container-fluid themed-container bg-primary text-light">(C) Copyright 2021-22 Magnus Persson</div></div></body></html>
<!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>Beer Gravity Monitor</title><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous"><script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script><script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-fQybjgWLrvvRgtW6bFlB7jaZrFsaBXjsOMm/tB9LTS58ONXgqbR9W8oWht/amnpF" crossorigin="anonymous"></script></head><body class="py-4"><!-- START MENU --><nav class="navbar navbar-expand-sm navbar-dark bg-primary"><a class="navbar-brand" href="/index.htm">Beer Gravity Monitor</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button><div class="collapse navbar-collapse" id="navbar"><ul class="navbar-nav mr-auto"><li class="nav-item"><a class="nav-link" href="javascript:history.back()">Back to configuration</a></li></ul></div><div class="spinner-border text-light" id="spinner" role="status"></div></nav><!-- START MAIN INDEX --><div class="container"><hr class="my-2"><div class="alert alert-success alert-dismissible fade hide show d-none" role="alert" id="alert"><div id="alert-msg">...</div><button type="button" id="alert-btn" class="close" aria-label="Close"><span aria-hidden="true">&times;</span></button></div><script type="text/javascript">function showError(s){$("#alert").removeClass("alert-success").addClass("alert-danger").removeClass("d-none").addClass("show"),$("#alert-msg").text(s)}function showSuccess(s){$("#alert").addClass("alert-success").removeClass("alert-danger").removeClass("d-none").addClass("show"),$("#alert-msg").text(s)}$("#alert-btn").click(function(s){$("#alert").addClass("d-none").removeClass("show")})</script><div><div class="card"><div class="card-body"><pre class="card-preview" id="preview" name="preview"></pre></div></div><div class="form-group row"></div><div class="form-group row"><div class="col-sm-8"><button class="btn btn-primary" id="test-btn">Test</button></div></div><hr class="my-4"></div><script type="text/javascript">function clearLog(){$("#preview").text("")}function appendLog(t){doc=$("#preview").text(),doc+=t+"\n",$("#preview").text(doc)}function testMqtt(t){var e="/api/test/push";e+="?id="+t+"&format=mqtt",$.getJSON(e,function(t){var e=t.code,r=t.success,i=t.enabled;appendLog(i?r?"Push target 'mqtt' successful":-3==e?"Push target 'mqtt' failed to connect":-4==e?"Push target 'mqtt' failed with error timeout":-10==e?"Push target 'mqtt' failed with error denied":"Push target 'mqtt' failed with error code "+e:"Push target 'mqtt' is not configured/used")}).fail(function(){appendLog("Failed to test push target 'influxdb'")})}function testInfluxdb(t){var e="/api/test/push";e+="?id="+t+"&format=influxdb",$.getJSON(e,function(t){var e=t.code,r=t.success,i=t.enabled;appendLog(i?r?"Push target 'influxdb' successful":400==e?"Push target 'influxdb' failed with error code 400, bad request":401==e?"Push target 'influxdb' failed with error code 401, unauthorized":404==e?"Push target 'influxdb' failed with error code 404, url not found":"Push target 'influxdb' failed with error code "+e:"Push target 'influxdb' is not configured/used")}).fail(function(){appendLog("Failed to test push target 'influxdb'")})}function testHttp(t,s){var e="/api/test/push";e+="?id="+t+"&format="+s,$.getJSON(e,function(t){var e=t.code,r=t.success,i=t.enabled;appendLog(i?r?"Push target '"+s+"' successful":400==e?"Push target '"+s+"' failed with error code 400, bad request":401==e?"Push target '"+s+"' failed with error code 401, unauthorized":404==e?"Push target '"+s+"' failed with error code 404, url not found":"Push target '"+s+"' failed with error code "+e:"Push target '"+s+"' is not configured/used")}).fail(function(){appendLog("Failed to test push target '"+s+"'")})}$("#spinner").hide(),$("#test-btn").click(function(t){clearLog(),appendLog("Starting test of push targets");var e="/api/status";$("#test-btn").prop("disabled",!0),$("#spinner").show(),$.getJSON(e,function(t){var e=t.id;console.log(e),testHttp(e,"http-1"),testHttp(e,"http-2"),testHttp(e,"http-3"),testHttp(e,"brewfather"),testInfluxdb(e),testMqtt(e),$("#spinner").hide(),$("#test-btn").prop("disabled",!1)}).fail(function(){showError("Unable to get data from the device."),$("#spinner").hide(),$("#test-btn").prop("disabled",!1)}).always(function(){})})</script><!-- START FOOTER --><div class="container-fluid themed-container bg-primary text-light">(C) Copyright 2021-22 Magnus Persson</div></div></body></html>

View File

@ -7,7 +7,7 @@ Welcome to GravityMon's documentation!
######################################
.. note::
This documentation reflects **v0.9**. Last updated 2022-03-12
This documentation reflects **v0.9**. Last updated 2022-03-14
GravityMon is used to measure gravity and temperature during fermentation of beer and report the progress. The graph below is
an example on how the fermentation process can be tracked. This is from my last brew that was over on a few days. The graph is rendered using

View File

@ -7,6 +7,7 @@ v0.9.0
------
* Added one http push target that uses HTTP GET. This can be used with ubidots or blynk api's.
* Added function to test push targets from configuration page. It will send data and show the return code as a first step.
* Added documetation on how to integrate with Blynk.io using http get.
* Experimental release of firmware using an esp32 instead of esp8266
* Merged index and device pages into one so that all the needed information is available on the index page.
* Removed api for device (/api/device), it's now merged into the /api/status api.

View File

@ -195,3 +195,28 @@ you want to include. The example below sends 5 different values to the channel i
"field4": ${battery},
"field5": ${rssi}
}
Blynk.io
++++++++
Blynk is an IoT service which can be updated via http get. It also has an mobile device that can be used to show the data.
In order to use this platform you need to create a device which can be used to receive the data. Each device will have a
unique token that is used to identify it. You need to use the HTTP GET option (http-3) on the device for this to work. Enter the
following URL in the UI. This will allow us to update several data points at once. I usually enter the token in the ``token2`` field
so the format template does not contain any sensitive data and it's easier to switch to another device.
.. code-block::
http://blynk.cloud/external/api/batch/update
In the format editor you can enter this template which will send 3 values to blynk. You can add as many as you want but make sure
these are configured on the device with the correct validation option such as data type and range. The value should be on one line
starting with a ``?``. This string will be added to the URL above when doing the post. You can add more values if you want.
.. code-block::
?token=${token2}&v1=${temp}&v2=${gravity}&v3=${angle}