0

I'm trying to connect my nodeMCU to my WiFi network also i have provided ip address but it keeps printing ........ it is not connecting to the network. Below is my code.

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
// Configration Parameter for Access Poin
char * ssid_ap = ""; 
char * password_ap = "";
IPAddress ip(192, 168, 1, 158); 
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255,255,255,0);
// Set up the server object
ESP8266WebServer server (80);
// Keep track of sensor data that's going to be sent by the client
float sensor_value = 0.0;
void setup() 
{
 WiFi.mode(WIFI_AP);
 WiFi.softAPConfig(ip,gateway,subnet);
 WiFi.softAP(ssid_ap,password_ap);
 Serial.begin(115200);
 delay(10);
 Serial.println();
 Serial.println();
 Serial.print("Connecting to ");
 Serial.println(ssid_ap);
 while (WiFi.status() != WL_CONNECTED) 
 {
 delay(500);
 Serial.print(".");
 }
 Serial.println("");
 Serial.println("WiFi connected");
 
 server.begin();
 Serial.println("Server started");
 Serial.print("IP Address:"); 
 // Serial.print(WiFi.localIP());
 // Configure Server Router
 server.on("/",handleIndex); // use the top root path to report the last sensor value
 server.on("/update",handleUpdate);
 // server.begin();
}
void loop() {
 // put your main code here, to run repeatedly:
}
void handleIndex()
{
 server.send(200,"text/plain",String(sensor_value)); //we'll need to refresh the page for getting the latest value
 
}
void handleUpdate()
{
 sensor_value = server.arg("value").toFloat(); 
 Serial.println(sensor_value);
 server.send(200,"text/plain","Updated");
 
}
Juraj
18.3k4 gold badges31 silver badges49 bronze badges
asked Jul 8, 2020 at 11:25
1
  • 1
    softAP is for acting as an access point, not being a station in a pre-existing network. Commented Jul 8, 2020 at 12:31

1 Answer 1

1

You are creating a SoftAP (in essence creating a separate Wifi network). In this configuration, the ESP8266 will not "connect" to anything so polling WiFi.Status for the WL_CONNECTED status is meaningless.

To see if the SoftAP instance was created successfully, you should look at the output of WiFi.SoftAP() when you create the SoftAP instance, which returns a boolean indicating success (true) or failure. Or you should see the SSID of your newly created access point appearing on your PC or phone.

I suggest you look at the ESP8266 examples included in the Arduino IDE when you install device support for the ESP8266 to get some ideas about what you can do with a SoftAP.

answered Jul 8, 2020 at 12:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.