返回列表 發帖

【RouterOS】—— How to schedule wireless

Source : http://forum.mikrotik.com/viewtopic.php?f=9&t=63139

Had a requirement to set the wireless radio on a RB751U to switch on and off at certain times.
E.g. On during business hours only (07:00 - 17:00)

The simplest solution was to use the scheduler to enable and disable the radio at the required times.
However, if the router was powered off sometime during the night in this example and only switched on after the 07:00 ON time, the scheduler ON time event, would never happen and the radio would remain off.

This script checks at whatever scheduled intervals the user requires, if the radio is supposed to be ON or OFF and then sets it accordingly.

It could be adapted for example to enable and disable your 3G modem WAN link, if you only wanted the router to have an active internet connection for certain time periods for example.
  1. # Script to ensure wireless lan radio is ON or OFF #
  2. # between user selected times #
  3. # The radio ON/OFF operation will not be performed if the system #
  4. # clock is not in sync with local time, unless so required #
  5. # Remember router is set back to default time after a reboot #
  6. # Schedule this script at required intervals #
  7. # Written by Peter James 2012-07-19 #
  8. # Tested on RB751U and RouterOS v5.19 #

  9. #####################################
  10. ## Set the Radio ON and OFF times here ##
  11. :local RadioOnTime "07:00";
  12. :local RadioOffTime "17:00";

  13. # set to "no" if clock is being set manually after each reboot #
  14. # set to "yes" if clock is being set using NTP client #
  15. :local UseNTPClientStatus "yes";
  16. #####################################

  17. :log info "RadioOnOff Script Starting";
  18. # get the name of the wlan radio interface #
  19. :local RadioName [/interface get [find type=wlan] name];
  20. :log info "Radio Name = $RadioName";

  21. # First check if system clock has been syncronized with local time #
  22. :local NTPSyncState [/system ntp client get status];
  23. :log info "NTP Client Status = $NTPSyncState";

  24. # Don't perform radio On or Off operation, if current real time is unknown, unless required #
  25. :if (($NTPSyncState="synchronized") or ($UseNTPClientStatus="no")) do {

  26. :local CurrentTime [/system clock get time];
  27. :log info "Current Time = $CurrentTime";

  28. # Check current ON or OFF status of radio #
  29. :local RadioDisabled [/interface get $RadioName disabled];
  30. :log info "Radio Disabled = $RadioDisabled";


  31. # Where the ON time is set earlier than the OFF time #
  32. :if ($RadioOnTime < $RadioOffTime) do {

  33. # Radio should be ON between these times #
  34. :if (($CurrentTime > $RadioOnTime) and ($CurrentTime < $RadioOffTime)) do {

  35. if ($RadioDisabled=true) do {
  36. :log info "Radio was OFF, now switching ON";
  37. /interface enable $RadioName;
  38. }
  39. } else {

  40. if ($RadioDisabled=false) do {
  41. :log info "Radio was ON, now switching OFF";
  42. /interface disable $RadioName;
  43. }

  44. }

  45. }

  46. # Where the ON time is set later than the OFF time #
  47. :if ($RadioOnTime > $RadioOffTime) do {

  48. # Radio should be OFF between these times #
  49. :if (($CurrentTime < $RadioOnTime) and ($CurrentTime > $RadioOffTime)) do {

  50. if ($RadioDisabled=false) do {
  51. :log info "Radio was ON, now switching OFF";
  52. /interface disable $RadioName;
  53. }
  54. } else {

  55. if ($RadioDisabled=true) do {
  56. :log info "Radio was OFF, now switching ON";
  57. /interface enable $RadioName;
  58. }

  59. }

  60. }

  61. } else {

  62. :log info "System clock may not be synchronized to local time, unable to perform operation";

  63. }

  64. :log info "RadioOnOff Script completed";
複製代碼

How to make it for "Mikrotik hAP AC - RB962UiGS-5HacT2HnT"
dual wireless ...?

TOP

Just select the wireless that you want. Both wireless interfaces can be used at the same time.

TOP

本帖最後由 carlchan 於 2016-5-3 20:20 編輯

It get error ...
Need to change line 22?
I changed but get error

TOP

回復 4# carlchan

I mis-interpreted your message. The code that I just copied from other website. The script is, I believe, applicable to single wireless interface. You need to modify it if you are able to do so for dual wireless interfaces.

TOP

Finally , I use the following with Scheduler:

:log info "Wireless , now switching ON";
/interface enable "wlan-2G";
/interface enable "wlan-5G";

:log info "Wireless , now switching OFF";
/interface disable "wlan-2G";
/interface disable "wlan-5G";

TOP

Thanks you very much for your information.

You meant you have two scripts running at different scheduled time interval, right?

TOP

返回列表