SunMonitor: Unterschied zwischen den Versionen

Aus Info-Theke
Zur Navigation springen Zur Suche springen
Zeile 13: Zeile 13:
* Eintrag in /home/www/ip/setip.php
* Eintrag in /home/www/ip/setip.php


= tom =
= Markus =
* suntom.hamatoma.de: proxy_pass http://127.0.0.1:8083;
* masun.hamatoma.de: proxy_pass http://127.0.0.1:8083;
* sunmonitortom.service
* masunmonitor.service
* sunservertom.service
* masunserver.service
* /etc/sunmonitor: monitor.tom.conf  server.tom.conf
* /etc/sunmonitor: masunmonitor.conf  masunserver.conf
* curl -s https://ip.hamatoma.de/setip.php?hostname=suntom
* curl -s https://ip.hamatoma.de/setip.php?hostname=masun
* Eintrag in /home/www/ip/setip.php


= Script für Shelly =
= Script für Shelly =

Version vom 19. März 2023, 10:00 Uhr

Links

hm

Markus

Script für Shelly

 let remoteurl = "http://ip.hamatoma.de/setip.php?hostname=sunmonitor";
 let maxfails = 1000;
// checks the internet connection every x minutes, recommended is 5 or more
let interval = 60;
// CONFIG END

// no need to change anything below this line.
let alertTimer = '';
let failcounter = 0;
function setIp(){
  print("setIp:");
  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,
    function () {
      print("started by timer");
      setIP();
    },
    null
  );
}
function restartRelay() {
    Shelly.call(
        "switch.set",
        { id: 0, on: false, toggle: 2},
        function (result, code, msg, ud) {
        },
        null
    );
}
startMonitor();