From 172d789f2a4f350555665173f53f6cd5122cd1a7 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 10 Sep 2018 22:15:54 +0200 Subject: add scripts mode-button-{event,scheduler} --- global-config | 8 ++++++++ mode-button-event | 14 ++++++++++++++ mode-button-scheduler | 16 ++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 mode-button-event create mode 100644 mode-button-scheduler diff --git a/global-config b/global-config index ae7f73a..e42139b 100644 --- a/global-config +++ b/global-config @@ -39,6 +39,14 @@ # pseudo-random PSK. :global "daily-psk-match-comment" "Daily PSK"; +# Run different commands with multiple mode-button presses. +:global "mode-button" { + 1="/ system script run leds-toggle-mode;"; + 2="/ system shutdown"; + 3="/ system reboot"; +# add mode here... +}; + # This address should resolve ntp servers and is used to update # ntp settings. A pool can rotate servers. :global "ntp-pool" "pool.ntp.org"; diff --git a/mode-button-event b/mode-button-event new file mode 100644 index 0000000..2306e1e --- /dev/null +++ b/mode-button-event @@ -0,0 +1,14 @@ +# +# RouterOS script: mode-button-event +# Copyright (c) 2018 Christian Hesse +# +# run on mode-button event and count button presses + +:global "mode-button"; + +:set ($"mode-button"->"count") ($"mode-button"->"count" + 1); + +:if ([ :len [ / system scheduler find where name="mode-button-scheduler" ] ] = 0) do={ + :log info "Creating mode-button scheduler..."; + / system scheduler add name=mode-button-scheduler on-event=mode-button-scheduler interval=5s; +} diff --git a/mode-button-scheduler b/mode-button-scheduler new file mode 100644 index 0000000..bf85826 --- /dev/null +++ b/mode-button-scheduler @@ -0,0 +1,16 @@ +# +# RouterOS script: mode-button-scheduler +# Copyright (c) 2018 Christian Hesse +# +# act on multiple mode-botton presses from scheduler + +:global "mode-button"; + +:local count ($"mode-button"->"count"); +:local action [ :parse ($"mode-button"->[ :tostr $count ]) ]; + +:set ($"mode-button"->"count") 0; +/ system scheduler remove mode-button-scheduler; + +:log info ("Acting on " . $count . " mode-button presses."); +$action; -- cgit v1.2.3-70-g09d2