我无法使用arduino成功连接到8266 wifi模块
问题描述:
嗨,我是arduino编程的新手,我有一个问题。我已经成功设法使用esp8266模块显示WiFi,即当我运行我的代码时,esp8266模块创建一个wifi。它还要求输入密码,但之后没有成功连接的输出。我正在使用wifi.softAp(用户名,密码)方法创建wifi网络。我写了下面的代码:我无法使用arduino成功连接到8266 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();
}
当我运行代码时,我得到.............在串口监视器上不断输出。请帮助我解决这个问题,如果有人知道我做错了什么。建议也将不胜感激。
答
它陷入while循环。 Wifi.status()在连接到wifi网络(返回到另一个接入点)时返回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
谢谢@Petri。它为我工作。但是,我无法在串行监视器上获得serial.print命令输出,即在串行监视器上没有显示上述serial.print输出。你能帮我一下,或者给我一个建议,说明它没有出现。我再次感谢你的帮助。 – Jeet
您是否使用arduino ide的串口监视器?你有正确的波特率(115200)吗?同时检查接地连接。 –
是的,我使用的是Arduino IDE的串行监视器,并且我已将波特率设置为115200.可以让我知道您指的是什么接地连接。我正在使用ESP 8266 01模块。你能否让我知道什么闪光灯大小可用于获得正确的输出。我正在向您发送工具配置截图的链接。您可以通过以下链接查看屏幕截图:\t drive.google.com/open?id=0Bw8dCxSUylyKeUlkNjRZZVpXRHc。请让我知道如果变化reuired。我非常感谢你的帮助 – Jeet