Skip to content
Snippets Groups Projects
Unverified Commit cdf9363c authored by Florian Maurer's avatar Florian Maurer
Browse files

ff-ap-timer: add renamed ap-timer from ffho

parent d7554980
No related branches found
No related tags found
No related merge requests found
include $(TOPDIR)/rules.mk
PKG_NAME:=ffho-ap-timer
PKG_VERSION:=1
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
include $(TOPDIR)/../package/gluon.mk
define Package/ffho-ap-timer
SECTION:=ffho
CATEGORY:=FFHO
TITLE:=Timer for the client wifi
DEPENDS:=+gluon-core
MAINTAINER:=Freifunk Hochstift <kontakt@hochstift.freifunk.net>
endef
define Package/ffho-ap-timer/description
Timer for the client wifi
endef
$(eval $(call BuildPackageGluon,$(PKG_NAME)))
ffho-ap-timer
=============
Timer for the client wifi with three modes (daily, weekly, monthly)
/etc/config/ap-timer
-------------------
**ap-timer.settings.enabled:**
- `0` disables the ap-timer (default)
- `1` enables the ap-timer
**ap-timer.settings.type:**
- `day`, $day = all
- `week`, $day = [Mon|Tue|Wed|Thu|Fri|Sat|Sun]
- `month`, $day = [01-31]
**ap-timer.$day.on:**
- List of time to enable wireless
**ap-timer.$day.off:**
- List of time to disable wireless
### example
```
config ap-timer 'settings'
option enabled '1'
option type 'week'
config week 'Sun'
list on '06:00'
list off '23:00'
```
#config ap-timer 'settings'
# option enabled '1'
# option type 'day'
#
#config day 'all'
# list on '06:00'
# list off '23:00'
#!/bin/sh
rm -f /etc/config/aptimer
* * * * * /usr/sbin/ap-timer
#!/usr/bin/lua
local timestamp = os.time()
local uci = require('simple-uci').cursor()
local function compare(list, value)
if not list then
return nil
end
for _, v in ipairs(list) do
if v == value then
return true
end
end
return false
end
local function getDay()
local type = uci:get('ap-timer', 'settings', 'type')
if type == 'day' then return 'all'
elseif type == 'week' then return os.date('%a', timestamp)
elseif type == 'month' then return os.date('%d', timestamp)
else return nil
end
end
local function apSet(enable)
local execWifi = false
local radios = {'client_radio0', 'client_radio1'}
for _, radio in ipairs(radios) do
if uci:get('wireless', radio) then
uci:set('wireless', radio, 'disabled', not enable)
execWifi = true
end
end
if execWifi then
uci:save('wireless')
os.execute('wifi')
end
end
if uci:get_bool('ap-timer', 'settings', 'enabled') then
local day = getDay()
local current = os.date('%H:%M', timestamp)
local off = compare(uci:get_list('ap-timer', day, 'off'), current)
local on = compare(uci:get_list('ap-timer', day, 'on'), current)
if on and not off then
apSet(true)
end
if off and not on then
apSet(false)
end
end
include $(TOPDIR)/rules.mk
PKG_NAME:=ffho-web-ap-timer
PKG_VERSION:=1
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
include $(TOPDIR)/../package/gluon.mk
define Package/ffho-web-ap-timer
SECTION:=ffho
CATEGORY:=FFHO
TITLE:=Luci module for ap-timer settings
DEPENDS:=+gluon-web-admin
MAINTAINER:=Freifunk Hochstift <kontakt@hochstift.freifunk.net>
endef
$(eval $(call BuildPackageGluon,$(PKG_NAME)))
ffho-web-ap-timer
=================
Gluon-web module for ap-timer settings.
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"PO-Revision-Date: 2017-06-24 23:00+0200\n"
"Last-Translator: <freifunk@kb-light.de>\n"
"Language-Team: German\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
msgid "AP Timer"
msgstr "AP Timer"
msgid "Daily"
msgstr "Täglich"
msgid "Enabled"
msgstr "Aktiviert"
msgid "OFF"
msgstr "Aus"
msgid "ON"
msgstr "An"
msgid "Type"
msgstr "Typ"
msgid "You can setup the AP Timer here"
msgstr "Hier kannst du den AP-Timer konfigurieren"
msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8"
msgid "AP Timer"
msgstr ""
msgid "Daily"
msgstr ""
msgid "Enabled"
msgstr ""
msgid "OFF"
msgstr ""
msgid "ON"
msgstr ""
msgid "Type"
msgstr ""
msgid "You can setup the AP Timer here"
msgstr ""
package 'ffho-web-ap-timer'
entry({"admin", "ap-timer"}, model("admin/ap-timer"), _("AP Timer"), 30)
local uci = require('simple-uci').cursor()
pkg_i18n = i18n 'ffho-web-ap-timer'
if not uci:get('ap-timer', 'settings') then
uci:section('ap-timer', 'ap-timer', 'settings')
uci:save('ap-timer')
end
if not uci:get('ap-timer', 'all') then
uci:section('ap-timer', 'day', 'all')
uci:save('ap-timer')
end
local f = Form(pkg_i18n.translate('AP Timer'), pkg_i18n.translate(
'You can setup the AP Timer here'))
local s = f:section(Section)
enabled = s:option(Flag, 'enabled', pkg_i18n.translate('Enabled'))
enabled.default = uci:get_bool('ap-timer', 'settings', 'enabled')
enabled.optional = false
function enabled:write(data)
uci:set('ap-timer', 'settings', 'enabled', data)
end
local timer_type = s:option(ListValue, 'type', pkg_i18n.translate('Type'))
timer_type.default = uci:get('ap-timer', 'settings', 'type')
timer_type:depends(enabled, true)
timer_type:value('day', pkg_i18n.translate('Daily'))
function timer_type:write(data)
uci:set('ap-timer', 'settings', 'type', data)
end
local s = f:section(Section)
o = s:option(DynamicList, 'on', pkg_i18n.translate('ON'))
o.default = uci:get_list('ap-timer', 'all', 'on')
o.placeholder = '06:30'
o:depends(timer_type, 'day')
o.optional = false
o.datatype = 'minlength(5)'
function o:write(data)
uci:set_list('ap-timer', 'all', 'on', data)
end
o = s:option(DynamicList, 'off', pkg_i18n.translate('OFF'))
o.default = uci:get_list('ap-timer', 'all', 'off')
o.placeholder = '23:00'
o:depends(timer_type, 'day')
o.optional = false
o.datatype = 'minlength(5)'
function o:write(data)
uci:set_list('ap-timer', 'all', 'off', data)
end
function f:write()
uci:commit('ap-timer')
end
return f
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment