Skip to content

v2.4.0 - ESP8266WebServer , Wish option that we can change port in setup() #4109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TridentTD opened this issue Jan 7, 2018 · 4 comments
Closed

Comments

@TridentTD
Copy link

TridentTD commented Jan 7, 2018

Basic Infos

Wish option that we can change port in setup().

Hardware

Hardware: Wemos D1 Mini
Core Version: 2.1.0-rc2

Description

I try to create ESP8266WebServer and use config structure.
In my config structure has web_port for config ESP8266WebServer's port.

How I can change port of ESP8266WebServer in setup() ?

Settings in IDE

Module: Wemos D1 Mini
Flash Size: 4MB
CPU Frequency: 80Mhz
Flash Mode: qio
Flash Frequency: 40Mhz
Upload Using: SERIAL
Reset Method: nodemcu

Sketch

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

ESP8266WebServer webserver(80);

struct  __config {
   uint8_t ssid[32];
   uint8_t passwod[64];
   uint16_t  web_port;
} config;

void setup() {
        sprintf( (char*) config.ssid , "%s",  "-----SSID-----");
        sprintf( (char*) config.password, "%s",  "-----PASSWORD-----");
        config.web_port = (uint16_t) 8080;

        Serial.begin(115200);
        WiFi.begin((char*) config.ssid, (char*) config.password);
        while(!WiFi.isConnected()) delay(400);
        Serial.printf("WiFi connected , IP : %s\r\n", WiFi.localIP().toString().c_str());

        //  At here I wish to change webserver 's port  
        // by config after declare ESP8266WebServer's object.
        //webserver( config.web_port);   

        webserver.on("/", [](){  webserver.send(200, "text/html", "Hello Webserver"); });
        webserver.begin();
}

void loop() {
        webserver.handleClient();
}
@caverna
Copy link
Contributor

caverna commented Jan 7, 2018

Man, does this line gives you any clue? ;-)
ESP8266WebServer webserver(80);

@igrr
Copy link
Member

igrr commented Jan 8, 2018

@caverna

here I wish to change webserver 's port by config after declare ESP8266WebServer's object.

(emphasis mine)

I think this is a valid request, perhaps we can fix the issue with assignment between ESP8266WebServer objects to support it.

@igrr
Copy link
Member

igrr commented Jan 8, 2018

Closing as same basic issue as #4085.
@TridentTD please follow to the linked issue and click "Subscribe" to receive notifications.

@igrr igrr closed this as completed Jan 8, 2018
@TridentTD
Copy link
Author

Thank you @igrr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants