ESP8266 disconnect from router

Hello.Sorry my English is poor.
I've connected esp8266 to my router. now I want to disconnect it from router.
How could I do that?
Is there any way except below function:
WiFi.disconnect();
thanks.

Why not use the proper function ?

How can I use the proper function?
which function.

What is wrong with

WiFi.disconnect();

You should read the documentation.

Here are two ways:

WiFi.disconnect();
WiFi.mode(WIFI_OFF);

They are different.
WiFi.dicsonnect() turns off the radio but also erases any saved access point credentials.
WiFi.mode(WIFI_OFF) merely turns off the radio but saves previously used credentials.

Which one you use depends on what you are wanting to do.

--- bill

Or with at command AT+CWQAP

leoncorleone:
Hello.Sorry my English is poor.
I've connected esp8266 to my router. now I want to disconnect it from router.
How could I do that?
Is there any way except below function:
WiFi.disconnect();
thanks.

What are you trying to do and why ?

I have connected to esp8266 via modem and directly by phone like below picture.

Now I just want to disconnect esp8266 from modem. I use that function, but when I use, both of connections are disconnected.

It sounds like you have the part in both station and accesspoint mode?
and now you just want it to be one of those modes?

WiFi.mode() can be used to change modes.

https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/readme.html
https://esp8266.github.io/Arduino/versions/2.1.0-rc1/doc/libraries.html#wifi-esp8266wifi-library

--- bill

another problem I have.
I've connected to ESP8266 by my smartphone locally.
Now I want to set ssid and password of my modem by html request.
I use below function, but when I request by my smartphone, the response not come back.I checked and the port of connection closed.So what can I do?

WiFi.begin(_ssid,_password);