代码之家  ›  专栏  ›  技术社区  ›  Alex

Arduino如何使用ESP2668创建wifi接入点?

  •  0
  • Alex  · 技术社区  · 7 年前

    我使用的是Arduino型设备RobotDyn WiFi D1 R2,内置ESP8266 WiFi模块。有两张照片: enter image description here 我想使用从那里获取的官方图书馆创建WiFi接入点:

    https://arduino-esp8266.readthedocs.io/en/2.5.0-beta2/installing.html

    请看我的草图(代码):

    #include <ESP8266WiFi.h> // Include the Wi-Fi library
    #include <WiFiClient.h>
    #include <ESP8266WebServer.h>
    #include <ESP8266mDNS.h>
    
    const char *ssid = "ESP8266Test";  // The name of the Wi-Fi network that will be created
    const char *password = "vadimn231"; // The password required to connect to it, leave blank for an open network
    
    ESP8266WebServer server(80);
    
    void handleRoot() {
      server.send(200, "text/html", "<h1>You are connected</h1>");
      // Go to http://192.168.4.1 in a web browser connected to this access point to see it.
    }
    
    void setup() {
      Serial.begin(115200);
    
      WiFi.softAP(ssid); // Start the access point
    
      Serial.println("");
      IPAddress myIP = WiFi.softAPIP();
      Serial.print("Access Point IP address: ");
      Serial.println(myIP);
      Serial.print("Access Point \"");
      Serial.print(ssid);
      Serial.println("\" started");
    
      server.on("/", handleRoot);
      server.begin();
    
      Serial.println("HTTP server started");
    }
    
    void loop() {
      server.handleClient();
    }
    

    此代码正在工作,但未创建WiFi热点。所以,问题是:如何使用ESP8266在Arduino上创建工作接入点? 我将感谢任何帮助或建议!

    非常感谢。

    有时候,我可以强迫它工作。方法:首先将Arduino连接到任何现有网络,然后一切正常。但我怀疑,这是正确的解决方案。

    https://drive.google.com/open?id=1sWYOxqG3EaeYfM6akXVU5omP3jr7Ki2c

    1 回复  |  直到 7 年前
        1
  •  1
  •   Nitro    7 年前

    使用此代码,您的TCP IP设置似乎没有初始化,但当您通过DHCP服务器将其连接到外部wifi时,它们会被设置。

    我有一个适合我的功能。你可能想试试。

    ConfigAndStartAp(){
      while(!(WiFi.softAPConfig(IPAddress(192, 168, 4, 2) , IPAddress(192, 168, 4, 2) , IPAddress(255, 255, 255, 0) )));
      while(!(WiFi.softAP( ssid)));
    }