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

xiaoxiao2021-02-28  118

在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)
转载请注明原文地址: https://www.6miu.com/read-22151.html

最新回复(0)