Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By seedseifer
#64031 hello All!

after some search I finally found a way to set server port at setup:

add
Code: Select allvoid begin(uint16_t port);
to ESP8266WebServer.h (after void begin();)

add
Code: Select allvoid ESP8266WebServer::begin(uint16_t port) {
  _currentStatus = HC_NONE;
  _server.begin(port);
  if(!_headerKeysCount)
    collectHeaders(0, 0);
}
to cpp

add
Code: Select allvoid begin(uint16_t port);
to Wifiserver.h

add
Code: Select allvoid WiFiServer::begin(uint16_t port) {
    close();
   _port = port;
    err_t err;
    tcp_pcb* pcb = tcp_new();
    if (!pcb)
        return;

    ip_addr_t local_addr;
    local_addr.addr = (uint32_t) _addr;
    pcb->so_options |= SOF_REUSEADDR;
    err = tcp_bind(pcb, &local_addr, _port);

    if (err != ERR_OK) {
        tcp_close(pcb);
        return;
    }

    tcp_pcb* listen_pcb = tcp_listen(pcb);
    if (!listen_pcb) {
        tcp_close(pcb);
        return;
    }
    _pcb = listen_pcb;
    tcp_accept(listen_pcb, &WiFiServer::_s_accept);
    tcp_arg(listen_pcb, (void*) this);
}
to wifiserver.cpp

change normal server begin to server.begin(8080); or another port.


if you use captive portal and isIP function pay attention on server.hostheader() now you have to include the port, my I changed to
Code: Select allboolean isIp(String str) {
  for (int i = 0; i < str.length(); i++) {
    int c = str.charAt(i);
    if (c != '.' && (c < '0' || c > '9') && c != ':') {
      return false;
    }
  }
  return true;
}


sorry about the bad english, its no my native laguage.

credits to:LuchoBecerra