简体   繁体   中英

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


    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". When you use it on the ESP32 it means the ESP32, not the server you're trying to connect to. It's also known as localhost - again, shorthand for the computer or device the software is running on. It does not identify an external computer.

You need to use the actual IP address of the server you're trying to connect to. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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