diff --git a/html/config.htm b/html/config.htm index 08fc724..6bc5fa9 100644 --- a/html/config.htm +++ b/html/config.htm @@ -196,6 +196,15 @@
+
+ +
+ +
+
+ +
+
@@ -223,8 +232,6 @@
-
-
@@ -503,6 +510,7 @@ $('#modal-http').on('hide.bs.modal', function (event) { if( cfg["gravity-format"] == "G" ) $("#gravity-format-g").click(); else $("#gravity-format-p").click(); $("#ota-url").val(cfg["ota-url"]); + $("#token").val(cfg["token"]); $("#http-push").val(cfg["http-push"]); $("#http-push-h1").val(cfg["http-push-h1"]); $("#http-push-h2").val(cfg["http-push-h2"]); diff --git a/html/config.min.htm b/html/config.min.htm index 969958e..df5e584 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/format.htm b/html/format.htm index 04e71fb..c19070d 100644 --- a/html/format.htm +++ b/html/format.htm @@ -148,10 +148,11 @@ // Test the calibration $("#test-btn").click(function(e) { var doc = $("#format").val(); - doc = doc.replaceAll("${mdns}", "gravmon2"); + doc = doc.replaceAll("${mdns}", "testing"); doc = doc.replaceAll("${id}", "e4a344"); doc = doc.replaceAll("${sleep-interval}", "300"); doc = doc.replaceAll("${temp}", "21.1"); + doc = doc.replaceAll("${token}", "a-token"); doc = doc.replaceAll("${temp-c}", "21.1"); doc = doc.replaceAll("${temp-f}", "51.3"); doc = doc.replaceAll("${temp-unit}", "C"); diff --git a/html/format.min.htm b/html/format.min.htm index 0840663..b1a97fb 100644 --- a/html/format.min.htm +++ b/html/format.min.htm @@ -1,2 +1,2 @@ Beer Gravity Monitor


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

(C) Copyright 2021-22 Magnus Persson
\ No newline at end of file diff --git a/src/config.cpp b/src/config.cpp index 7568e0f..b192267 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -71,6 +71,7 @@ void Config::createJson(DynamicJsonDocument& doc) { doc[PARAM_PASS] = getWifiPass(); doc[PARAM_TEMPFORMAT] = String(getTempFormat()); doc[PARAM_PUSH_BREWFATHER] = getBrewfatherPushUrl(); + doc[PARAM_TOKEN] = getToken(); doc[PARAM_PUSH_HTTP] = getHttpUrl(); doc[PARAM_PUSH_HTTP_H1] = getHttpHeader(0); doc[PARAM_PUSH_HTTP_H2] = getHttpHeader(1); @@ -206,6 +207,7 @@ bool Config::loadFile() { if (!doc[PARAM_PUSH_BREWFATHER].isNull()) setBrewfatherPushUrl(doc[PARAM_PUSH_BREWFATHER]); + if (!doc[PARAM_TOKEN].isNull()) setToken(doc[PARAM_TOKEN]); if (!doc[PARAM_PUSH_HTTP].isNull()) setHttpUrl(doc[PARAM_PUSH_HTTP]); if (!doc[PARAM_PUSH_HTTP_H1].isNull()) setHttpHeader(doc[PARAM_PUSH_HTTP_H1], 0); diff --git a/src/config.hpp b/src/config.hpp index 08ea6fc..c7e29f7 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -104,6 +104,8 @@ class Config { // Push target settings String _brewfatherPushUrl = ""; + String _token = ""; + String _httpUrl = ""; String _httpHeader[2] = { "Content-Type: application/json", "" }; String _http2Url = ""; @@ -174,6 +176,13 @@ class Config { return _brewfatherPushUrl.length() ? true : false; } + // Token parameter + const char* getToken() { return _token.c_str(); } + void setToken(String s) { + _token = s; + _saveNeeded = true; + } + // Standard HTTP const char* getHttpUrl() { return _httpUrl.c_str(); } void setHttpUrl(String s) { diff --git a/src/resources.hpp b/src/resources.hpp index b95a1d6..3263b10 100644 --- a/src/resources.hpp +++ b/src/resources.hpp @@ -32,6 +32,7 @@ SOFTWARE. #define PARAM_PASS "wifi-pass" #define PARAM_RUNTIME_AVERAGE "runtime-average" #define PARAM_PUSH_BREWFATHER "brewfather-push" +#define PARAM_TOKEN "token" #define PARAM_PUSH_HTTP "http-push" #define PARAM_PUSH_HTTP_H1 "http-push-h1" #define PARAM_PUSH_HTTP_H2 "http-push-h2" diff --git a/src/templating.cpp b/src/templating.cpp index 9360cac..6c3debb 100644 --- a/src/templating.cpp +++ b/src/templating.cpp @@ -35,7 +35,7 @@ const char iSpindleFormat[] PROGMEM = "{" "\"name\" : \"${mdns}\", " "\"ID\": \"${id}\", " - "\"token\" : \"gravmon\", " + "\"token\" : \"${token}\", " "\"interval\": ${sleep-interval}, " "\"temperature\": ${temp}, " "\"temp-units\": \"${temp-unit}\", " @@ -88,6 +88,7 @@ void TemplatingEngine::initialize(float angle, float gravitySG, float corrGravit // Names setVal(TPL_MDNS, myConfig.getMDNS()); setVal(TPL_ID, myConfig.getID()); + setVal(TPL_TOKEN, myConfig.getToken()); // Temperature if (myConfig.isTempC()) { diff --git a/src/templating.hpp b/src/templating.hpp index 7b02192..fa87cd1 100644 --- a/src/templating.hpp +++ b/src/templating.hpp @@ -34,6 +34,7 @@ SOFTWARE. // Templating variables #define TPL_MDNS "${mdns}" #define TPL_ID "${id}" +#define TPL_TOKEN "${token}" #define TPL_SLEEP_INTERVAL "${sleep-interval}" #define TPL_TEMP "${temp}" #define TPL_TEMP_C "${temp-c}" @@ -71,7 +72,7 @@ class TemplatingEngine { String val; }; - KeyVal items[19] = {{TPL_MDNS, ""}, {TPL_ID, ""}, + KeyVal items[20] = {{TPL_MDNS, ""}, {TPL_ID, ""}, {TPL_SLEEP_INTERVAL, ""}, {TPL_TEMP, ""}, {TPL_TEMP_C, ""}, {TPL_TEMP_F, ""}, {TPL_TEMP_UNITS, ""}, {TPL_BATTERY, ""}, @@ -80,7 +81,7 @@ class TemplatingEngine { {TPL_GRAVITY, ""}, {TPL_GRAVITY_G, ""}, {TPL_GRAVITY_P, ""}, {TPL_GRAVITY_CORR, ""}, {TPL_GRAVITY_CORR_G, ""}, {TPL_GRAVITY_CORR_P, ""}, - {TPL_GRAVITY_UNIT, ""}}; + {TPL_GRAVITY_UNIT, ""}, {TPL_TOKEN, ""}}; char buffer[20]; String baseTemplate; diff --git a/src/webserver.cpp b/src/webserver.cpp index 2c10c63..8051f75 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -365,6 +365,8 @@ void WebServerHandler::webHandleConfigPush() { Log.verbose(F("WEB : %s." CR), getRequestArguments().c_str()); #endif + if (_server->hasArg(PARAM_TOKEN)) + myConfig.setToken(_server->arg(PARAM_TOKEN).c_str()); if (_server->hasArg(PARAM_PUSH_HTTP)) myConfig.setHttpUrl(_server->arg(PARAM_PUSH_HTTP).c_str()); if (_server->hasArg(PARAM_PUSH_HTTP_H1)) diff --git a/src_docs/source/api.rst b/src_docs/source/api.rst index 90cccdc..3f32f4c 100644 --- a/src_docs/source/api.rst +++ b/src_docs/source/api.rst @@ -23,6 +23,7 @@ Other parameters are the same as in the configuration guide. "ota-url": "http://192.168.1.50:80/firmware/gravmon/", "temp-format": "C", "brewfather-push": "http://log.brewfather.net/stream?id=Qwerty", + "token": "token", "http-push": "http://192.168.1.50:9090/api/v1/Qwerty/telemetry", "http-push-h1": "header: value", "http-push-h2": "header: value", @@ -273,6 +274,7 @@ The requests package converts the json to standard form post format. url = "http://" + host + "/api/config/push" json = { "id": id, + "token": "", "http-push": "http://192.168.1.1/ispindel", "http-push2": "", "http-push-h1": "", diff --git a/test/config.json b/test/config.json index 2f4ae9c..ed87f78 100644 --- a/test/config.json +++ b/test/config.json @@ -10,6 +10,7 @@ "http-push2": "http://192.168.1.10/ispindel", "http-push2-h1": "Second", "http-push2-h2": "First", + "token": "mytoken", "influxdb2-push": "http://192.168.1.10:8086", "influxdb2-org": "hello", "influxdb2-bucket": "spann",