完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我已经开始绕圈子了。我正在使用 wifiManager 库的 Ken Taylor 端口并想添加我自己的网站。
我有 wifiManager 库在工作。 当凭据被硬编码时,我的网站可以正常工作。 未能将两者结合起来。 我想要实现的目标: - 使用 wifiManager 门户输入 wifi 凭据 - 连接到本地 wifi - 通过本地网络为小型网站提供服务。 - wifiManager 门户仍然处于活动状态,但仅当直接连接到 192.168.4.1 上的 ESP8266 时 在下面的草图中。ESP8266 连接到本地网络,但是当我转到新的 IP 地址时,我得到了 wifiManager 门户。我没有得到我的网站。看来强制门户仍处于活动状态。 直到我关闭门户后,循环消息才会显示。关闭门户后,会显示 Looping 消息,但本地网络没有任何响应。我的网页未提供服务。 一切都告诉我这应该是直截了当的,但我无法让它发挥作用。 代码:全选#include WiFiServer server(80); #include //needed for library #include #include #include // Onboard LED I/O pin on NodeMCU board const int PIN_LED = D4; String request = ""; unsigned long time_now = 0; unsigned long time_prev = 0; void setup() { pinMode(PIN_LED, OUTPUT); Serial.begin(115200); Serial.println("n Starting"); unsigned long startedAt = millis(); WiFi.printDiag(Serial); //Remove this line if you do not want to see WiFi password printed Serial.println("Opening configuration portal"); digitalWrite(PIN_LED, LOW); // turn the LED on by making the voltage LOW to tell us we are in configuration mode. //Local intialization. Once its business is done, there is no need to keep it around WiFiManager wifiManager; //it starts an access point //and goes into a blocking loop awaiting configuration if (!wifiManager.startConfigPortal("ESP8266","password")) { //Delete these two parameters if you do not want a WiFi password on your configuration access point Serial.println("Not connected to WiFi but continuing anyway."); } else { //if you get here you have connected to the WiFi Serial.println("connected...yeey :)"); } digitalWrite(PIN_LED, HIGH); // Turn led off as we are not in configuration mode. // For some unknown reason webserver can only be started once per boot up // so webserver can not be used again in the sketch. Serial.print("After waiting "); int connRes = WiFi.waitForConnectResult(); float waited = (millis()- startedAt); Serial.print(waited/1000); Serial.print(" secs in setup() connection result is "); Serial.println(connRes); if (WiFi.status()!=WL_CONNECTED) { Serial.println("failed to connect, finishing setup anyway"); } else { Serial.print("local ip: "); Serial.println(WiFi.localIP()); } } void loop() { // Check if a client has connected WiFiClient client = server.available(); if (client) { Serial.println("Client is connected"); // Read the first line of the request request = client.readStringUntil('r'); Serial.print(F("request = ")); Serial.println( request ); client.flush(); client.print( "HTTP/1.1 200 OKrnContent-Type: text/htmlrnrn" ); client.print( " H2 titledelay(5); client.stop(); Serial.println("Client disonnected"); time_prev = millis(); } time_now = millis(); if (time_now - time_prev > 5000) { time_prev = millis(); Serial.println( "Looping" ); } } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
142 浏览 1 评论
550浏览 6评论
460浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
442浏览 5评论
444浏览 4评论
415浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 20:28 , Processed in 0.659459 second(s), Total 73, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号