update wifi updown

This commit is contained in:
JamesonHuang 2015-05-14 10:17:14 +08:00
parent b48c8407aa
commit d753370f63
7 changed files with 5705 additions and 10 deletions

73
Me_Lua/R10-WIFI.lua Normal file
View File

@ -0,0 +1,73 @@
function wifi_reconnect_shutdown(shutdown, wnet)
local netmd = require "luci.model.network".init()
local net = netmd:get_wifinet(wnet)
local dev = net:get_device()
if dev and net then
dev:set("disabled", nil)
net:set("disabled", shutdown and 1 or nil)
netmd:commit("wireless")
luci.sys.call("env -i /bin/ubus call network reload >/dev/null 2>/dev/null")
luci.sys.call("env -i /sbin/wifi reload >/dev/null 2>/dev/null")
--luci.http.status(200, shutdown and "Shutdown" or "Reconnected")
return
end
--luci.http.status(404, "No such radio")
end
function wifi_reconnect(wnet)
wifi_reconnect_shutdown(false, wnet)
end
function wifi_shutdown(wnet)
wifi_reconnect_shutdown(true, wnet)
end
function fork_smart_wifi_shutdown(switch, wnet, close_time, open_time)
local close_interval = close_time - os.time()
local open_interval = open_time - os.time()
local cmd = string.format("/sbin/wifi down "..wnet.."; sleep 15; /sbin/wifi up "..wnet)
require "MZLog".log(3, cmd)
--local cmd = string.format("sleep %s; /sbin/wifi down; sleep %s; /sbin/wifi up;", tostring(close_interval), tostring(open_interval))
--local cmd = "/sbin/wifi "..switch.." "..wnet
exec_cmd_in_sh(cmd)
end
function smart_wifi_shutdown()
local wnet = "wl1"
local info = {}
local switch = luci.http.formvalue("switch")
--get para
--close_time = luci.http.formvalue("close_time")
--open_time = luci.http.formvalue("open_time")
--test normal
close_time = os.time() + 2
restart_time = os.time() + 4
--test exception
--close_time = os.time() - 5
--restart_time = os.time() - 10
--para err manage
if close_time < os.time() or restart_time < close_time then
info["SUCCESS"] = false
else
info["SUCCESS"] = true
end
fork_smart_wifi_shutdown(switch, wnet, close_time, restart_time)
luci.http.write_json(info)
end

View File

@ -438,6 +438,137 @@ function fork_restart_network()
exec_cmd_in_sh(FORK_RESTART_WORK)
end
function fork_smart_wifi_shutdown(wnet, close_time, open_time)
local close_interval = close_time - os.time()
local open_interval = open_time - os.time()
local cmd = string.format("sleep 15; /sbin/wifi down "..wnet.."; sleep 15; /sbin/wifi up "..wnet)
--local cmd = string.format("sleep %s; /sbin/wifi down; sleep %s; /sbin/wifi up;", tostring(close_interval), tostring(open_interval))
--local cmd = "/sbin/wifi "..switch.." "..wnet
--local cmd = string.format("sleep %s; /sbin/wifi down; sleep %s; /sbin/wifi up;", tostring(close_interval), tostring(open_interval))
local cmd = string.format("/sbin/wifi down")
luci.http.status(200, shutdown and "Shutdown" or "Reconnected")
exec_cmd_in_sh(cmd)
end
--[[
--function: 定时wifi开关
--author rh_Jameson
--]]--
--wifi重连 &开关基础函数
local function wifi_reconnect_shutdown(shutdown, wnet)
local netmd = require "luci.model.network".init()
local net = netmd:get_wifinet(wnet)
local dev = net:get_device()
if dev and net then
dev:set("disabled", nil)
net:set("disabled", shutdown and 1 or nil)
netmd:commit("wireless")
luci.sys.call("env -i /bin/ubus call network reload >/dev/null 2>/dev/null")
luci.sys.call("env -i /sbin/wifi reload >/dev/null 2>/dev/null")
--luci.http.status(200, shutdown and "Shutdown" or "Reconnected")
return
end
--luci.http.status(404, "No such radio")
end
--wifi重连
function wifi_reconnect(wnet)
wifi_reconnect_shutdown(false, wnet)
end
--wifi关闭
function wifi_shutdown(wnet)
wifi_reconnect_shutdown(true, wnet)
end
--function: 定时wifi开关shell形式
--author rh_Jameson
function smart_wifi_shutdown()
local wnet = 'WL1'
local info = {}
local switch = luci.http.formvalue("switch")
--get para
--close_time = luci.http.formvalue("close_time")
--open_time = luci.http.formvalue("open_time")
--test normal
close_time = os.time() + 5
restart_time = os.time() + 10
--test exception
--close_time = os.time() - 5
--restart_time = os.time() - 10
--para err manage
if close_time < os.time() or restart_time < close_time then
info["SUCCESS"] = false
else
info["SUCCESS"] = true
end
fork_smart_wifi_shutdown(switch, wnet, close_time, restart_time)
luci.http.write_json(info)
end
--[[
--function: 定时wifi开关
--author rh_Jameson
function smart_wifi_shutdown()
local wnet = 'mt7628.network1'
local table = {}
--get para
--local close_time = luci.http.formvalue("close_time")
--local open_time = luci.http.formvalue("open_time")
--test normal
--local close_time = os.time() + 5
--local restart_time = os.time() + 10
--test exception
local close_time = os.time() - 5
local restart_time = os.time() - 10
--para err manage
if close_time < os.time() or restart_time < close_time then
table["err"] = true
luci.http.write_json(table)
return
end
--do close
while true do
if os.time() ~= close_time then
posix.sleep(1)
else
wifi_shutdown(wnet)
table["close"] = true
luci.http.write_json(table)
break
end
end
--do restart
while true do
if os.time() ~= restart_time then
posix.sleep(1)
else
wifi_reconnect(wnet)
table["restart"] = true
luci.http.write_json(table)
break
end
end
end
--]]--
function check_guest_wifi()
local uci = require("luci.model.uci").cursor()
local guest = uci:get_all("network", "eth0_3")

