嗨,我是arduino编程的新手,我有一个问题。我已经成功地使用esp8266模块显示了wifi,也就是说,当我运行我的代码时,esp8266模块创建了wifi。它还要求输入密码,但之后没有成功连接的输出。我使用wifi.softAp(用户名,密码)的方法来创建wifi网络。我写了以下代码:
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
const char* ssid = "Jeet";//Wifi username
const char* password = "wifibin12"; //Wifi password
ESP8266WebServer server(80);
void handleRoot() {
server.send(200, "text/plain", "<h1>hello from esp8266!</h1>");
}
void setup(void) {
// put your setup code here, to run once:
Serial.begin(115200);
//WiFi.mode(WIFI_AP);
Serial.print("this is my pass");
Serial.print(password);
WiFi.softAP(ssid, password);
Serial.print("Setting soft-Ap ... ");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
//If connection successful show IP address in serial monitor
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP()); //IP address assigned to your ESP
server.on("/", handleRoot); //Which routine to handle at root location
server.begin(); //Start server
Serial.println("HTTP server started");
}
void loop() {
// put your main code here, to run repeatedly:
server.handleClient();
}当我运行代码时,我得到.............串行监视器上连续输出。如果有人知道我做错了什么,请帮助我解决这个问题。建议也将不胜感激。
发布于 2017-02-23 02:36:03
它被while循环卡住了。当连接到wifi网络(到另一个接入点)时,Wifi.status()返回WL_CONNECTED。因此,如果你想让AP正常工作,你应该尝试这样做:
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
const char* ssid = "Jeet"; //Wifi username
const char* password = "wifibin12"; //Wifi password
ESP8266WebServer server(80);
void handleRoot() {
server.send(200, "text/plain", "<h1>hello from esp8266!</h1>");
}
void setup(void) {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.print("this is my pass");
Serial.print(password);
WiFi.softAP(ssid, password);
Serial.print("Setting soft-Ap ... ");
// Wait for connection
//If connection successful show IP address in serial monitor
Serial.println("");
Serial.print("AP name ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP()); //IP address assigned to your ESP
server.on("/", handleRoot); //Which routine to handle at root location
server.begin(); //Start server
Serial.println("HTTP server started");
}
void loop() {
// put your main code here, to run repeatedly:
server.handleClient();
}并且WiFi.localIP()不返回AP的本地ip。默认值为192.168.4.1。
我推荐从这里查看文档和示例:https://github.com/esp8266/Arduino/tree/master/doc/esp8266wifi
https://stackoverflow.com/questions/42399409
复制相似问题