如何新增json.cgi?
切换到www/cgi-bin目录,新增json.cgi
cd /www
mkdir cgi-bin
cd cgi-bin
vi json.cgi
!/bin/sh
echo “Content-Type: application/javascript”
echo “Cache-Control: no-cache, must-revalidate”
echo “Expires: Sat, 26 Jul 1997 05:00:00 GMT”
echo
VERSION=0.0.1
RELAY_CTRL=/sys/class/leds/tp-link:blue:relay/brightness
TIMINGS=tail -n+3 /etc/online.txt | sed ':a;N;$!ba;s/\n/","/g'
IP_ADDRESS=ifconfig wlan0 | sed ':a;N;$!ba;s/\n/","/g' | grep -E -o '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | head -n 1
get=$(echo "$QUERY_STRING” | sed -n ‘s/^.get=(1).*$/1/p’ | sed “s/%20/ /g”)
set=$(echo "$QUERY_STRING” | sed -n ‘s/^.set=(1).*$/1/p’ | sed “s/%20/ /g”)
callback=$(echo "$QUERY_STRING” | sed -n ‘s/^.callback=(1).*$/1/p’ | sed “s/%20/ /g”)
case “$get” in
state)
case "`cat $RELAY_CTRL`" in
0) echo "$callback({\"state\":\"off\"})"
;;
1) echo "$callback({\"state\":\"on\"})"
;;
esac
;;
timing)
echo "$callback({\"timings\":[\"$TIMINGS\"]})"
;;
esac
case “$set” in
on)
echo 1 > $RELAY_CTRL
echo "$callback({\"ok\":true})"
;;
off)
echo 0 > $RELAY_CTRL
echo "$callback({\"ok\":true})"
;;
esac
if [ -z “$get" ] && [ -z "$set” ]; then
echo “$callback({\"info\":{\"name\":\"kankun-json\",\"version\":\"$VERSION","ipAddress":"$IP_ADDRESS\"},\"links\":{\"meta\":{\"state\":\"http://$IP_ADDRESS/cgi-bin/json.cgi?get=state","timing":"http://$IP_ADDRESS/cgi-bin/json.cgi?get=timing\"},\"actions\":{\"on\":\"http://$IP_ADDRESS/cgi-bin/json.cgi?set=on","off":"http://$IP_ADDRESS/cgi-bin/json.cgi?set=off"}}})”
fi
!/bin/sh
echo “Content-Type: application/javascript”
echo “Cache-Control: no-cache, must-revalidate”
echo “Expires: Sat, 26 Jul 1997 05:00:00 GMT”
echo
VERSION=0.0.1
RELAY_CTRL=/sys/class/leds/tp-link:blue:relay/brightness
TIMINGS=tail -n+3 /etc/online.txt | sed ':a;N;$!ba;s/\n/","/g'
IP_ADDRESS=ifconfig wlan0 | sed ':a;N;$!ba;s/\n/","/g' | grep -E -o '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | head -n 1
get=$(echo "$QUERY_STRING” | sed -n ‘s/^.get=(1).*$/1/p’ | sed “s/%20/ /g”)
set=$(echo "$QUERY_STRING” | sed -n ‘s/^.set=(1).*$/1/p’ | sed “s/%20/ /g”)
callback=$(echo "$QUERY_STRING” | sed -n ‘s/^.callback=(1).*$/1/p’ | sed “s/%20/ /g”)
case “$get” in
state)
case "`cat $RELAY_CTRL`" in
0) echo "$callback({\"state\":\"off\"})"
;;
1) echo "$callback({\"state\":\"on\"})"
;;
esac
;;
timing)
echo "$callback({\"timings\":[\"$TIMINGS\"]})"
;;
esac
case “$set” in
on)
echo 1 > $RELAY_CTRL
echo "$callback({\"ok\":true})"
;;
off)
echo 0 > $RELAY_CTRL
echo "$callback({\"ok\":true})"
;;
esac
if [ -z “$get" ] && [ -z "$set” ]; then
echo “$callback({\"info\":{\"name\":\"kankun-json\",\"version\":\"$VERSION","ipAddress":"$IP_ADDRESS\"},\"links\":{\"meta\":{\"state\":\"http://$IP_ADDRESS/cgi-bin/json.cgi?get=state","timing":"http://$IP_ADDRESS/cgi-bin/json.cgi?get=timing\"},\"actions\":{\"on\":\"http://$IP_ADDRESS/cgi-bin/json.cgi?set=on","off":"http://$IP_ADDRESS/cgi-bin/json.cgi?set=off"}}})”
fi
FD.TN下载库:http://fd.tn/%E8%B7%AF%E7%94%B1%E5%99%A8%E5%88%B7%E6%9C%BA/plug/json.cgi
设置权限:
chmod -R 0755 /www/
chmod +x /www/cgi-bin/json.cgi
接着在浏览器中访问:
http://ip/cgi-bin/json.cgi
如果出现以下提示代表json.cgi安裝成功。
网页端控制面板的使用:
面板一:
下载dash面板到插座中,感谢开源项目。
FD.TN下载库:http://fd.tn/%E8%B7%AF%E7%94%B1%E5%99%A8%E5%88%B7%E6%9C%BA/plug/homedash/kankun-json/master.zip
把下载的文件通过scp上传到插座的/www/目录中,
chmod +x /www/cgi-bin/*
然后修改switches.json中的插座地址:
接下来,直接在浏览器中访问,即可出现dash页面,可以随意控制插座开关。
面板二:
下载面板源代码
FD.TN下载库:http://fd.tn/%E8%B7%AF%E7%94%B1%E5%99%A8%E5%88%B7%E6%9C%BA/plug/homedash/andash/master.zip
然后上传到插座的/www目录下:
修改cgi文件权限:
chmod +x /www/cgi-bin/*
修改/www/index.html文件中插座的信息。
修改完毕后就可以直接在浏览器中对插座进行控制了。
- & ↩
最新评论
世间因为有你而美丽!我也一直想当个志愿者,奈何身体不允许
告诉那小孩 叫哥哥
666
123
此时此刻,感慨万千,旧的一年已经过去,新的一年已经到来,展望未来,美好的日子正等 着我们去奋斗,愿在新的一年里,我们能够继续经受住考验,克服困难,春暖花开
智能插座都是扯,插座还是公牛好用
下载链接失效了 求补
连接失效了