首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我无法使用arduino成功连接到8266 wifi模块

我无法使用arduino成功连接到8266 wifi模块
EN

Stack Overflow用户
提问于 2017-02-23 02:25:10
回答 1查看 688关注 0票数 1

嗨,我是arduino编程的新手,我有一个问题。我已经成功地使用esp8266模块显示了wifi,也就是说,当我运行我的代码时,esp8266模块创建了wifi。它还要求输入密码,但之后没有成功连接的输出。我使用wifi.softAp(用户名,密码)的方法来创建wifi网络。我写了以下代码:

代码语言:javascript
复制
#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();
}

当我运行代码时,我得到.............串行监视器上连续输出。如果有人知道我做错了什么,请帮助我解决这个问题。建议也将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-23 02:36:03

它被while循环卡住了。当连接到wifi网络(到另一个接入点)时,Wifi.status()返回WL_CONNECTED。因此,如果你想让AP正常工作,你应该尝试这样做:

代码语言:javascript
复制
#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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42399409

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档