ESP8266WebServer server port at setup
Posted: Mon Mar 20, 2017 11:05 pm
hello All!
after some search I finally found a way to set server port at setup:
add
add
add
add
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
sorry about the bad english, its no my native laguage.
credits to:LuchoBecerra
after some search I finally found a way to set server port at setup:
add
Code: Select all
to ESP8266WebServer.h (after void begin();)void begin(uint16_t port);
add
Code: Select all
to cppvoid ESP8266WebServer::begin(uint16_t port) {
_currentStatus = HC_NONE;
_server.begin(port);
if(!_headerKeysCount)
collectHeaders(0, 0);
}
add
Code: Select all
to Wifiserver.hvoid begin(uint16_t port);
add
Code: Select all
to wifiserver.cppvoid 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);
}
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 all
boolean 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