Tatsächlich ist das Problem, das dass Script nach einen Durchlauf weiterhin stehen bleibt.
Auch wenn die Zeile 61 auskommentiert wird, läuft die Schleife nicht weiter.
Eben probiert.
Start watchdog timer 19:35:52
Failed to fetch https://global.gcping.com/ping 19:36:52
Rotating through endpoints 19:36:52
Failed to fetch https://us-central1-5tkroniexa-uc.a.run.app/ping 19:37:52
Rotating through endpoints 19:37:52
Failed to fetch https://global.gcping.com/ping 19:38:52
Rotating through endpoints 19:38:52
Too many fails, resetting... 19:38:52
Meine angepasste Version funktioniert! warum auch immer
// Copyright 2021 Allterco Robotics EOOD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Shelly is a Trademark of Allterco Robotics
// Shelly Script example: Router Watchdog
//
// This script tries to execute HTTP GET requests within a set time, against a set of endpoints
// After certain number of failures the script sets the Switch off and after some time
// turns it back on
let CONFIG = {
endpoints: [
"https://global.gcping.com/ping",
"https://us-central1-5tkroniexa-uc.a.run.app/ping",
],
//number of failures that trigger the reset
numberOfFails: 3,
//time in seconds after which the http request is considered failed
httpTimeout: 10,
//time in seconds for the relay to be off
toggleTime: 30,
//time in seconds to retry a "ping"
pingTime: 60,
};
let endpointIdx = 0;
let failCounter = 0;
let pingTimer = null;
function pingEndpoints() {
Shelly.call(
"http.get",
{ url: CONFIG.endpoints[endpointIdx], timeout: CONFIG.httpTimeout },
function (response, error_code, error_message) {
//http timeout, magic number, not yet documented
if (error_code === -114) {
print("Failed to fetch ", CONFIG.endpoints[endpointIdx]);
failCounter++;
print("Rotating through endpoints");
endpointIdx++;
endpointIdx = endpointIdx % CONFIG.endpoints.length;
} else {
failCounter = 0;
}
if (failCounter >= CONFIG.numberOfFails) {
print("Too many fails, resetting...");
failCounter = 0;
//Timer.clear(pingTimer);
//set the output with toggling back
Shelly.call(
"Switch.Set",
{ id: 0, on: false, toggle_after: CONFIG.toggleTime },
function () {}
);
return;
}
}
);
}
print("Start watchdog timer");
pingTimer = Timer.set(CONFIG.pingTime * 1000, true, pingEndpoints);
Shelly.addEventHandler(function (event) {
//timeout has expired and we have turned back power
if (
event.name === "switch" &&
event.info.source === "timer" &&
event.info.output === true
) {
print("Start watchdog timer");
pingTimer = Timer.set(CONFIG.pingTime * 1000, true, pingEndpoints);
}
});
Logfile:
Start watchdog timer 19:48:49
Failed to fetch https://global.gcping.com/ping 19:52:50
Rotating through endpoints 19:52:50
Failed to fetch https://us-central1-5tkroniexa-uc.a.run.app/ping 19:53:50
Rotating through endpoints 19:53:50
Failed to fetch https://global.gcping.com/ping 19:54:50
Rotating through endpoints 19:54:50
Too many fails, resetting... 19:54:50
Failed to fetch https://us-central1-5tkroniexa-uc.a.run.app/ping 19:55:50
Rotating through endpoints 19:55:50
Failed to fetch https://global.gcping.com/ping 19:56:50
Rotating through endpoints 19:56:50
Failed to fetch https://us-central1-5tkroniexa-uc.a.run.app/ping 19:57:50
Rotating through endpoints 19:57:50
Too many fails, resetting... 19:57:50
Failed to fetch https://global.gcping.com/ping 19:58:50
Rotating through endpoints 19:58:50
Failed to fetch https://us-central1-5tkroniexa-uc.a.run.app/ping 19:59:50
Rotating through endpoints 19:59:50
Failed to fetch https://global.gcping.com/ping 20:00:50
Rotating through endpoints 20:00:50
Too many fails, resetting... 20:00:50
Failed to fetch https://us-central1-5tkroniexa-uc.a.run.app/ping 20:01:50
Rotating through endpoints 20:01:50
Failed to fetch https://global.gcping.com/ping 20:02:50
Rotating through endpoints 20:02:50
Failed to fetch https://us-central1-5tkroniexa-uc.a.run.app/ping 20:03:50
Rotating through endpoints 20:03:50
Too many fails, resetting... 20:03:50
Failed to fetch https://global.gcping.com/ping 20:04:50
Rotating through endpoints 20:04:50
...
...
Alles anzeigen