|
本帖最后由 275891381 于 2016-8-17 15:29 编辑
补充:ESP8266-01外网控制——基于Arduino + ESP8266-01 AT透传控制LED灯并返回控制结果
http://www.geek-workshop.com/thread-27340-1-1.html
1:下载jawa环境安装
a)http://www.java.com/zh_CN/
b)http://sw.bos.baidu.com/sw-searc ... 586_8.0.1010.13.exe
c)https://yunpan.cn/cMs5MsCzcGxkL 访问密码 b3fb
2:NodeMCU Studio 2015的升级版ESPlorer下载
a)http://esp8266.ru/esplorer-latest/?f=ESPlorer.zip
b)https://nodemcu.readthedocs.io/en/dev/en/upload/
c)使用时用jawa打开根目录中的ESPlorer.jar如下
3:ESP8266-01烧写NodeMCU固件
a)固件:
b)接线方式:
c)烧写工具:
d)注意:烧写完后只断开 GPIO0---地
e)成功后重新上电串口9600会接收到
d+?嗮i4:?<+?02[?饖家V<薇!P
NodeMCU custom build by frightanic.com
branch: master
commit: c8037568571edb5c568c2f8231e4f8ce0683b883
SSL: false
modules: cjson,file,gpio,net,node,pwm,tmr,uart,wifi
build built on: 2016-03-14 02:10
powered by Lua 5.1.4 on SDK 1.4.0
lua: cannot open init.lua
4:ESP8266-01下载init.lua和kaiguan.lua
a)init.lua和kaiguan.lua下载
或者
或者https://github.com/bigiot/bigiotArduino
b)1用ESPlore打开init.lua修改第4行自己的路由器账号密码
2打开右边串口9600
3点击左下角的 save to esp 或者 send to esp 一定要看见进度条走到100%,有可能出错多下载几次,进度条位置
c)成功后串口9600会收到
IP unavaiable, Waiting...
IP unavaiable, Waiting...
IP unavaiable, Waiting...
Config done, IP is 10.10.10.104
PANIC: unprotected error in call to Lua API (cannot open kaiguan.lua)
d)打开kaiguan.lua 同样的方法下载到ESP8266-01;前两行修改为自己的账号DEVICEID和APIKEY“LED = 5”这一行需要修改为LED = 4 原因如下图我的灯放在GPIO2口,GPIO2是4
e)成功后串口9600会收到
> file.open("kaiguan.lua","w+");
> w = file.writeline
> w([==[DEVICEID = "***"]==]);
> w([==[APIKEY = "**********"]==]);
> w([==[INPUTID = "36"]==]);
> w([==[host = host or "www.bigiot.net"]==]);
> w([==[port = port or 8181]==]);
> w([==[LED = 4]==]);
> w([==[gpio.mode(LED,gpio.OUTPUT)]==]);
> w([==[cu = net.createConnection(net.TCP)]==]);
> w([==[cun("receive", function(cu, c) ]==]);
> w([==[print(c)]==]);
> w([==[r = cjson.decode(c)]==]);
> w([==[if r.M == "say" then]==]);
> w([==[ if r.C == "play" then ]==]);
> w([==[ gpio.write(LED, gpio.HIGH) ]==]);
> w([==[ ok, played = pcall(cjson.encode, {M="say",ID=r.ID,C="LED turn on!"})]==]);
> w([==[ cu:send( played.."\n" )]==]);
> w([==[ end]==]);
> w([==[ if r.C == "stop" then ]==]);
> w([==[ gpio.write(LED, gpio.LOW)]==]);
> w([==[ ok, stoped = pcall(cjson.encode, {M="say",ID=r.ID,C="LED turn off!"})]==]);
> w([==[ cu:send( stoped.."\n" ) ]==]);
> w([==[ end]==]);
> w([==[ end]==]);
> w([==[end)]==]);
> w([==[cu:connect(port, host)]==]);
> w([==[ok, s = pcall(cjson.encode, {M="checkin",ID=DEVICEID,K=APIKEY})]==]);
> w([==[if ok then]==]);
> w([==[ print(s)]==]);
> w([==[else]==]);
> w([==[ print("failed to encode!")]==]);
> w([==[end]==]);
> w([==[cu:send( s.."\n" )]==]);
> w([==[tmr.alarm(1, 60000, 1, function()]==]);
> w([==[ cu:send( s.."\n" )]==]);
> w([==[ end)]==]);
> file.close();
> dofile("kaiguan.lua");
{"M":"checkin","K":"*****","ID":"*****"}
> {"M":"WELCOME TO BIGIOT"}
f)右下角命令框改为 =node.restart() 发送重启ESP8266-01
出现“{"M":"WELCOME TO BIGIOT"}”后等待一分钟左右会出现
“{"M":"checkinok","ID":"D****","CID":"************","NAME":"***********@qq.com","T":"***********"}”;大功告成
此时串口可以断开,串口紧作为数据监控用;登陆www.bigiot.net控制灯
5:参考帖子
http://www.bigiot.net/help/20.html |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|