ESP8266-01之NodeMCU(lua)实现远程控制LED灯

开发环境

ESP-01 wifi模块
LualLoader
NodeMCU

nodemcu_float_0.9.6-dev_20150704.bin
nodemcu_integer_0.9.6-dev_20150704.bin

将ESP-01刷写过NodeMCU固件之后,就可以用lua语言来玩wifi模块了:
ESP8266-01之NodeMCU(lua)实现远程控制LED灯_第1张图片
NodeMCU固件中的GPIO引脚定义如下:
ESP8266-01之NodeMCU(lua)实现远程控制LED灯_第2张图片

使用GPIO2控制LED灯:

wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","PWD")
print(wifi.sta.getip())

led = 4
gpio.mode(led, gpio.OUTPUT)
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
    conn:on("receive", function(client,request)
        local buf = "";
        local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP");
        if(method == nil)then
            _, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP");
        end
        local _GET = {}
        if (vars ~= nil)then
            for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
                _GET[k] = v
            end
        end
        buf = buf.."

ESP8266 Web Server

"; buf = buf.."

LED

"; local _on,_off = "","" if(_GET.pin == "ON")then gpio.write(led, gpio.HIGH); elseif(_GET.pin == "OFF")then gpio.write(led, gpio.LOW); end client:send(buf); client:close(); collectgarbage(); end) end)

ESP8266-01之NodeMCU(lua)实现远程控制LED灯_第3张图片

参考:http://blog.csdn.net/dingzz/article/details/46876503
参考:http://blog.csdn.net/menghuanbeike/article/details/73504188

k222172t97.iask.in

你可能感兴趣的:(ESP8266-01之NodeMCU(lua)实现远程控制LED灯)