简体   繁体   English

如何在 ESP32 作为接入点和本地服务器之间建立连接

[英]How Stablish conection between ESP32 as access point and local server

I have to send a file to the local server so I use the httpClient and try to use the post with the host: http://127.0.0.1:5000/show-version , In the serial monitor, but it dosn't work, again the esp is in access point mode我必须将文件发送到本地服务器,所以我使用 httpClient 并尝试在主机上使用帖子: http://127.0.0.1:5000/show-version ,在串行监视器中,但它不起作用, esp 再次处于接入点模式


    void SendVersion (){
        client.begin(HOST);
        client.addHeader("Content-Type", "text/plain");
        int response = client.POST(version);
        if(response>0){
      
          String response = client.getString();  //Get the response to the request
        
          Serial.println(response);   //Print return code
          Serial.println(response);           //Print request answer
    
        }else{
      
          Serial.print("Error on sending POST: ");
          Serial.println(response);
      
        }
        client.end(); 
    }

127.0.0.1 is a special IP address which means "this computer or device". 127.0.0.1是一个特殊的 IP 地址,意思是“这台计算机或设备”。 When you use it on the ESP32 it means the ESP32, not the server you're trying to connect to.当您在 ESP32 上使用它时,它意味着 ESP32,而不是您尝试连接的服务器。 It's also known as localhost - again, shorthand for the computer or device the software is running on.它也被称为localhost - 同样是运行软件的计算机或设备的简写。 It does not identify an external computer.它不识别外部计算机。

You need to use the actual IP address of the server you're trying to connect to.您需要使用您尝试连接的服务器的实际 IP 地址。 How you'll find that depends on the OS the server is running - if you don't know how to do it, use Google to find out.如何找到取决于服务器运行的操作系统 - 如果您不知道如何操作,请使用 Google 查找。

And of course, if the ESP32 is in AP mode then the server it's trying to talk to needs to be connected to the ESP32's wifi network in order for the ESP32 to be able to talk to it.当然,如果 ESP32 处于 AP 模式,那么它试图与之通信的服务器需要连接到 ESP32 的 wifi 网络,以便 ESP32 能够与之通信。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM