李子

智能插座实现简单API功能
自建relay.cgi 用网页界面切换小K的 on / off首先登陆小K智能插座:cd /wwwmkdir cg...
扫描右侧二维码阅读全文
18
2018/09

智能插座实现简单API功能

自建relay.cgi 用网页界面切换小K的 on / off
首先登陆小K智能插座:
cd /www
mkdir cgi-bin
cd cgi-bin
vi relay.cgi
1.jpg

!/bin/sh

echo "Content-Type: text/plain"
echo "Cache-Control: no-cache, must-revalidate"
echo "Expires: Sat, 26 Jul 1997 05:00:00 GMT"
echo

RELAY_CTRL=/sys/class/leds/tp-link:blue:relay/brightness

case "$QUERY_STRING" in
state)
case "cat $RELAY_CTRL" in
0) echo "OFF"
;;
1) echo "ON"
;;
esac
;;
on)
echo 1 > $RELAY_CTRL
echo ON OK
;;
off)
echo 0 > $RELAY_CTRL
echo OFF OK
;;
esac
接下来修改一下目录权限。
chmod -R 0755 /www/
chmod +x /www/cgi-bin/relay.cgi
接下来你可以去用网页浏览器简单控制小K on & off 了。如需远程控制自行映射到外网即可。
打开 http://ip/cgi-bin/relay.cgi?on
关闭 http://ip/cgi-bin/relay.cgi?off
2.jpg

Last modification:September 18th, 2018 at 02:32 am
If you think my article is useful to you, please feel free to appreciate

Leave a Comment