1

I'm using an ESP8266 web server. I'm creating a Wifi AP and I use a web server to host a website that I want to access from my mobile phone's browser:

void wifi::access_point::begin() {
  WiFi.mode(WIFI_AP_STA);
  WiFi.softAPConfig(ap_ip, ap_gateway, ap_subnet);
  WiFi.softAP(ap_ssid, ap_password);
  server.on ( "/", [this]() {
    handle_root();
  });
  server.on( "/submit", [this]() {
    handle_submit();
  });
  server.begin();
  dns_server.start(dns_port, "my_wifi_config.com", ap_ip);
}

void wifi::access_point::handle_root() {
  char html[1000];
  snprintf (html, 1000,
        "<html>\
        <head>\
        <title>Wifi Configuration</title>\
        <style>\
        body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; font-size: 1.5em; Color: #000000; }\
        h1 { Color: #AA0000; }\
        </style>\
        </head>\
        <body>\
        <center>\
        <h1>Wifi Configuration</h1>\
        <form action='/submit' method='POST'>\
        <p> Wifi SSID: </p>\
        <input type='text' name='ssid'>\
        <p> Wifi password: <\p>\
        <input type='text' name='password'>\
        <br>\
        <input type='submit' name='Submit'>\
        </form>\
        </center>\
        </body>\
        </html>"
       );
  server.send(200, "text/html", html);
}

From my desktop I can connect to the AP and access the ap_ip and everything works fine. In my phone I can also connect to the WiFi AP, but if I'm connected to the mobile network the browser doesn't load the website, it says "web page not found". If it turn it off, the website loads fine.

I would need to be able to load the website hosted by my ESP8266 web server without having to turn off my mobile data. Any idea why this is happening and how could I avoid this problem?

2
  • Since your ESP created a local network, it is unreachable from outside. You need to have the wifi on on your phone, and make that the priority network – I haven't seen this in a long time, but I used to have phones that had an option to select which was the priority network. Maybe that's the problem on your phone? Commented Apr 25, 2018 at 3:45
  • Isn't there any other way to do it? I mean, even if I try to access the local ip 192.168.1.123 it tries to use the mobile network... Commented Apr 25, 2018 at 7:10

1 Answer 1

1

Your ESP creates its own little LAN, and you can access it when you're part of this LAN. But when you're connected to mobile network you are part of global internet which doesn't know anything about your ESP's LAN. So, you need to connect them somehow.

For example - you have your home internet provider and, let's say, you have a wireless router D-Link. It means that you can make your home LAN visible to the internet via D-Link Dynamic DNS service. So, you can run your ESP as a client of the home LAN (not as AP) and you can map ESP's local IP to some globally available address.

Yes, you will loose nice domain 'my_wifi_config.com', but you will be able to access ESP's functionality, whatever it is (webpage with thermotemeter values or a button to turn on the lights).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.