diff --git a/html/test.htm b/html/test.htm index 557479a..918aaaa 100644 --- a/html/test.htm +++ b/html/test.htm @@ -23,7 +23,7 @@ @@ -89,15 +89,10 @@ var id = cfg["id"]; console.log( id ); - appendLog( "Testing push target http-1" ); testHttp( id, "http-1" ); - appendLog( "Testing push target http-2" ); testHttp( id, "http-2" ); - appendLog( "Testing push target brewfather" ); testHttp( id, "brewfather" ); - appendLog( "Testing push target influxdb" ); testInfluxdb( id ); - appendLog( "Testing push target mqtt" ); testMqtt( id ); }) .fail(function () { @@ -112,30 +107,25 @@ var url = "/api/test/push"; url += "?id=" + id + "&format=mqtt"; //var url = "/test/push.json"; - $.ajax({ - type: 'GET', - url: url, - async: false, - success: function(cfg) { - var code = cfg["code"]; - var success = cfg["success"]; - var enabled = cfg["enabled"]; + $.getJSON(url, function (cfg) { + var code = cfg["code"]; + var success = cfg["success"]; + var enabled = cfg["enabled"]; - if(!enabled) { - appendLog( "Push target 'mqtt' is not configured/used" ); - } else if(success) { - appendLog( "Push target 'mqtt' successful" ); - } else{ - if(code==-3) - appendLog( "Push target 'mqtt' failed to connect" ); - else if(code==-4) - appendLog( "Push target 'mqtt' failed with error timeout" ); - else if(code==-10) - appendLog( "Push target 'mqtt' failed with error denied" ); - else - appendLog( "Push target 'mqtt' failed with error code " + code ); - } - } + if(!enabled) { + appendLog( "Push target 'mqtt' is not configured/used" ); + } else if(success) { + appendLog( "Push target 'mqtt' successful" ); + } else{ + if(code==-3) + appendLog( "Push target 'mqtt' failed to connect" ); + else if(code==-4) + appendLog( "Push target 'mqtt' failed with error timeout" ); + else if(code==-10) + appendLog( "Push target 'mqtt' failed with error denied" ); + else + appendLog( "Push target 'mqtt' failed with error code " + code ); + } }) .fail(function () { appendLog( "Failed to test push target 'influxdb'"); @@ -146,30 +136,25 @@ var url = "/api/test/push"; url += "?id=" + id + "&format=influxdb"; //var url = "/test/push.json"; - $.ajax({ - type: 'GET', - url: url, - async: false, - success: function(cfg) { - var code = cfg["code"]; - var success = cfg["success"]; - var enabled = cfg["enabled"]; + $.getJSON(url, function (cfg) { + var code = cfg["code"]; + var success = cfg["success"]; + var enabled = cfg["enabled"]; - if(!enabled) { - appendLog( "Push target 'influxdb' is not configured/used" ); - } else if(success) { - appendLog( "Push target 'influxdb' successful" ); - } else{ - if(code==400) - appendLog( "Push target 'influxdb' failed with error code 400, bad request" ); - else if(code==401) - appendLog( "Push target 'influxdb' failed with error code 401, unauthorized" ); - else if(code==404) - appendLog( "Push target 'influxdb' failed with error code 404, url not found" ); - else - appendLog( "Push target 'influxdb' failed with error code " + code ); - } - } + if(!enabled) { + appendLog( "Push target 'influxdb' is not configured/used" ); + } else if(success) { + appendLog( "Push target 'influxdb' successful" ); + } else{ + if(code==400) + appendLog( "Push target 'influxdb' failed with error code 400, bad request" ); + else if(code==401) + appendLog( "Push target 'influxdb' failed with error code 401, unauthorized" ); + else if(code==404) + appendLog( "Push target 'influxdb' failed with error code 404, url not found" ); + else + appendLog( "Push target 'influxdb' failed with error code " + code ); + } }) .fail(function () { appendLog( "Failed to test push target 'influxdb'"); @@ -180,30 +165,25 @@ var url = "/api/test/push"; url += "?id=" + id + "&format=" + target; //var url = "/test/push.json"; - $.ajax({ - type: 'GET', - url: url, - async: false, - success: function(cfg) { - var code = cfg["code"]; - var success = cfg["success"]; - var enabled = cfg["enabled"]; + $.getJSON(url, function (cfg) { + var code = cfg["code"]; + var success = cfg["success"]; + var enabled = cfg["enabled"]; - if(!enabled) { - appendLog( "Push target '" + target + "' is not configured/used" ); - } else if(success) { - appendLog( "Push target '" + target + "' successful" ); - } else{ - if(code==400) - appendLog( "Push target '" + target + "' failed with error code 400, bad request" ); - else if(code==401) - appendLog( "Push target '" + target + "' failed with error code 401, unauthorized" ); - else if(code==404) - appendLog( "Push target '" + target + "' failed with error code 404, url not found" ); - else - appendLog( "Push target '" + target + "' failed with error code " + code ); - } - } + if(!enabled) { + appendLog( "Push target '" + target + "' is not configured/used" ); + } else if(success) { + appendLog( "Push target '" + target + "' successful" ); + } else{ + if(code==400) + appendLog( "Push target '" + target + "' failed with error code 400, bad request" ); + else if(code==401) + appendLog( "Push target '" + target + "' failed with error code 401, unauthorized" ); + else if(code==404) + appendLog( "Push target '" + target + "' failed with error code 404, url not found" ); + else + appendLog( "Push target '" + target + "' failed with error code " + code ); + } }) .fail(function () { appendLog( "Failed to test push target '" + target + "'"); diff --git a/html/test.min.htm b/html/test.min.htm index 606d222..2e3bceb 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/pushtarget.cpp b/src/pushtarget.cpp index 99884fe..4f24151 100644 --- a/src/pushtarget.cpp +++ b/src/pushtarget.cpp @@ -104,6 +104,7 @@ void PushTarget::sendInfluxDb2(TemplatingEngine& engine) { _lastCode = _http.POST(doc); if (_lastCode == 204) { + _lastSuccess = true; Log.notice(F("PUSH: InfluxDB2 push successful, response=%d" CR), _lastCode); } else { diff --git a/src/webserver.cpp b/src/webserver.cpp index 011a1c0..a4ddcc2 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -799,14 +799,20 @@ void WebServerHandler::webHandleTestPush() { enabled = true; } - DynamicJsonDocument doc(20); + DynamicJsonDocument doc(100); doc[PARAM_PUSH_ENABLED] = enabled; doc[PARAM_PUSH_SUCCESS] = push.getLastSuccess(); doc[PARAM_PUSH_CODE] = push.getLastCode(); String out; - out.reserve(50); + out.reserve(100); serializeJson(doc, out); + +#if LOG_LEVEL == 6 && !defined(WEB_DISABLE_LOGGING) + serializeJson(doc, Serial); + Serial.print(CR); +#endif + _server->send(200, "application/json", out.c_str()); LOG_PERF_STOP("webserver-api-test-push"); }