Nodemcu通过网页Web设置sta.config配置
来源:互联网 发布:国泰安怎么下载数据 编辑:程序博客网 时间:2024/06/15 22:40
首先,感谢Zexi on GitHub 213行代码写出一个HttpServer真的服了。还带有GZip压缩,先膜拜大神。
HttpServer By Zexi
访问这个网址,把httpServer.lua复制下来,下面我们就要用这个文件,建立自己的配置网页。
我们的需求是,NodeMCU用AP+Station模式,启动一个叫Config的热点,用户连接后,可以通过192.168.1.1来进行访问,然后输入WIFI的SSID和密码,就能让NodeMCU自动连接!
天太晚了,不多BB,直接上代码。
init.lua
wifi.setmode(wifi.STATIONAP)cfg={}cfg.ssid="config" --我们的NodeMcu热点cfg.pwd="00000000"--密码wifi.ap.config(cfg)cfg2 ={ip="192.168.1.1",--设置IPnetmask="255.255.255.0",--子网掩码gateway="192.168.1.1"--默认网关}wifi.ap.setip(cfg2)wifi.sta.autoconnect(1)--自动连接dofile('httpServer.lua')--执行HttpServer.luahttpServer:use('/config', function(req, res) if req.query.ssid ~= nil and req.query.pwd ~= nil then print(req.query.ssid..req.query.pwd) config={} config.ssid=req.query.ssid config.pwd=req.query.pwd wifi.sta.config(config) end res:send('<head><meta charset="UTF-8"><title>配置终端</title></head><h1>您设置的wifi是:'..req.query.ssid..',请等待红灯常亮即连接完成。</h1>')end)httpServer:listen(80) --启动Server
index.html
别忘了把这个文件上传哦~
<!DOCTYPE html><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>配置终端</title></head><body style="text-align:center;background:#f8fffbb2;"> <h1>配置页面</h1> <form action="/config" method="get"> <label>WiFi</label> <input type="text" name="ssid" /> <br /> <label>密码</label> <input type="password" name="pwd" /> <br /> <input type="submit" value="确认" style="background:#678df9;height:40px;width:60px;border-radius:5px;border:none;outline:none;"/> </form> <p style="max-width:50vw;margin:auto;">注意:由于NodeMCU内存很小,附近热点过多时,扫描热点会造成内存不足自动重启。请手动输入WIFI信息进行配置。</p></body><style> input{ margin-bottom:30px; }</style></html>
这可以说是最简单的配置界面了,但是大家可以根据这个自己开发需要的功能,就需要靠自己发挥了!!
阅读全文
0 0
- Nodemcu通过网页Web设置sta.config配置
- Web.Config 文件中的设置配置网页身份验证
- 通过web.config设置数据库连接串
- 通过配置web.config发电子邮件详解
- 通过web.config配置数据库连接池
- 通过编程读写Web.config配置节
- 通过编程读写Web.config配置节
- 通过configSource提高web.config配置灵活性
- 通过configSource提高web.config配置灵活性
- 通过configSource提高web.config配置灵活性
- 通过configSource提高web.config配置灵活性
- 连接字符串设置(Web.config配置)
- ASP.NET2.0中通过web.config设置数据库连接串
- asp.net通过web.config设置网站默认页
- 通过继承ConfigurationSection,在web.config中增加自定义配置
- 通过继承ConfigurationSection,在web.config中增加自定义配置
- 通过web.config可配置多个数据库连接
- 通过继承ConfigurationSection,在web.config中增加自定义配置
- Slim研读笔记七乱入篇之Monolog(补)
- NodeMCU检测环境亮度GY30程序
- ConcurrentHashMap一点理解
- 解析 Shiro-Spring 过滤器全流程
- stm32内存分配(全解释详细)
- Nodemcu通过网页Web设置sta.config配置
- react中路由和按需加载问题
- hannuota
- Bailian2786 Pell数列【数列】(POJ NOI0102-1788,POJ NOI0103-1788)
- 如何高效与人聊天
- Vmware添加磁盘的方法:扩展磁盘
- 腾讯副总裁马斌:数字时代下国家网络安全面临全新机遇与挑战
- 埃里克·施密特辞任Alphabet 执行主席,继续担任董事会董事
- 京东正式上线拍拍二手,计划三年内投入10亿