From 83dffd0366b81ba7d88e52c6f96f0ce31a4e0bef Mon Sep 17 00:00:00 2001 From: fe51 <55736935+fe51@users.noreply.github.com> Date: Wed, 22 Apr 2026 09:41:39 +0200 Subject: [PATCH 1/3] Update internet checks --- watchdog/pi_zero/watchdog.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/watchdog/pi_zero/watchdog.py b/watchdog/pi_zero/watchdog.py index 9243909d..0991e889 100644 --- a/watchdog/pi_zero/watchdog.py +++ b/watchdog/pi_zero/watchdog.py @@ -56,7 +56,12 @@ def _load_env(path: Path) -> dict: "192.168.1.11", "192.168.1.12", ] -INTERNET_IP = "1.1.1.1" +_INTERNET_HTTP_URLS = [ + "https://clients3.google.com/generate_204", + "https://connectivitycheck.gstatic.com/generate_204", + "https://example.com", +] +_INTERNET_PING_IPS = ["1.1.1.1", "8.8.8.8", "9.9.9.9"] PING_COUNT = 2 TIMEOUT = 2 # seconds, used for ping and HTTP timeout @@ -135,6 +140,25 @@ def ping_host(ip: str, count: int = PING_COUNT, timeout: int = TIMEOUT) -> bool: return False +def internet_check_ok() -> bool: + for url in _INTERNET_HTTP_URLS: + try: + with urlopen(url, timeout=TIMEOUT) as resp: + if resp.status in (200, 204): + logging.info("Internet HTTP check OK: %s", url) + return True + except Exception: + pass + + for ip in _INTERNET_PING_IPS: + if ping_host(ip, count=1, timeout=TIMEOUT): + logging.info("Internet ping fallback OK: %s", ip) + return True + + logging.warning("Internet connectivity FAILED") + return False + + def http_health_ok(url: str) -> bool: req = Request(url, method="GET", headers={"accept": "application/json"}) try: @@ -253,8 +277,8 @@ def main() -> None: reboot_12v = False - internet_ok = ping_host(INTERNET_IP, count=1, timeout=TIMEOUT) - internet_fails = update_fail_counter(internet_ok, FAIL_INTERNET_FILE, f"Internet {INTERNET_IP}") + internet_ok = internet_check_ok() + internet_fails = update_fail_counter(internet_ok, FAIL_INTERNET_FILE, "Internet") if internet_fails >= MAX_FAILS: reboot_12v = True From 11a35a2bd5617a7138744ae4e5da94cae7feccfe Mon Sep 17 00:00:00 2001 From: fe51 <55736935+fe51@users.noreply.github.com> Date: Mon, 27 Apr 2026 18:13:40 +0200 Subject: [PATCH 2/3] updates urls --- watchdog/pi_zero/watchdog.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/watchdog/pi_zero/watchdog.py b/watchdog/pi_zero/watchdog.py index 0991e889..a97feef4 100644 --- a/watchdog/pi_zero/watchdog.py +++ b/watchdog/pi_zero/watchdog.py @@ -59,7 +59,8 @@ def _load_env(path: Path) -> dict: _INTERNET_HTTP_URLS = [ "https://clients3.google.com/generate_204", "https://connectivitycheck.gstatic.com/generate_204", - "https://example.com", + "http://cp.cloudflare.com", + "www.msftconnecttest.com/connecttest.txt" ] _INTERNET_PING_IPS = ["1.1.1.1", "8.8.8.8", "9.9.9.9"] From cb71c7c8825b5c0b9a9163df296e91482c111d65 Mon Sep 17 00:00:00 2001 From: fe51 <55736935+fe51@users.noreply.github.com> Date: Mon, 27 Apr 2026 19:57:23 +0200 Subject: [PATCH 3/3] style (on purpose, do not log useless fail) --- watchdog/pi_zero/watchdog.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/watchdog/pi_zero/watchdog.py b/watchdog/pi_zero/watchdog.py index a97feef4..68984d5f 100644 --- a/watchdog/pi_zero/watchdog.py +++ b/watchdog/pi_zero/watchdog.py @@ -60,7 +60,7 @@ def _load_env(path: Path) -> dict: "https://clients3.google.com/generate_204", "https://connectivitycheck.gstatic.com/generate_204", "http://cp.cloudflare.com", - "www.msftconnecttest.com/connecttest.txt" + "www.msftconnecttest.com/connecttest.txt", ] _INTERNET_PING_IPS = ["1.1.1.1", "8.8.8.8", "9.9.9.9"] @@ -148,7 +148,7 @@ def internet_check_ok() -> bool: if resp.status in (200, 204): logging.info("Internet HTTP check OK: %s", url) return True - except Exception: + except Exception: # noqa: S110 pass for ip in _INTERNET_PING_IPS: