欢迎光临
我们一直在努力

小K智能插座实现网页控制

如何新增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安裝成功。
1.jpg

网页端控制面板的使用:
面板一:
下载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/目录中,
2.jpg
chmod +x /www/cgi-bin/*
然后修改switches.json中的插座地址:
3.jpg

接下来,直接在浏览器中访问,即可出现dash页面,可以随意控制插座开关。
4.jpg

面板二:
下载面板源代码
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目录下:
5.jpg
修改cgi文件权限:
chmod +x /www/cgi-bin/*
修改/www/index.html文件中插座的信息。
6.jpg
修改完毕后就可以直接在浏览器中对插座进行控制了。
7.jpg
8.jpg


  1. &
赞(0)
未经允许不得转载:李子博客 » 小K智能插座实现网页控制
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址