add scripts mode-button-{event,scheduler}

This commit is contained in:
Christian Hesse 2018-09-10 22:15:54 +02:00
parent 8f4986af0b
commit 172d789f2a
3 changed files with 38 additions and 0 deletions

View file

@ -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";

14
mode-button-event Normal file
View file

@ -0,0 +1,14 @@
#
# RouterOS script: mode-button-event
# Copyright (c) 2018 Christian Hesse <mail@eworm.de>
#
# 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;
}

16
mode-button-scheduler Normal file
View file

@ -0,0 +1,16 @@
#
# RouterOS script: mode-button-scheduler
# Copyright (c) 2018 Christian Hesse <mail@eworm.de>
#
# 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;