-->
Page 2 of 2

Re: Different HTML on AP and STATION address.

PostPosted: Tue May 31, 2016 8:11 pm
by martinayotte
Oh ! that seems even simpler since you don't need to verify remoteIP() against subnets ... ;)

Re: Different HTML on AP and STATION address.

PostPosted: Tue May 31, 2016 11:00 pm
by Subhajit Das
You can also set a flag variable at wifi setup stage. Simpler and faster as no addition method call to detect ip configuration. Like this:

Code: Select allboolean WifiConnected = true;  // <- global variable
void setupWifi() {
  WiFi.mode(WIFI_STA);

  // starting wifi
  String esid ="ssid";
  String epass = "pass";

  if ( esid.length() > 2 ) {
    if ( epass.length() > 2 ) {
      WiFi.begin(esid.c_str(), epass.c_str());
    } else {
      WiFi.begin(esid.c_str());
    }
    if (WiFiAvailable()) {
      return;
    }
  }

  WiFi.disconnect();
  WifiConnected = false;  // <- this point
  WiFi.mode(WIFI_AP);
  WiFi.softAP("Web Remote Receiver");
}

Re: Different HTML on AP and STATION address.

PostPosted: Wed Jun 01, 2016 7:13 am
by martinayotte
In fact, webserver.hostHeader() and webserver.client().localIP() is returning the same thing, so in both cases you need to verify if it is part of STA or AP subnets.

Re: Different HTML on AP and STATION address.

PostPosted: Wed Jun 01, 2016 10:55 am
by Me-no-dev
the proper way to check if a given client belongs to particular side of the network in pseudo C code:
Code: Select allif(((uint32_t)client.ip & (uint32_t)ap.mask) == ((uint32_t)ap.ip & (uint32_t)ap.mask)){
  //this client is AP client
} else {
  //this client is on the STA side
}

the Host header is actually the name of the address that you typed to get to the page. It can be IP or DNS name. It is used in virtual hosting to decide which virtual server is this request for (when you host more than one site on the same server)