没错,今年我又搞崩路由器了,还好有备份,但是WOL相关配置没有备份,所以还是得做一下笔记。
要做一个siri控制PC打开的功能,流程就是如下所示
siri->快捷指令(打开url)->openwrt uttpd(接受请求)->lua(调用etherwake)->PC监听WOL唤醒
这边要记录的就是如何搭建一个openwrt的uttpd的配置
- uttpd记得安装luci,增加一个监听81端口的服务
- Lua 脚本处理程序的完整真实路径:/root/lua/http.lua。
- 文档根:/root/www(当初作为rewrite路径,但是遗失相关代码,忽略)
新建 /root/lua/http.lua
function handle_request(env)
uhttpd.send("Status: 200 OK\r\n")
uhttpd.send("Content-Type: text/plain\r\n\r\n")
local rsfile = io.popen('/usr/bin/etherwake -D -i br-lan -b xx:xx:xx:xx:xx:2A')
local rschar = rsfile:read("*all")
uhttpd.send(rschar)
end
记得重启uttpd服务
然后创建siri的快捷指令访问就行了,甚至可以在上面返回一些文字,让siri读出来
2022/09/21更新 后来发现可能还需要path,做了一点更新
function handle_request(env)
uhttpd.send("Status: 200 OK\r\n")
uhttpd.send("Content-Type: text/plain\r\n\r\n")
local path = env.PATH_INFO
if (path == '/wol')
then
local rsfile = io.popen('/usr/bin/etherwake -D -i br-lan -b xx:xx:xx:xx:xx:2A')
local rschar = rsfile:read("*all")
uhttpd.send(path)
else
uhttpd.send("Hello World.")
end
end
您必须登录才能发表评论。