作者:zls121zls | 更新時間:2017-01-17 | 瀏覽量:3052
在貝殼網站上申請了一片匯思銳的8266開發底板
首先下載樂鑫的固件然后按照下圖燒寫固件
打開匯思銳調試工具,按照上面一步一步設置
點擊airkiss 按鈕進入airkiss 配網模式。
AT+RST
OK
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x40100000, len 1856, room 16
tail 0
chksum 0x63
load 0x3ffe8000, len 776, room 8
tail 0
chksum 0x02
load 0x3ffe8310, len 552, room 8
tail 0
chksum 0x79
csum 0x79
2nd boot version : 1.5
SPI Speed : 40MHz
SPI Mode : DOUT
SPI Flash Size & Map: 16Mbit(512KB+512KB)
jump to run user1 @ 1000
rl??r?
ready
----------------------------
AT+CWMODE=1
OK
AT+CWSTARTSMART=2
OK
----------------上述測試說明模塊已經焊接沒問題----------------------------------------------------
環境搭建:
2、固件燒錄工具:esp8266 flash升級燒寫燒錄工具v2.1綠色版
3、燒寫教程:參考difiot
4、以上所有資料訪問百度云盤
NodeMCU所有資料和源碼
基礎編程手冊
二、硬件介紹
匯思銳開發板 | |||
開發板標識 | 匯思銳開發板 | NODEMCU引腳 | LED等亮 |
LED1 | GPIO4 | IO2 | 低有效 |
LED2 | GPIO14 | IO5 | 高有效 |
LED3 | GPIO12 | IO6 | 低有效 |
LED4 | GPIO5 | IO1 | 低有效 |
三、程序的編寫
init.lua 文件
匯思銳開發板 | |||
開發板標識 | 匯思銳開發板 | NODEMCU引腳 | LED等亮 |
LED1 | GPIO4 | IO2 | 低有效 |
LED2 | GPIO14 | IO5 | 高有效 |
LED3 | GPIO12 | IO6 | 低有效 |
LED4 | GPIO5 | IO1 | 低有效 |
config.lua文件
runtime.lua文件
dofile("config.lua")
bLive=0
bOnLine=0
gpio.mode(config.LED1,gpio.OUTPUT)
gpio.mode(config.LED2,gpio.OUTPUT)
gpio.mode(config.LED3,gpio.OUTPUT)
gpio.mode(config.LED4,gpio.OUTPUT)
gpio.write(config.LED1, gpio.HIGH)
gpio.write(config.LED2, gpio.LOW)
gpio.write(config.LED3, gpio.HIGH)
gpio.write(config.LED4, gpio.HIGH)
cu = net.createConnection(net.TCP)
cu:connect(config.port, config.host)
cu:on("receive", function(cu, c)
print(c)
r = cjson.decode(c)
--如果存活標記為1,置為0
if r.M=="isOL" then
bLive=0
end
tmr.alarm(1, 10000, 1, function()
--checkin和心跳
dofile("checkIn.lua")
--在線后再讀取數據,發送年,接收命令
end)
--執行命令
dofile("sayCommand.lua")
end)
checkin.lua文件
dofile("config.lua")
bLive=0
bOnLine=0
gpio.mode(config.LED1,gpio.OUTPUT)
gpio.mode(config.LED2,gpio.OUTPUT)
gpio.mode(config.LED3,gpio.OUTPUT)
gpio.mode(config.LED4,gpio.OUTPUT)
gpio.write(config.LED1, gpio.HIGH)
gpio.write(config.LED2, gpio.LOW)
gpio.write(config.LED3, gpio.HIGH)
gpio.write(config.LED4, gpio.HIGH)
cu = net.createConnection(net.TCP)
cu:connect(config.port, config.host)
cu:on("receive", function(cu, c)
print(c)
r = cjson.decode(c)
--如果存活標記為1,置為0
if r.M=="isOL" then
bLive=0
end
tmr.alarm(1, 10000, 1, function()
--checkin和心跳
dofile("checkIn.lua")
--在線后再讀取數據,發送年,接收命令
end)
--執行命令
dofile("sayCommand.lua")
end)
sayCommand.lua
--sayCommand.lua
gpio.mode(config.LED1,gpio.OUTPUT)
gpio.mode(config.LED2,gpio.OUTPUT)
gpio.mode(config.LED3,gpio.OUTPUT)
gpio.mode(config.LED4,gpio.OUTPUT)
if r.M == "say" then
local commander=r.C
if commander == "play" then
print("play:LED1 turn on!")
gpio.write(config.LED1,gpio.LOW)
ok, played = pcall(cjson.encode, {M="say",ID=r.ID,C="play:LED1 turn on!"})
cu:send( played.."\n" )
elseif commander == "stop" then
print("stop:LED1 turn off!")
gpio.write(config.LED1,gpio.HIGH)
ok, stoped = pcall(cjson.encode, {M="say",ID=r.ID,C="stop:LED1 turn off!"})
cu:send( stoped.."\n" )
--------1--------
elseif commander == "up" then
print("up:LED2 turn on!")
gpio.write(config.LED2,gpio.HIGH)
ok, uped = pcall(cjson.encode, {M="say",ID=r.ID,C="up:LED2 turn on!"})
cu:send( uped.."\n" )
elseif commander == "plus" then
print("plus:LED2 turn off!")
gpio.write(config.LED2,gpio.LOW)
ok, plused = pcall(cjson.encode, {M="say",ID=r.ID,C="plus:LED2 turn off!"})
cu:send( plused.."\n" )
--------2--------
elseif commander == "pause" then
print("pause:LED3 turn on!")
gpio.write(config.LED3,gpio.LOW)
ok, paused = pcall(cjson.encode, {M="say",ID=r.ID,C="pause:LED3 turn on!"})
cu:send( paused.."\n" )
elseif commander == "right" then
print("right:LED3 turn off!")
gpio.write(config.LED3,gpio.HIGH)
ok, righted = pcall(cjson.encode, {M="say",ID=r.ID,C="right:LED3 turn off!"})
cu:send( righted.."\n" )
--------3--------
elseif commander == "down" then
print("right:LED4 turn on!")
gpio.write(config.LED4,gpio.LOW)
ok, downed = pcall(cjson.encode, {M="say",ID=r.ID,C="down:LED4 turn on!"})
cu:send( downed.."\n" )
elseif commander == "forward" then
print("forward:LED4 turn off!")
gpio.write(config.LED4,gpio.HIGH)
ok, forward = pcall(cjson.encode, {M="say",ID=r.ID,C="forward:LED4 turn off!"})
cu:send( forward.."\n" )
--------4--------
elseif commander == "offOn" then
print("offOn:LED ALL off!")
gpio.write(config.LED1,gpio.HIGH)
gpio.write(config.LED2,gpio.LOW)
gpio.write(config.LED3,gpio.HIGH)
gpio.write(config.LED4,gpio.HIGH)
ok, offOned = pcall(cjson.encode, {M="say",ID=r.ID,C="offOn:LED ALL off!"})
cu:send( offOned.."\n" )
elseif commander == "minus" then
print("minus:LED ALL off!")
gpio.write(config.LED1,gpio.LOW)
gpio.write(config.LED2,gpio.HIGH)
gpio.write(config.LED3,gpio.LOW)
gpio.write(config.LED4,gpio.LOW)
ok, minused = pcall(cjson.encode, {M="say",ID=r.ID,C="minus:LED ALL ON!"})
cu:send( minused.."\n" )
--------5--------
elseif commander == "left" then
print("^~^left^~^")
ok, lefted = pcall(cjson.encode, {M="say",ID=r.ID,C="^~^left^~^"})
cu:send( lefted.."\n" )
elseif commander == "backward" then
print("^~^backward^~^")
ok, forwarded = pcall(cjson.encode, {M="say",ID=r.ID,C="^~^forward^~^"})
cu:send( forwarded.."\n" )
end
end