NodeMcu之AP模式通过浏览器查看信息

来源:互联网 发布:新疆广电网络上市辅导 编辑:程序博客网 时间:2024/05/18 14:12

在AP模式下通过浏览器访问192.168.4.1查看信息

--设置wifi为softap模式wifi.setmode(wifi.SOFTAP)--配置AP名称和密码apcfg={}apcfg.ssid='nodemcu'apcfg.pwd='password'wifi.ap.config(apcfg)--使用dht11获取温湿度信息dhtzt,wd,sd,wddec,sddec=dht.read11(1)tmr.alarm(1,10000,1,function()    dhtzt,wd,sd,wddec,sddec=dht.read11(1)end)--设置简单的web服务端,发送信息到html页面srv=net.createServer(net.TCP)  srv:listen(80,function(conn)    conn:on("receive",function(conn,payload)      print(payload)          local html = string.format("HTTP/1.0 200 OK\r\n"          .."Content-Type: text/html\r\n"          .."Connection: Close\r\n\r\n"          .."<title>音信霾明</title>"          .."<h1>欢迎使用音信霾明</h1>"        .."<h2>当前温度"..wd.."</h2>"        .."<h2>当前湿度"..sd.."</h2>"        )    conn:send(html)    end)    conn:on("sent",function(conn) conn:close() end)  end)