Last active
August 29, 2015 14:07
-
-
Save Raidok/cacd1b16fc1f4e14c6ef to your computer and use it in GitHub Desktop.
WR703N + OpenWRT cat feeder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- lucidir/controller/cats.lua | |
module("luci.controller.cats", package.seeall) | |
function index() | |
entry({"cats"}, cbi("cats"), "Feed cats", 30).dependent=false | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- lucidir/model/cbi/cats.lua | |
f = SimpleForm("cats", "Feed cats") | |
f.submit = false | |
f.reset = false | |
f:field(Value, "time", translate("Time in seconds")) | |
f:field(Button, "_btn", translate("Click to feed")) | |
function f.handle(self, state, data) | |
time = tonumber(data.time) | |
-- If all mandatory fields are filled and module should be enabled | |
if state == FORM_VALID and time and time > 0 then | |
-- Check for parameters and append them if set | |
command = "echo '1' > /sys/class/gpio/gpio29/value && sleep %s && echo '0' > /sys/class/gpio/gpio29/value" % { time } | |
-- Execute and save return code | |
local stat = luci.sys.call(command) | |
-- Check whether action succeeded (return code: 0) | |
if stat == 0 then | |
f.message = "Ran %s seconds" % { time } | |
else | |
f.errmessage = "Failed. Code: %i" % stat | |
end | |
end | |
end | |
-- Return form | |
return f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment