我是靠谱客的博主 娇气小蜜蜂,这篇文章主要介绍ESP8266例程,现在分享给大家,希望可以做个参考。

乐鑫的这个开发板, 可以用LUA来编程, 下面的例子是一个简单的web服务器, 当你用浏览器访问wifi的IP时,后面加一个http://ip/abc123, 这样就可以给wifi模组发命令了.

srv=net.createServer(net.TCP,10)
srv:listen(80,function(conn)
conn:on("receive", function(conn, pl)
cmd=string.sub(pl,6,10)
print(cmd)
if (cmd=="abc12") then
  print("yes")
elseif (cmd=="abc13") then
  print("why")
end
conn:send("Hello, NodeMCU.")
end)
conn:on("sent", function(conn) conn:close() end)
end)

神奇...

内核到底是不是linux呢?

设置wifi为softAP:

wifi.setmode(wifi.SOFTAP)
local cfg={}
cfg.ssid="denis_nodemcu"
cfg.pwd="87654321"
wifi.ap.config(cfg)

设置成station:

print("ShipID["..node.chipid().."] Starting...")

print("WiFi connecting...")
wifi.setmode(wifi.SOFTAP)

--wifi.sta.config("fuckapple","11111111")
wifi.sta.connect()

定时器加IO例子:

led=1
gpio.mode(led, gpio.OUTPUT)

switch=0;
tmr.alarm(1, 1000, 1, function ()
  if(switch==0) then
     gpio.write(led, gpio.HIGH)
     switch=1;
  elseif(switch==1) then
     gpio.write(led, gpio.LOW)
     switch=0;
  end
end
)

停止定时器:

tmr.stop(1)
gpio.write(led, gpio.LOW)

 

基本两天就玩到这里吧.

 

转载于:https://www.cnblogs.com/Montauk/p/5461931.html

最后

以上就是娇气小蜜蜂最近收集整理的关于ESP8266例程的全部内容,更多相关ESP8266例程内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(134)

评论列表共有 0 条评论

立即
投稿
返回
顶部