Introduce timeout for checking internet

This commit is contained in:
Pothi Kalimuthu 2022-11-18 10:07:05 +05:30
parent fd35e525bc
commit 69023b21f8
No known key found for this signature in database
GPG key ID: 08202A469C2D0E06

View file

@ -1,23 +1,39 @@
# Initialize the router with default values, run backup scripts and check for updates! # Initialize the router with default values, run backup scripts and check for updates!
# Version: 2
# changelog
# version: 2
# - date: 2022-11-18
# - introduction of timeout to check internet
:global adminEmail "noreply@example.com" :global adminEmail "noreply@example.com"
:global cloudPass "" :global cloudPass ""
:local isUP 0
:local timeout 5
/interface/detect-internet /interface/detect-internet
set detect-interface-list=WAN set detect-interface-list=WAN
state state
:do { :do {
:delay 60s :delay 60s
:set $internetStatus ([:pick [print as-value] 0]->"state") :set $internetStatus ([:pick [print as-value] 0]->"state")
# :log info "Waiting for internet..." # :log info "Waiting for internet..."
:set isUP ($isUP+1)
:if ($isUP = $timeout) do={ :error "Internet timed out after $timeout minutes!" }
} while ($internetStatus != "internet") } while ($internetStatus != "internet")
# :log info "Connected to internet." # :log info "Connected to internet."
:log info "Init script started." :log info "Init script started."
/system script /system script
:local commonScripts {"backup-cron"; "backup-scripts"; "cloud-backup"; "firmware-check"} :local commonScripts {"backup-buttons"; "backup-cron"; "backup-scripts"; "cloud-backup"; "firmware-check"}
:local initScripts ("enable-wifi", $commonScripts) :local initScripts ("enable-wifi", $commonScripts)
:foreach scriptName in $initScripts do={ :foreach scriptName in $initScripts do={