Program ESP8266 to recieve data through WiFi connection

I build remote with 4 buttons to communicate with server via HTTP requests based on ESP8266-12-E. That part is done but right now credentials for WiFi network are fixed and hard coded in variable. I am looking for a way to change them and connect to different network while ESP8266 is running and I have no idea how to start and integrate it with code I already wrote. Could it be somehow done that PC could connect to running ESP, send request which ESP would handle by changing variables (WiFi details)?

Here is my already written code, I helped myself with example from library:

#define buttonOne 2
#define buttonTwo 4
#define buttonThree 12
#define buttonFour 14
#include <ESP8266WiFi.h>

char* ssid     = "Xperia M2_c7e3";
char* password = "bojowyborsuk69";
char* host = "";
int httpPort = 5000;
int ID = 1;

bool buttonOnePressed = false;
bool buttonTwoPressed = false;
bool buttonThreePressed = false;
bool buttonFourPressed = false;

void setup() {
  pinMode(4, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(12, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
  pinMode(13, OUTPUT);
  Serial.print("Connecting to ");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {

  Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  digitalWrite(13, HIGH);

void sendRequest(int option){
  WiFiClient client;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");

  String url = "/ev/remote/";
  url += ID;
  url += "/";
  url += option;
  Serial.print("Requesting URL: ");
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" + 
               "Connection: close\r\n\r\n");
  unsigned long timeout = millis();
  while (client.available() == 0) {
    if (millis() - timeout > 5000) {
      Serial.println(">>> Client Timeout !");

void loop() {

  if(digitalRead(buttonOne) == LOW && buttonOnePressed == false){
    buttonOnePressed = true;
    buttonOnePressed = false;

  if(digitalRead(buttonTwo) == LOW && buttonTwoPressed == false){
    buttonTwoPressed = true;
    buttonTwoPressed = false;

  if(digitalRead(buttonThree) == LOW && buttonThreePressed == false){
    buttonThreePressed = true;
    buttonThreePressed = false;

  if(digitalRead(buttonFour) == LOW && buttonFourPressed == false){
    buttonFourPressed = true;
    buttonFourPressed = false;

I am looking for a way to change them and connect to different network while ESP8266 is running

Please explain why. My laptop connects to my home network. From it, I can browse any site in the world.

If I move my laptop, I need to connect to a different network, but I don't change networks while in one spot. Why are you trying to?

Server that ESP8266 is sending requests to is local server runned by Windows application. Due to that both ESP8266 and PC that hosts server must be in the same network. Possibility to connect to ESP8266 and change the network it has to connect to, would be much more comfortable than taking remote to pieces, connecting and uploading new software.

The wifi.begin() statement is the only function that uses the ssid and pass values. They are not const, so they can be changed.

Add some code before wifi.begin() to get new values for ssid and pass, if needed.

The new values can come from an SD card or from the user, via Serial.