-
Notifications
You must be signed in to change notification settings - Fork 0
Tipps de
Hamatoma edited this page Aug 18, 2022
·
3 revisions
Dieses Script ist ein Baustein, um bei täglich wechselnden IP-Adressen dennoch Zugriffsmöglichkeiten für den SunMonitor zu haben, ohne dass DynDNS oder ähnliches bemüht wird.
Es wird ein Server im Internet angesprochen (hier myip.example.com), der dann die IP-Adresse aus dem Zugriff ermitteln kann.
let remoteurl = "http://myip.example.com/setip.php?hostname=sunmonitor&script=setip";
let maxfails = 1000;
// interval in minutes
let interval = 1;
// CONFIG END
// no need to change anything below this line.
let alertTimer = '';
let failcounter = 0;
function setIp(){
print("setIp " + remoteurl);
Shelly.call("HTTP.GET", {
url: remoteurl
},
function (res, error_code, error_msg, ud) {
if (error_code !== 0) {
if (failcounter === maxfails) {
print("Restart");
restartRelay();
failcounter = 0;
} else {
failcounter++;
print("fail: res: ", res, " err: ", error_code, " msg: ",
error_msg, " ud: ", ud, " #: ", failcounter);
}
}
},
null
);
}
function startMonitor() {
alertTimer = Timer.set(interval * 60 * 1000, true, setIp, null);
}
function restartRelay() {
Shelly.call(
"switch.set",
{ id: 0, on: false, toggle: 2},
function (result, code, msg, ud) {
},
null
);
}
startMonitor();
setIp();