Esp8266 Wifi connection

Hey, I bought an ESP8266, but I can not connect it with my wifi, I’ve used it with the example of the ESP8266 library. But for some reason, it does not connect to my router, or he gives a false ip, because if I look in the router then he has no ip and no internet connection.

#include <ESP8266WiFi.h>

#ifndef STASSID
#define STASSID "SSID"
#define STAPSK  "Passwort"
#endif

const char* ssid     = STASSID;
const char* password = STAPSK;

void setup() {
  Serial.begin(115200);

  // We start by connecting to a WiFi network

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {}

I take it you substituted your SSID and password for your WiFi connection in the sketch . I think it has to be on a 2G network.

yeah and i connect to a 2.4 ghz network

What do you get on the serial
Monitor ?

sometimes i get a connection with the fall back ip but no internet connection and the most tries i get only points