0

I am just trying to establish a server and it seems that I can't get the serial monitor to read the local IP of my device and my Client can't establish a connection to update the sensor value. when I run the monitor I get this:

IP Address: (IP unset)

here is my code:

    #include <ESP8266WiFi.h>
    #include <ESP8266WebServer.h>

    /// Config parameters for Access Point
    char * ssid_ap = "This Little Buddy";
    char * password_ap = "guessing";
    IPAddress local_ip(192,168,4,4);
    IPAddress gateway(192,168,4,1);
    IPAddress subnet(255,255,255,0);

    //Setup Server Object
    ESP8266WebServer server;

    //Sensors and what not here
    float sensor_value = 0.0;

    void setup() {
        //identify and start WiFi
      WiFi.mode(WIFI_AP);
      WiFi.softAPConfig(local_ip, gateway, subnet);
      WiFi.softAP(ssid_ap, password_ap);
      //sanity check
      Serial.begin(115200);
      Serial.println();
      Serial.print("IP Address: "); Serial.println(WiFi.localIP());
      //Configure the server's routes
      server.on("/", handleIndex); //using top root path for last sensor value
      server.on("/update", handleUpdate); //use this to update sensor value
      server.begin();
    }

    void loop() {
      // put your main code here, to run repeatedly:
    server.handleClient();
    }

    void handleIndex(){
      server.send(200, "text/plain", String(sensor_value));//need to refresh page to get information
    }

    void handleUpdate(){
      //value is passed by an URL argument
      sensor_value = server.arg("value").toFloat();
      Serial.println(sensor_value);
      server.send(200,"text/plain", "Updated");
    }
  • 1
    You should be using WiFi.softAPIP(); to get the AP IP address. – Majenko Mar 28 at 20:46
  • Ya I know this but I am still not getting a reponse from my client. this line isnt becoming true on the client. Serial.println("Response: "); while(client.available()){ String line = client.readStringUntil('\r'); Serial.print(line); – Fojikey Mar 28 at 21:02
  • Have you tried just running the WiFiAccessPoint example? – Majenko Mar 28 at 21:04
  • Comment // WiFi.mode(WIFI_AP); You dont need it with softAP – Codebreaker007 Mar 28 at 22:44
1

The WiFi.localIP() is a function of the STA. To print the IP address of the SoftAP, use WiFi.softAPIP().

| improve this answer | |
  • this is the answer to the question, code and output in the question. if you want to ask why the client can't connect, ask with the code and output of the client – Juraj Mar 29 at 5:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.