View File

@ -34,6 +34,8 @@ nw_set_wan_type = nwfs.nw_set_wan_type
nw_wifi_settings = nwfs.nw_wifi_settings
nw_get_wireless_channel = nwfs.nw_get_wireless_channel
nw_set_wireless_channel = nwfs.nw_set_wireless_channel
--rh_Jameson
smart_wifi_shutdown = nwfs.smart_wifi_shutdown
nw_scan_ble_switch = nwfs.nw_scan_ble_switch
nw_get_ble_device_list = nwfs.nw_get_ble_device_list
@ -86,8 +88,11 @@ function index()
page.leaf = true
page = entry({"api", "pysip"}, call("pysip"), nil, nil)
page.leaf = true
page = entry({"api", "getWifiSettings"}, call("nw_get_wifi_settings"), nil)
--rh_Jameson
page = entry({"api", "smart_wifi_shutdown"}, call("smart_wifi_shutdown"), nil)
page.leaf = true
page = entry({"api", "getWifiSettings"}, call("nw_get_wifi_settings"), nil)
page.leaf = true
page = entry({"api", "getConnectDeviceList"}, call("nw_get_connect_device_list"), nil)
page.leaf = true

View File

@ -6,6 +6,7 @@ local lfs = require "lfs"
local bfs = require "meizu.bfs"
local RC = require "meizu.r10config"
local dbfs = require "meizu.dbfs"
local posix = require "posix"
local bind_router = bfs.bind_router
local data_to_json = bfs.data_to_json
@ -365,15 +366,52 @@ function check_wifi_passwd(passwd,encryption)
end
return 0
end
function fork_smart_wifi_shutdown(wnet, close_time, open_time)
local close_interval = close_time - os.time()
local open_interval = open_time - os.time()
local cmd = string.format("/sbin/wifi down "..wnet.."; sleep 15; /sbin/wifi up "..wnet)
--local cmd = string.format("sleep %s; /sbin/wifi down; sleep %s; /sbin/wifi up;", tostring(close_interval), tostring(open_interval))
--local cmd = "/sbin/wifi "..switch.." "..wnet
exec_cmd_in_sh(cmd)
end
--[[
return coroutine.create(function()
--do close
while true do
if os.time() ~= close_time then
posix.sleep(1)
else
wifi_shutdown(wnet)
table["close"] = true
luci.http.write_json(table)
break
end
end
--do restart
while true do
if os.time() ~= restart_time then
posix.sleep(1)
else
wifi_reconnect(wnet)
table["restart"] = true
luci.http.write_json(table)
break
end
end
)
--require "MZLog".log(3, debug.getinfo(1).currentline)
]]--
function fork_restart_wifi()
local FORK_RESTART_WIFI = "sleep 1; /sbin/wifi >/dev/null 2>/dev/null; /etc/init.d/minidlna restart; /etc/init.d/samba restart; /usr/bin/gettraffic flush_wl_dev >/dev/null 2>/dev/null"
exec_cmd_in_sh(FORK_RESTART_WIFI)
local cmd = "sleep 1; /sbin/wifi >/dev/null 2>/dev/null;"
exec_cmd_in_sh(cmd)
end
function fork_restart_network()
local FORK_RESTART_WORK= "/etc/init.d/network restart"
exec_cmd_in_sh(FORK_RESTART_WORK)
local cmd = "/etc/init.d/network restart"
exec_cmd_in_sh(cmd)
end
function get_lan_ip()
@ -400,25 +438,103 @@ local function wifi_reconnect_shutdown(shutdown, wnet)
luci.sys.call("env -i /sbin/wifi reload >/dev/null 2>/dev/null")
luci.http.status(200, shutdown and "Shutdown" or "Reconnected")
--luci.http.status(200, shutdown and "Shutdown" or "Reconnected")
return
end
luci.http.status(404, "No such radio")
--luci.http.status(404, "No such radio")
end
--wifi重连
function wifi_reconnect(wnet)
if(getstate)
wifi_reconnect_shutdown(false, wnet)
end
--wifi
--wifi
function wifi_shutdown(wnet)
wifi_reconnect_shutdown(true, wnet)
end
--function: 定时wifi开关shell形式
--author rh_Jameson
function smart_wifi_shutdown()
local wnet = 'mt7628.network1'
local info = {}
--get para
--close_time = luci.http.formvalue("close_time")
--open_time = luci.http.formvalue("open_time")
--test normal
close_time = os.time() + 5
restart_time = os.time() + 10
--test exception
--close_time = os.time() - 5
--restart_time = os.time() - 10
--para err manage
if close_time < os.time() or restart_time < close_time then
info["SUCCESS"] = false
else
info["SUCCESS"] = true
end
fork_smart_wifi_shutdown(wnet, close_time, restart_time)
luci.http.write_json(info)
end
--[[
--function: 定时wifi开关
--author rh_Jameson
function smart_wifi_shutdown()
local wnet = 'mt7628.network1'
local table = {}
--get para
--local close_time = luci.http.formvalue("close_time")
--local open_time = luci.http.formvalue("open_time")
--test normal
--local close_time = os.time() + 5
--local restart_time = os.time() + 10
--test exception
local close_time = os.time() - 5
local restart_time = os.time() - 10
--para err manage
if close_time < os.time() or restart_time < close_time then
table["err"] = true
luci.http.write_json(table)
return
end
--do close
while true do
if os.time() ~= close_time then
posix.sleep(1)
else
wifi_shutdown(wnet)
table["close"] = true
luci.http.write_json(table)
break
end
end
--do restart
while true do
if os.time() ~= restart_time then
posix.sleep(1)
else
wifi_reconnect(wnet)
table["restart"] = true
luci.http.write_json(table)
break
end
end
end
--]]--

View File

@ -535,6 +535,7 @@ sinkt["keep-open"] ./socket.lua /^sinkt["keep-open"] = function(sock)$/;" f
sip ./meizu/sipfs.lua /^function sip()$/;" f
sip_get_parameters ./meizu/sipfs.lua /^function sip_get_parameters(commandId)$/;" f
sip_response_uploader ./meizu/sipfs.lua /^function sip_response_uploader(cmd, commandId, data, finishstatus)$/;" f
smart_wifi_shutdown ./meizu/nwfs.lua /^function smart_wifi_shutdown()$/;" f
socket.sinkt["http-chunked"] ./socket/http.lua /^socket.sinkt["http-chunked"] = function(sock)$/;" f
socket.sourcet["http-chunked"] ./socket/http.lua /^socket.sourcet["http-chunked"] = function(sock, headers)$/;" f
source.cat ./ltn12.lua /^function source.cat(...)$/;" f

1972
Mi_Lua/tags Normal file

File diff suppressed because it is too large Load Diff

3397
tags Normal file

File diff suppressed because it is too large Load Diff