diff --git a/html/config.htm b/html/config.htm index e6e402c..2e8a759 100644 --- a/html/config.htm +++ b/html/config.htm @@ -175,7 +175,7 @@
- +
@@ -184,7 +184,7 @@
- +
@@ -193,8 +193,6 @@
-
-
@@ -204,6 +202,22 @@
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+
@@ -617,12 +631,14 @@ function checkHeader(input) { else $("#gravity-format-p").click(); $("#ota-url").val(cfg["ota-url"]); $("#token").val(cfg["token"]); + $("#token2").val(cfg["token2"]); $("#http-push").val(cfg["http-push"]); $("#http-push-h1").val(cfg["http-push-h1"]); $("#http-push-h2").val(cfg["http-push-h2"]); $("#http-push2").val(cfg["http-push2"]); $("#http-push2-h1").val(cfg["http-push2-h1"]); $("#http-push2-h2").val(cfg["http-push2-h2"]); + $("#http-push3").val(cfg["http-push3"]); $("#brewfather-push").val(cfg["brewfather-push"]); $("#influxdb2-push").val(cfg["influxdb2-push"]); $("#influxdb2-org").val(cfg["influxdb2-org"]); diff --git a/html/config.min.htm b/html/config.min.htm index 4c71ec7..cca456a 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 f9b8ce8..4561a76 100644 --- a/html/format.htm +++ b/html/format.htm @@ -74,6 +74,7 @@ + @@ -81,8 +82,9 @@

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


(C) Copyright 2021-22 Magnus Persson
\ No newline at end of file diff --git a/html/test.htm b/html/test.htm index f4d7230..b11d6e1 100644 --- a/html/test.htm +++ b/html/test.htm @@ -91,6 +91,7 @@ testHttp( id, "http-1" ); testHttp( id, "http-2" ); + testHttp( id, "http-3" ); testHttp( id, "brewfather" ); testInfluxdb( id ); testMqtt( id ); diff --git a/html/test.min.htm b/html/test.min.htm index 407d881..5c789ea 100644 --- a/html/test.min.htm +++ b/html/test.min.htm @@ -1 +1 @@ -Beer Gravity Monitor


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


(C) Copyright 2021-22 Magnus Persson
\ No newline at end of file diff --git a/src/config.cpp b/src/config.cpp index fcad595..e6fd4c7 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -74,12 +74,14 @@ void Config::createJson(DynamicJsonDocument& doc) { doc[PARAM_TEMPFORMAT] = String(getTempFormat()); doc[PARAM_PUSH_BREWFATHER] = getBrewfatherPushUrl(); doc[PARAM_TOKEN] = getToken(); + doc[PARAM_TOKEN2] = getToken2(); doc[PARAM_PUSH_HTTP] = getHttpUrl(); doc[PARAM_PUSH_HTTP_H1] = getHttpHeader(0); doc[PARAM_PUSH_HTTP_H2] = getHttpHeader(1); doc[PARAM_PUSH_HTTP2] = getHttp2Url(); doc[PARAM_PUSH_HTTP2_H1] = getHttp2Header(0); doc[PARAM_PUSH_HTTP2_H2] = getHttp2Header(1); + doc[PARAM_PUSH_HTTP3] = getHttp3Url(); doc[PARAM_PUSH_INFLUXDB2] = getInfluxDb2PushUrl(); doc[PARAM_PUSH_INFLUXDB2_ORG] = getInfluxDb2PushOrg(); doc[PARAM_PUSH_INFLUXDB2_BUCKET] = getInfluxDb2PushBucket(); @@ -215,6 +217,7 @@ bool Config::loadFile() { setBrewfatherPushUrl(doc[PARAM_PUSH_BREWFATHER]); if (!doc[PARAM_TOKEN].isNull()) setToken(doc[PARAM_TOKEN]); + if (!doc[PARAM_TOKEN2].isNull()) setToken2(doc[PARAM_TOKEN2]); 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); @@ -225,6 +228,7 @@ bool Config::loadFile() { setHttp2Header(doc[PARAM_PUSH_HTTP2_H1], 0); if (!doc[PARAM_PUSH_HTTP2_H2].isNull()) setHttp2Header(doc[PARAM_PUSH_HTTP2_H2], 1); + if (!doc[PARAM_PUSH_HTTP3].isNull()) setHttp3Url(doc[PARAM_PUSH_HTTP3]); if (!doc[PARAM_PUSH_INFLUXDB2].isNull()) setInfluxDb2PushUrl(doc[PARAM_PUSH_INFLUXDB2]); diff --git a/src/config.hpp b/src/config.hpp index 48cd427..68486a1 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -109,11 +109,13 @@ class Config { String _brewfatherPushUrl = ""; String _token = ""; + String _token2 = ""; String _httpUrl = ""; String _httpHeader[2] = {"Content-Type: application/json", ""}; String _http2Url = ""; String _http2Header[2] = {"Content-Type: application/json", ""}; + String _http3Url = ""; String _influxDb2Url = ""; String _influxDb2Org = ""; @@ -192,6 +194,11 @@ class Config { _token = s; _saveNeeded = true; } + const char* getToken2() { return _token2.c_str(); } + void setToken2(String s) { + _token2 = s; + _saveNeeded = true; + } // Standard HTTP const char* getHttpUrl() { return _httpUrl.c_str(); } @@ -220,6 +227,14 @@ class Config { bool isHttp2Active() { return _http2Url.length() ? true : false; } bool isHttp2SSL() { return _http2Url.startsWith("https://"); } + const char* getHttp3Url() { return _http3Url.c_str(); } + void setHttp3Url(String s) { + _http3Url = s; + _saveNeeded = true; + } + bool isHttp3Active() { return _http3Url.length() ? true : false; } + bool isHttp3SSL() { return _http3Url.startsWith("https://"); } + // InfluxDB2 const char* getInfluxDb2PushUrl() { return _influxDb2Url.c_str(); } void setInfluxDb2PushUrl(String s) { @@ -345,7 +360,7 @@ class Config { } bool isBLEActive() { return _colorBLE.length() ? true : false; } bool isWifiPushActive() { - return (isHttpActive() || isHttp2Active() || isBrewfatherActive() || isInfluxDb2Active() || isMqttActive()) ? true : false; + return (isHttpActive() || isHttp2Active() || isHttp3Active() || isBrewfatherActive() || isInfluxDb2Active() || isMqttActive()) ? true : false; } const RawGyroData& getGyroCalibration() { return _gyroCalibration; } diff --git a/src/pushtarget.cpp b/src/pushtarget.cpp index 4f24151..cd917a0 100644 --- a/src/pushtarget.cpp +++ b/src/pushtarget.cpp @@ -52,16 +52,22 @@ void PushTarget::sendAll(float angle, float gravitySG, float corrGravitySG, if (myConfig.isHttpActive()) { LOG_PERF_START("push-http"); - sendHttp(engine, myConfig.isHttpSSL(), 0); + sendHttpPost(engine, myConfig.isHttpSSL(), 0); LOG_PERF_STOP("push-http"); } if (myConfig.isHttp2Active()) { LOG_PERF_START("push-http2"); - sendHttp(engine, myConfig.isHttp2SSL(), 1); + sendHttpPost(engine, myConfig.isHttp2SSL(), 1); LOG_PERF_STOP("push-http2"); } + if (myConfig.isHttp3Active()) { + LOG_PERF_START("push-http3"); + sendHttpGet(engine, myConfig.isHttp3SSL()); + LOG_PERF_STOP("push-http3"); + } + if (myConfig.isInfluxDb2Active()) { LOG_PERF_START("push-influxdb2"); sendInfluxDb2(engine); @@ -178,9 +184,9 @@ void PushTarget::addHttpHeader(HTTPClient& http, String header) { } // -// Send data to http target +// Send data to http target using POST // -void PushTarget::sendHttp(TemplatingEngine& engine, bool isSecure, int index) { +void PushTarget::sendHttpPost(TemplatingEngine& engine, bool isSecure, int index) { #if !defined(PUSH_DISABLE_LOGGING) Log.notice(F("PUSH: Sending values to http (%s)" CR), index ? "http2" : "http"); @@ -248,12 +254,12 @@ void PushTarget::sendHttp(TemplatingEngine& engine, bool isSecure, int index) { if (_lastCode == 200) { _lastSuccess = true; - Log.notice(F("PUSH: HTTP push successful, response=%d" CR), + Log.notice(F("PUSH: HTTP post successful, response=%d" CR), _lastCode); } else { ErrorFileLog errLog; errLog.addEntry( - "PUSH: HTTP push failed response=" + String(_lastCode) + + "PUSH: HTTP post failed response=" + String(_lastCode) + String(index == 0 ? " (http)" : " (http2)")); } @@ -268,7 +274,71 @@ void PushTarget::sendHttp(TemplatingEngine& engine, bool isSecure, int index) { } // -// Send data to http target +// Send data to http target using GET +// +void PushTarget::sendHttpGet(TemplatingEngine& engine, bool isSecure) { +#if !defined(PUSH_DISABLE_LOGGING) + Log.notice(F("PUSH: Sending values to http3" CR)); +#endif + _lastCode = 0; + _lastSuccess = false; + + String serverPath; + + serverPath = myConfig.getHttp3Url(); + serverPath += engine.create(TemplatingEngine::TEMPLATE_HTTP3); + +#if LOG_LEVEL == 6 && !defined(PUSH_DISABLE_LOGGING) + Log.verbose(F("PUSH: url %s." CR), serverPath.c_str()); +#endif + + if (isSecure) { + Log.notice(F("PUSH: HTTP, SSL enabled without validation." CR)); + _wifiSecure.setInsecure(); + +#if defined (ESP8266) + String host = serverPath.substring(8); // remove the prefix or the probe will fail, it needs a pure host name. + int idx = host.indexOf("/"); + if (idx!=-1) + host = host.substring(0, idx); + + if (_wifiSecure.probeMaxFragmentLength(host, 443, 512)) { + Log.notice(F("PUSH: HTTP server supports smaller SSL buffer." CR)); + _wifiSecure.setBufferSizes(512, 512); + } +#endif + + _httpSecure.begin(_wifiSecure, serverPath); + _httpSecure.setTimeout(myHardwareConfig.getPushTimeout() * 1000); + _lastCode = _httpSecure.GET(); + } else { + _http.begin(_wifi, serverPath); + _http.setTimeout(myHardwareConfig.getPushTimeout() * 1000); + _lastCode = _http.GET(); + } + + if (_lastCode == 200) { + _lastSuccess = true; + Log.notice(F("PUSH: HTTP get successful, response=%d" CR), + _lastCode); + } else { + ErrorFileLog errLog; + errLog.addEntry( + "PUSH: HTTP get failed response=" + String(_lastCode)); + } + + if (isSecure) { + _httpSecure.end(); + _wifiSecure.stop(); + } else { + _http.end(); + _wifi.stop(); + } + tcp_cleanup(); +} + +// +// Send data to mqtt target // void PushTarget::sendMqtt(TemplatingEngine& engine, bool isSecure) { #if !defined(PUSH_DISABLE_LOGGING) diff --git a/src/pushtarget.hpp b/src/pushtarget.hpp index 8f2456c..2c237c2 100644 --- a/src/pushtarget.hpp +++ b/src/pushtarget.hpp @@ -42,7 +42,8 @@ class PushTarget { int _lastCode; bool _lastSuccess; - void sendHttp(TemplatingEngine& engine, bool isSecure, int index); + void sendHttpPost(TemplatingEngine& engine, bool isSecure, int index); + void sendHttpGet(TemplatingEngine& engine, bool isSecure); void addHttpHeader(HTTPClient& http, String header); public: @@ -50,8 +51,9 @@ class PushTarget { float runTime); void sendBrewfather(TemplatingEngine& engine); - void sendHttp1(TemplatingEngine& engine, bool isSecure) { sendHttp(engine, isSecure, 0); } - void sendHttp2(TemplatingEngine& engine, bool isSecure) { sendHttp(engine, isSecure, 1); } + void sendHttp1(TemplatingEngine& engine, bool isSecure) { sendHttpPost(engine, isSecure, 0); } + void sendHttp2(TemplatingEngine& engine, bool isSecure) { sendHttpPost(engine, isSecure, 1); } + void sendHttp3(TemplatingEngine& engine, bool isSecure) { sendHttpGet(engine, isSecure); } void sendInfluxDb2(TemplatingEngine& engine); void sendMqtt(TemplatingEngine& engine, bool isSecure); int getLastCode() { return _lastCode; } diff --git a/src/resources.hpp b/src/resources.hpp index 4c284de..5a90b61 100644 --- a/src/resources.hpp +++ b/src/resources.hpp @@ -34,12 +34,14 @@ SOFTWARE. #define PARAM_RUNTIME_AVERAGE "runtime-average" #define PARAM_PUSH_BREWFATHER "brewfather-push" #define PARAM_TOKEN "token" +#define PARAM_TOKEN2 "token2" #define PARAM_PUSH_HTTP "http-push" #define PARAM_PUSH_HTTP_H1 "http-push-h1" #define PARAM_PUSH_HTTP_H2 "http-push-h2" #define PARAM_PUSH_HTTP2 "http-push2" #define PARAM_PUSH_HTTP2_H1 "http-push2-h1" #define PARAM_PUSH_HTTP2_H2 "http-push2-h2" +#define PARAM_PUSH_HTTP3 "http-push3" #define PARAM_PUSH_INFLUXDB2 "influxdb2-push" #define PARAM_PUSH_INFLUXDB2_ORG "influxdb2-org" #define PARAM_PUSH_INFLUXDB2_BUCKET "influxdb2-bucket" @@ -81,6 +83,7 @@ SOFTWARE. #define PARAM_HW_PUSH_TIMEOUT "push-timeout" #define PARAM_FORMAT_HTTP1 "http-1" #define PARAM_FORMAT_HTTP2 "http-2" +#define PARAM_FORMAT_HTTP3 "http-3" #define PARAM_FORMAT_BREWFATHER "brewfather" #define PARAM_FORMAT_INFLUXDB "influxdb" #define PARAM_FORMAT_MQTT "mqtt" diff --git a/src/templating.cpp b/src/templating.cpp index 9e79b25..9a91971 100644 --- a/src/templating.cpp +++ b/src/templating.cpp @@ -30,7 +30,7 @@ SOFTWARE. #include #endif -// Use iSpindle format for compatibility +// Use iSpindle format for compatibility, HTTP POST const char iSpindleFormat[] PROGMEM = "{" "\"name\" : \"${mdns}\", " @@ -48,6 +48,22 @@ const char iSpindleFormat[] PROGMEM = "\"run-time\": ${run-time} " "}"; +// Format for an HTTP GET +const char iHttpGetFormat[] PROGMEM = + "?name=${mdns}" + "&id=${id}" + "&token=${token2}" + "&interval=${sleep-interval}" + "&temperature=${temp}" + "&temp-units=${temp-unit}" + "&gravity=${gravity}" + "&angle=${angle}" + "&battery=${battery}" + "&rssi=${rssi}" + "&corr-gravity=${corr-gravity}" + "&gravity-unit=${gravity-unit}" + "&run-time=${run-time}"; + const char brewfatherFormat[] PROGMEM = "{" "\"name\": \"${mdns}\"," @@ -89,6 +105,7 @@ void TemplatingEngine::initialize(float angle, float gravitySG, float corrGravit setVal(TPL_MDNS, myConfig.getMDNS()); setVal(TPL_ID, myConfig.getID()); setVal(TPL_TOKEN, myConfig.getToken()); + setVal(TPL_TOKEN2, myConfig.getToken2()); // Temperature if (myConfig.isTempC()) { @@ -151,6 +168,10 @@ const String& TemplatingEngine::create(TemplatingEngine::Templates idx) { baseTemplate = String(iSpindleFormat); fname = TPL_FNAME_HTTP2; break; + case TEMPLATE_HTTP3: + baseTemplate = String(iHttpGetFormat); + fname = TPL_FNAME_HTTP3; + break; case TEMPLATE_BREWFATHER: baseTemplate = String(brewfatherFormat); //fname = TPL_FNAME_BREWFATHER; diff --git a/src/templating.hpp b/src/templating.hpp index fa87cd1..5a40ceb 100644 --- a/src/templating.hpp +++ b/src/templating.hpp @@ -35,6 +35,7 @@ SOFTWARE. #define TPL_MDNS "${mdns}" #define TPL_ID "${id}" #define TPL_TOKEN "${token}" +#define TPL_TOKEN2 "${token2}" #define TPL_SLEEP_INTERVAL "${sleep-interval}" #define TPL_TEMP "${temp}" #define TPL_TEMP_C "${temp-c}" @@ -55,11 +56,13 @@ SOFTWARE. #define TPL_FNAME_HTTP1 "/http-1.tpl" #define TPL_FNAME_HTTP2 "/http-2.tpl" +#define TPL_FNAME_HTTP3 "/http-3.tpl" // #define TPL_FNAME_BREWFATHER "/brewfather.tpl" #define TPL_FNAME_INFLUXDB "/influxdb.tpl" #define TPL_FNAME_MQTT "/mqtt.tpl" extern const char iSpindleFormat[] PROGMEM; +extern const char iHttpGetFormat[] PROGMEM; extern const char brewfatherFormat[] PROGMEM; extern const char influxDbFormat[] PROGMEM; extern const char mqttFormat[] PROGMEM; @@ -72,7 +75,7 @@ class TemplatingEngine { String val; }; - KeyVal items[20] = {{TPL_MDNS, ""}, {TPL_ID, ""}, + KeyVal items[21] = {{TPL_MDNS, ""}, {TPL_ID, ""}, {TPL_SLEEP_INTERVAL, ""}, {TPL_TEMP, ""}, {TPL_TEMP_C, ""}, {TPL_TEMP_F, ""}, {TPL_TEMP_UNITS, ""}, {TPL_BATTERY, ""}, @@ -81,7 +84,8 @@ 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_TOKEN, ""}}; + {TPL_GRAVITY_UNIT, ""}, {TPL_TOKEN, ""}, + {TPL_TOKEN2, ""} }; char buffer[20]; String baseTemplate; @@ -128,9 +132,10 @@ class TemplatingEngine { enum Templates { TEMPLATE_HTTP1 = 0, TEMPLATE_HTTP2 = 1, - TEMPLATE_BREWFATHER = 2, - TEMPLATE_INFLUX = 3, - TEMPLATE_MQTT = 4 + TEMPLATE_HTTP3 = 2, + TEMPLATE_BREWFATHER = 3, + TEMPLATE_INFLUX = 4, + TEMPLATE_MQTT = 5 }; void initialize(float angle, float gravitySG, float corrGravitySG, diff --git a/src/webserver.cpp b/src/webserver.cpp index 7ca4b73..2f84b32 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -285,6 +285,7 @@ void WebServerHandler::webHandleStatus() { doc[PARAM_RSSI] = WiFi.RSSI(); doc[PARAM_SLEEP_INTERVAL] = myConfig.getSleepInterval(); doc[PARAM_TOKEN] = myConfig.getToken(); + doc[PARAM_TOKEN2] = myConfig.getToken2(); doc[PARAM_APP_VER] = CFG_APPVER; doc[PARAM_MDNS] = myConfig.getMDNS(); @@ -413,6 +414,8 @@ void WebServerHandler::webHandleConfigPush() { if (_server->hasArg(PARAM_TOKEN)) myConfig.setToken(_server->arg(PARAM_TOKEN).c_str()); + if (_server->hasArg(PARAM_TOKEN2)) + myConfig.setToken2(_server->arg(PARAM_TOKEN2).c_str()); if (_server->hasArg(PARAM_PUSH_HTTP)) myConfig.setHttpUrl(_server->arg(PARAM_PUSH_HTTP).c_str()); if (_server->hasArg(PARAM_PUSH_HTTP_H1)) @@ -425,6 +428,8 @@ void WebServerHandler::webHandleConfigPush() { myConfig.setHttp2Header(_server->arg(PARAM_PUSH_HTTP2_H1).c_str(), 0); if (_server->hasArg(PARAM_PUSH_HTTP2_H2)) myConfig.setHttp2Header(_server->arg(PARAM_PUSH_HTTP2_H2).c_str(), 1); + if (_server->hasArg(PARAM_PUSH_HTTP3)) + myConfig.setHttp3Url(_server->arg(PARAM_PUSH_HTTP3).c_str()); if (_server->hasArg(PARAM_PUSH_BREWFATHER)) myConfig.setBrewfatherPushUrl(_server->arg(PARAM_PUSH_BREWFATHER).c_str()); if (_server->hasArg(PARAM_PUSH_INFLUXDB2)) @@ -710,6 +715,8 @@ void WebServerHandler::webHandleConfigFormatWrite() { success = writeFile(TPL_FNAME_HTTP1, _server->arg(PARAM_FORMAT_HTTP1)); } else if (_server->hasArg(PARAM_FORMAT_HTTP2)) { success = writeFile(TPL_FNAME_HTTP2, _server->arg(PARAM_FORMAT_HTTP2)); + } else if (_server->hasArg(PARAM_FORMAT_HTTP3)) { + success = writeFile(TPL_FNAME_HTTP3, _server->arg(PARAM_FORMAT_HTTP3)); } else if (_server->hasArg(PARAM_FORMAT_INFLUXDB)) { success = writeFile(TPL_FNAME_INFLUXDB, _server->arg(PARAM_FORMAT_INFLUXDB)); @@ -774,6 +781,9 @@ void WebServerHandler::webHandleTestPush() { } else if (!type.compareTo(PARAM_FORMAT_HTTP2) && myConfig.isHttp2Active()) { push.sendHttp2(engine, myConfig.isHttp2SSL()); enabled = true; + } else if (!type.compareTo(PARAM_FORMAT_HTTP3) && myConfig.isHttp3Active()) { + push.sendHttp3(engine, myConfig.isHttp3SSL()); + enabled = true; } else if (!type.compareTo(PARAM_FORMAT_INFLUXDB) && myConfig.isInfluxDb2Active()) { push.sendInfluxDb2(engine); enabled = true; @@ -868,6 +878,12 @@ void WebServerHandler::webHandleConfigFormatRead() { else doc[PARAM_FORMAT_HTTP2] = urlencode(String(&iSpindleFormat[0])); + s = readFile(TPL_FNAME_HTTP3); + if (s.length()) + doc[PARAM_FORMAT_HTTP3] = urlencode(s); + else + doc[PARAM_FORMAT_HTTP3] = urlencode(String(&iHttpGetFormat[0])); + /*s = readFile(TPL_FNAME_BREWFATHER); if (s.length()) doc[PARAM_FORMAT_BREWFATHER] = urlencode(s); diff --git a/src_docs/source/advanced.rst b/src_docs/source/advanced.rst index 49028dc..618c75a 100644 --- a/src_docs/source/advanced.rst +++ b/src_docs/source/advanced.rst @@ -35,6 +35,12 @@ These are the format keys available for use in the format. * - ${mdns} - Name of the device - gravmon2 + * - ${token} + - Token + - any value + * - ${token2} + - Token 2 + - any value * - ${id} - Unique id of the device - e422a3 diff --git a/src_docs/source/api.rst b/src_docs/source/api.rst index 187bc70..6cd1478 100644 --- a/src_docs/source/api.rst +++ b/src_docs/source/api.rst @@ -26,12 +26,14 @@ Other parameters are the same as in the configuration guide. "ble": "color", "brewfather-push": "http://log.brewfather.net/stream?id=Qwerty", "token": "token", + "token2": "token2", "http-push": "http://192.168.1.50:9090/api/v1/Qwerty/telemetry", "http-push-h1": "header: value", "http-push-h2": "header: value", "http-push2": "http://192.168.1.50/ispindel", "http-push2-h1": "header: value", "http-push2-h2": "header: value", + "http-push3": "http://192.168.1.50/ispindel", "influxdb2-push": "http://192.168.1.50:8086", "influxdb2-org": "org", "influxdb2-bucket": "bucket_id", @@ -103,6 +105,7 @@ Other parameters are the same as in the configuration guide. "temp-format": "C", "sleep-mode": false, "token": "token", + "token2": "token2", "rssi": -56, "app-ver": "0.0.0", "mdns": "gravmon", @@ -211,8 +214,11 @@ Payload should be in standard format used for posting a form. Such as as: `id=va .. code-block:: id=ee1bfc + token= + token2= http-push=http://192.168.1.50/ispindel http-push2= + http-push3= http-push-h1= http-push-h2= http-push2-h1= @@ -332,8 +338,10 @@ The requests package converts the json to standard form post format. url = "http://" + host + "/api/config/push" json = { "id": id, "token": "", + "token2": "", "http-push": "http://192.168.1.1/ispindel", "http-push2": "", + "http-push3": "", "http-push-h1": "", "http-push-h2": "", "http-push2-h1": "" diff --git a/src_docs/source/configuration.rst b/src_docs/source/configuration.rst index 05649db..cde4c59 100644 --- a/src_docs/source/configuration.rst +++ b/src_docs/source/configuration.rst @@ -92,13 +92,13 @@ Push Settings When enabling SSL this will not validate the root CA of the remote service, this is a design decision based on two aspects. Enabling CA validation will take 3-4s extra on each connection which means way less battery life, so the decision is to prioritize battery life over security. The data transmitted is not really that sensitive anyway so I belive this is a good balance. -* **HTTP URL 1:** +* **HTTP 1 (POST):** Endpoint to send data via http. Default format used Format used :ref:`data-formats-ispindle`. You can customize the format using :ref:`format-editor`. If you add the prefix `https://` then the device will use SSL when sending data. -* **HTTP URL 2:** +* **HTTP 2 (POST):** Endpoint to send data via http. Default format used :ref:`data-formats-ispindle`. You can customize the format using :ref:`format-editor`. @@ -109,6 +109,16 @@ Push Settings The token is included in the iSpindle JSON format and will be used for both HTTP targets. If you need to have 2 different tokens please use the :ref:`format-editor` to customize the data format. +* **HTTP 3 (GET):** + + Endpoint to send data via http. This is using an HTTP GET request instead of a post. This means that the values are appended to the URL like; http://endpoint?param=value¶m2=value2. You can customize the format using :ref:`format-editor`. + + If you add the prefix `https://` then the device will use SSL when sending data. + +* **Token 2:** + + The token is included in the default format for the HTTP GET url but can be used for any of the formats. For HTTP GET use can use this for an authorization token with for instance ubidots or blynk http api. + * **Brewfather URL:** Endpoint to send data via http to brewfather. Format used :ref:`data-formats-brewfather` diff --git a/src_docs/source/data.rst b/src_docs/source/data.rst index d16d875..55f1557 100644 --- a/src_docs/source/data.rst +++ b/src_docs/source/data.rst @@ -5,8 +5,8 @@ Data Formats .. _data-formats-ispindle: -iSpindle format -=============== +HTTP Post, iSpindle format +========================== This is the format used for standard http posts. @@ -75,6 +75,25 @@ This is the format for Brewfather. See: `Brewfather API docs ,id=,token=&interval=300&temperature=20.1&temp-units=& + gravity=$1.004&angle=45.5&battery=3.96&rssi=-18&corr-gravity=1.004&gravity-unit=&run-time=2.1 + +This is the format template used to create the data above. + +.. code-block:: + + ?name=${mdns}&id=${id}&token=${token2}&interval=${sleep-interval}&temperature=${temp}& + temp-units=${temp-unit}&gravity=${gravity}&angle=${angle}&battery=${battery}&rssi=${rssi}& + corr-gravity=${corr-gravity}&gravity-unit=${gravity-unit}&run-time=${run-time} + + Influx DB v2 ============ @@ -82,14 +101,17 @@ This is the format for InfluxDB v2 .. code-block:: - measurement,host=,device=,temp-format=,gravity-format=SG,gravity=1.0004,corr-gravity=1.0004,angle=45.45,temp=20.1,battery=3.96,rssi=-18 + measurement,host=,device=,temp-format=,gravity-format=SG, + gravity=1.0004,corr-gravity=1.0004,angle=45.45,temp=20.1,battery=3.96,rssi=-18 This is the format template used to create the json above. .. code-block:: - measurement,host=${mdns},device=${id},temp-format=${temp-unit},gravity-format=${gravity-unit} gravity=${gravity},corr-gravity=${corr-gravity},angle=${angle},temp=${temp},battery=${battery},rssi=${rssi} + measurement,host=${mdns},device=${id},temp-format=${temp-unit}, + gravity-format=${gravity-unit} gravity=${gravity},corr-gravity=${corr-gravity}, + angle=${angle},temp=${temp},battery=${battery},rssi=${rssi} .. _data-formats-mqtt: @@ -130,7 +152,10 @@ This is a format template that is compatible with v0.6. Just replace the `topic` .. code-block:: - topic:{"name":"gravmon","ID":"${id}","token":"gravmon","interval": ${sleep-interval},"temperature": ${temp},"temp-units": "${temp-unit}","gravity":${gravity},"angle": ${angle},"battery":${battery},"rssi": ${rssi},"corr-gravity":${corr-gravity},"gravity-unit": "${gravity-unit}","run-time": ${run-time}}| + topic:{"name":"gravmon", "ID":"${id}", "token":"gravmon", "interval": ${sleep-interval}, + "temperature": ${temp}, "temp-units": "${temp-unit}", "gravity":${gravity}, + "angle": ${angle}, "battery":${battery}, "rssi": ${rssi}, "corr-gravity":${corr-gravity}, + "gravity-unit": "${gravity-unit}", "run-time": ${run-time}}| version.json @@ -147,7 +172,7 @@ they can be uploaded manually afterwards. "version":"0.7.0", "html": [ "index.min.htm", - "device.min.htm", + "test.min.htm", "config.min.htm", "format.min.htm", "calibration.min.htm", diff --git a/src_docs/source/images/config2.png b/src_docs/source/images/config2.png index ca0a585..d654575 100644 Binary files a/src_docs/source/images/config2.png and b/src_docs/source/images/config2.png differ diff --git a/src_docs/source/releases.rst b/src_docs/source/releases.rst index 96257bc..c3d8641 100644 --- a/src_docs/source/releases.rst +++ b/src_docs/source/releases.rst @@ -5,18 +5,18 @@ Releases 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. +* 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. * Test function in format editor now uses real data and not fake. * Split push configuration into two sections to make it fit better on smaller devices * Updated WifiManager and DoubleReset libraries -* Experimental release of firmware using an esp32 instead of esp8266 * Updated esp32 target with littlefs support * Updated esp32 target with BLE send support (it will simulate a tilt) -* Corrected PIN for voltage read on ESP32 * Mounted esp32 d1 mini mounted to a iSpindle PCB 4.0 (CherryPhilip) which worked fine. - +* BUG: Corrected PIN for voltage read on ESP32 * BUG: If using plato and not gravity formula was defined the value was set to null. v0.8.0 @@ -29,7 +29,7 @@ v0.8.0 * Added instructions for how to configure integration with Brewspy * Added instructions for how to configure integration with Thingspeak * Added option to do a factory reset via API. -* Logging the runtime, how long a measurement take (last 10 are stored). This can be +* Added logging of the runtime, how long a measurement take (last 10 are stored). This can be used to check how good the wifi connection is and estimate the lifetime when on battery. Check the device page in the UI for this information. * Refactored code to free up more RAM to make SSL more stable. diff --git a/test/config.json b/test/config.json index 11c5f6b..b751976 100644 --- a/test/config.json +++ b/test/config.json @@ -11,6 +11,8 @@ "http-push2-h1": "Second", "http-push2-h2": "First", "token": "mytoken", + "token2": "mytoken2", + "http-push3": "http://192.168.1.10/ispindel", "influxdb2-push": "http://192.168.1.10:8086", "influxdb2-org": "hello", "influxdb2-bucket": "spann", diff --git a/test/format.json b/test/format.json index e2c7c21..c016523 100644 --- a/test/format.json +++ b/test/format.json @@ -2,6 +2,7 @@ "id": "7376ef", "http-1": "%7B%22name%22%20%3A%20%22gravmon%22%2C%20%22ID%22%3A%20%22%24%7Bid%7D%22%2C%20%22token%22%20%3A%20%22gravmon%22%2C%20%22interval%22%3A%20%24%7Bsleep%2Dinterval%7D%2C%20%22temperature%22%3A%20%24%7Btemp%7D%2C%20%22temp%2Dunits%22%3A%20%22%24%7Btemp%2Dunit%7D%22%2C%20%22gravity%22%3A%20%24%7Bgravity%7D%2C%20%22angle%22%3A%20%24%7Bangle%7D%2C%20%22battery%22%3A%20%24%7Bbattery%7D%2C%20%22rssi%22%3A%20%24%7Brssi%7D%2C%20%22corr%2Dgravity%22%3A%20%24%7Bcorr%2Dgravity%7D%2C%20%22gravity%2Dunit%22%3A%20%22%24%7Bgravity%2Dunit%7D%22%2C%20%22run%2Dtime%22%3A%20%24%7Brun%2Dtime%7D%20%7D", "http-2": "%7B%22name%22%20%3A%20%22gravmon%22%2C%20%22ID%22%3A%20%22%24%7Bid%7D%22%2C%20%22token%22%20%3A%20%22gravmon%22%2C%20%22interval%22%3A%20%24%7Bsleep%2Dinterval%7D%2C%20%22temperature%22%3A%20%24%7Btemp%7D%2C%20%22temp%2Dunits%22%3A%20%22%24%7Btemp%2Dunit%7D%22%2C%20%22gravity%22%3A%20%24%7Bgravity%7D%2C%20%22angle%22%3A%20%24%7Bangle%7D%2C%20%22battery%22%3A%20%24%7Bbattery%7D%2C%20%22rssi%22%3A%20%24%7Brssi%7D%2C%20%22corr%2Dgravity%22%3A%20%24%7Bcorr%2Dgravity%7D%2C%20%22gravity%2Dunit%22%3A%20%22%24%7Bgravity%2Dunit%7D%22%2C%20%22run%2Dtime%22%3A%20%24%7Brun%2Dtime%7D%20%7D", + "http-3": "%7B%22name%22%20%3A%20%22gravmon%22%2C%20%22ID%22%3A%20%22%24%7Bid%7D%22%2C%20%22token%22%20%3A%20%22gravmon%22%2C%20%22interval%22%3A%20%24%7Bsleep%2Dinterval%7D%2C%20%22temperature%22%3A%20%24%7Btemp%7D%2C%20%22temp%2Dunits%22%3A%20%22%24%7Btemp%2Dunit%7D%22%2C%20%22gravity%22%3A%20%24%7Bgravity%7D%2C%20%22angle%22%3A%20%24%7Bangle%7D%2C%20%22battery%22%3A%20%24%7Bbattery%7D%2C%20%22rssi%22%3A%20%24%7Brssi%7D%2C%20%22corr%2Dgravity%22%3A%20%24%7Bcorr%2Dgravity%7D%2C%20%22gravity%2Dunit%22%3A%20%22%24%7Bgravity%2Dunit%7D%22%2C%20%22run%2Dtime%22%3A%20%24%7Brun%2Dtime%7D%20%7D", "influxdb": "measurement%2Chost%3D%24%7Bmdns%7D%2Cdevice%3D%24%7Bid%7D%2Ctemp%2Dformat%3D%24%7Btemp%2Dunit%7D%2Cgravity%2Dformat%3D%24%7Bgravity%2Dunit%7D%20gravity%3D%24%7Bgravity%7D%2Ccorr%2Dgravity%3D%24%7Bcorr%2Dgravity%7D%2Cangle%3D%24%7Bangle%7D%2Ctemp%3D%24%7Btemp%7D%2Cbattery%3D%24%7Bbattery%7D%2Crssi%3D%24%7Brssi%7D%0A", "mqtt": "ispindel%2F%24%7Bmdns%7D%2Ftilt%3A%24%7Bangle%7D%7Cispindel%2F%24%7Bmdns%7D%2Ftemperature%3A%24%7Btemp%7D%7Cispindel%2F%24%7Bmdns%7D%2Ftemp%5Funits%3A%24%7Btemp%2Dunit%7D%7Cispindel%2F%24%7Bmdns%7D%2Fbattery%3A%24%7Bbattery%7D%7Cispindel%2F%24%7Bmdns%7D%2Fgravity%3A%24%7Bgravity%7D%7Cispindel%2F%24%7Bmdns%7D%2Finterval%3A%24%7Bsleep%2Dinterval%7D%7Cispindel%2F%24%7Bmdns%7D%2FRSSI%3A%24%7Brssi%7D%7C" } \ No newline at end of file diff --git a/test/status.json b/test/status.json index 91e9e33..960b710 100644 --- a/test/status.json +++ b/test/status.json @@ -5,6 +5,7 @@ "gravity-format": "G", "temp-c": 12, "temp-f": 32, + "sleep-interval": 300, "battery": 3.81, "temp-format": "C", "sleep-mode": false,