You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
4.0 KiB

  1. # wifischedule
  2. Turns WiFi on and off according to a schedule on an openwrt router
  3. ## Components
  4. * wifischedule: Shell script that creates cron jobs based on configuration provided in UCI and does all the other logic of enabling and disabling wifi with the use of `/sbin/wifi` and `/usr/bin/iwinfo`. Can be used standalone.
  5. * luci-app-wifischedule: LUCI frontend for creating the UCI configuration and triggering the actions. Depends on wifischedule.
  6. ## Use cases
  7. You can create user-defined events when to enable or disable WiFi.
  8. There are various use cases why you would like to do so:
  9. 1. Reduce power consumption and therefore reduce CO2 emissions.
  10. 2. Reduce emitted electromagnatic radiation.
  11. 3. Force busincess hours when WiFi is available.
  12. Regarding 1: Please note, that you need to unload the wireless driver modules in order to get the most effect of saving power.
  13. In my test scenario only disabling WiFi saves about ~0.4 Watt, unloading the modules removes another ~0.4 Watt.
  14. Regarding 2: Think of a wireless accesspoint e.g. in your bedrom, kids room where you want to remove the ammount of radiation emitted.
  15. Regarding 3: E.g. in a company, why would wireless need to be enabled weekends if no one is there working?
  16. Or think of an accesspoint in your kids room when you want the youngsters to sleep after 10 pm instead of facebooking...
  17. ## Configuration
  18. You can create an arbitrary number of schedule events. Please note that there is on sanity check done wheather the start / stop times overlap or make sense.
  19. If start and stop time are equal, this leads to disabling the WiFi at the given time.
  20. Logging if enabled is done to the file `/var/log/wifi_schedule.log` and can be reviewed through the "View Logfile" tab.
  21. The cron jobs created can be reviewed through the "View Cron Jobs" tab.
  22. Please note that the "Unload Modules" function is currently considered as experimental. You can manually add / remove modules in the text field.
  23. The button "Determine Modules Automatically" tries to make a best guess determining regarding the driver module and its dependencies.
  24. When un-/loading the modules, there is a certain number of retries (`module_load`) performed.
  25. The option "Force disabling wifi even if stations associated" does what it says - when activated it simply shuts down WiFi.
  26. When unchecked, its checked every `recheck_interval` minutes if there are still stations associated. Once the stations disconnect, WiFi is disabled. To ignore associated stations add their MAC to `ignore_stations`.
  27. Please note, that the parameters `module_load`, `recheck_interval` and `ignore_stations` are only accessible through uci.
  28. ## UCI Configuration `wifi_schedule`
  29. UCI configuration file: `/etc/config/wifi_schedule`:
  30. ```
  31. config global
  32. option logging '0'
  33. option enabled '0'
  34. option recheck_interval '10'
  35. option modules_retries '10'
  36. # option ignore_stations 'AA:AA:AA:AA:AA:AA BB:BB:BB:BB:BB:BB'
  37. config entry 'Businesshours'
  38. option enabled '0'
  39. option daysofweek 'Monday Tuesday Wednesday Thursday Friday'
  40. option starttime '06:00'
  41. option stoptime '22:00'
  42. option forcewifidown '0'
  43. config entry 'Weekend'
  44. option enabled '0'
  45. option daysofweek 'Saturday Sunday'
  46. option starttime '00:00'
  47. option stoptime '00:00'
  48. option forcewifidown '1'
  49. ```
  50. ## Script: `wifi_schedule.sh`
  51. This is the script that does the work. Make your changes to the UCI config file: `/etc/config/wifi_schedule`
  52. Then call the script as follows in order to get the necessary cron jobs created:
  53. `wifi_schedule.sh cron`
  54. All commands:
  55. ```
  56. wifi_schedule.sh cron|start|stop|forcestop|recheck|getmodules|savemodules|help
  57. cron: Create cronjob entries.
  58. start: Start wifi.
  59. stop: Stop wifi gracefully, i.e. check if there are stations associated and if so keep retrying.
  60. forcestop: Stop wifi immediately.
  61. recheck: Recheck if wifi can be disabled now.
  62. getmodules: Returns a list of modules used by the wireless driver(s)
  63. savemodules: Saves a list of automatic determined modules to UCI
  64. help: This description.
  65. ```