Skip to content
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

Request: Configure hostname #527

Closed
gepd opened this issue Feb 18, 2018 · 27 comments
Closed

Request: Configure hostname #527

gepd opened this issue Feb 18, 2018 · 27 comments
Labels
Discussion Further Discussion ongoing enhancement Feature Request QA Quality Assurance testing needed
Milestone

Comments

@gepd
Copy link

gepd commented Feb 18, 2018

From #513
Current workaround (I've only test it on esp32)

void WiFiEvent(WiFiEvent_t event){
    switch(event) {
        case SYSTEM_EVENT_AP_START:
            WiFi.softAPsetHostname(HOSTNAME);
            break;
        case SYSTEM_EVENT_STA_START:
            WiFi.setHostname(HOSTNAME);
            break;
        default:
            break;
    }
}

void setup(){
    WiFi.disconnect(true);
    WiFi.onEvent(WiFiEvent);
    WiFi.begin();

// checks connection and perform a call to the config portal if it's neccessary
}
@tablatronix tablatronix added the enhancement Feature Request label Feb 18, 2018
@tablatronix tablatronix added this to the dev milestone Feb 18, 2018
@tablatronix
Copy link
Collaborator

I don't really understand how hostname on esp works, is this mdns hostnames?
Does it use local.* ?

@tablatronix
Copy link
Collaborator

tablatronix commented Feb 18, 2018

Could you set softaphostname in the _apcallback and sta after autoconnect success also?
Does this need to be in core?

@tablatronix tablatronix added the Discussion Further Discussion ongoing label Feb 18, 2018
@tablatronix
Copy link
Collaborator

so these seem to be dhcp client ids maybe ?

I still cannot figure out when to set these, some says before , some says after ap and sta are enabled.

tablatronix added a commit that referenced this issue Feb 18, 2018
@tablatronix
Copy link
Collaborator

tablatronix commented Feb 18, 2018

I am setting before and after for sta, well see which ones work for which chip, and adjust as needed.
Obviously we can only set after if already connected etc. ( I added a reconnect to handle this scenario)

Any tips on how to test this ?
my router shows my esp32 dhcp client name correctly, so that works.

  • test esp32 ap hostname
  • test esp32 sta hostname
  • test esp8266 sta hostname
  • test sta static ip
  • test ap static ip

Must also test with wifi.config since it stop and start dhcp, make sure hostname still works with static ips

Using the same host name for both, not sure if we need to differentiate at this point

@gepd
Copy link
Author

gepd commented Feb 18, 2018

Yes, it's dhcp client ids

I've tried:

WiFi.begin();
WiFi.setHostname("name");

But it makes the device crash, but if you reverse it, it works

WiFi.setHostname("name");
WiFi.begin();

I took that piece of code from this example, it sets AP and STA:
https://github.com/copercini/esp32-iot-examples/blob/master/WiFi_nonBlocking/WiFi_nonBlocking.ino

Could you set softaphostname in the _apcallback and sta after autoconnect success also?
Does this need to be in core?

I'm not sure. Normally it need to be done before WiFi.begin But the flag SYSTEM_EVENT_AP_START make me doubt where it's performed

@tablatronix
Copy link
Collaborator

tablatronix commented Feb 18, 2018

I guess we could just use events also, but thats one more thing that could introduce bugs if its not needed. Well see

events do not work unless we can set them up before sta is enabled, which is going to be near impossible with autoconnect, and even then we need to know hostname very early, so store it, then we need to read it before start_sta, right now this is ok because autostart is not implemented yet, but it will be, I think setting it and restarting is the best most stable solution for now, although this might create issues with routers that cache the names, we will have to see, and events are also a pain , because we need to have access to the class in the event call backs to get the hostnames

@gepd
Copy link
Author

gepd commented Feb 19, 2018

I've tested AP and STA in esp32 and both cases are working

Just note if you are in STA mode, STA hostname will be what you had set, and STA will be espressif and if you are in AP will be the opposite.

You can check this from the Info section

@tablatronix
Copy link
Collaborator

ok I think i have a decent working solution now

tablatronix added a commit that referenced this issue Feb 19, 2018
@tablatronix
Copy link
Collaborator

tablatronix commented Feb 19, 2018

I am just setting hostname, and reconnecting for now if already connected, else it works fine normally.
Alternative is to restart the dhcp server, but I do not think that is exposed at all.

sta hostnames confirmed with dhcp wireshark
ip.src == 0.0.0.0 dhcp hostname as column

@gepd
Copy link
Author

gepd commented Feb 19, 2018

I've just check it and there is not problem in STA (both names are the same) but not in AP

@tablatronix
Copy link
Collaborator

Esp8266 has no apname config
I have not tested esp32 aphostnames yet.

It is nor working at all?

@gepd
Copy link
Author

gepd commented Feb 19, 2018

When you are in STA
STA Hostname: newname
AP Hostname: newname

In AP:
AP hostname: newname
STA hostname: espressif

is not a big deal, but if it's fixed would be good

@tablatronix
Copy link
Collaborator

which board?

@tablatronix
Copy link
Collaborator

how do you test ap hostname ? I dont seem to see it coming across in wirreshark, says "server hostname not given"

tablatronix added a commit that referenced this issue Feb 19, 2018
@tablatronix
Copy link
Collaborator

Might want to give it a try again.

On esp32 ap, info shows both newname, I have to confirm via network of course.

tablatronix added a commit that referenced this issue Feb 19, 2018
@gepd
Copy link
Author

gepd commented Feb 19, 2018

I'm working with a ESP32

Now both cases are working.
I checked that from my router, and also from the Info page of WM

First I start the portal and check the Info page (No WiFi connection) then I connect the device to a network and check it again.

Now it's working as spected.
I don't have an esp8266 here to test it

@tablatronix
Copy link
Collaborator

I still cannot figure out what the aphostname actually does. Shrug,

@gepd
Copy link
Author

gepd commented Feb 19, 2018

I don't know either, for me it has not sense to change it, but as it's displayed in the info page, is a little weird to read two hostnames with different names

@tablatronix tablatronix added the QA Quality Assurance testing needed label Feb 21, 2018
isots-code added a commit to isots-code/WiFiManager that referenced this issue May 31, 2018
* update library.properties

* clean up parameters

* oops

* clean up .h file

* fix tabs

* fix up parameters

* fixup debugging

* fixes paramid issues

paramid must be alphanumeric and adds {I} token support to use ids as input names if we make that optional.

* debugging clean

* oops

* adds exit to readme

* moved http strings to include, added token flags

* typo

* cleanup

* moved all html strings out of code

* more string tokens

* fix paramscount, oops

* doh...

* tzapu#454 adds WIFI_MANAGER_OVERRIDE_STRINGS

I dont feel like resolving conflicts

* fixup merge

* ajax test

* Bug fix for problem discovered when setting length to 1 for additional parameters

The initialization of the buffer holding the value stopped before the last character and storage did not take into account the extra-byte for end of string.

* debugsoftapconfig for esp32

* make debug funcs public

* fix esp32 examples

* fix esp32 wifi.ssid

* Update README.md

Esp32 warning

* camelcase _staShowStaticFields

* readme

* adds webclient checking for timeout delay

* remove reset, no reason for it

* converting token strings, in progress broken

* all tokens now in strings

* implemented info strings for esp32

* fix some html bugs

* change uptime

* infohelp align html

* added webserver precompiler warning

updates readme

* readme

* template

* Lower RAM usage of library

Place remaining debug messages into Flash using F().

* Update WiFiManager.cpp

* Update WiFiManager.cpp

* Update WiFiManager.cpp

* Create contributing.md

* Create ISSUE_TEMPLATE.md

* rename

* rename

* fix esp32 esp8266 bug

* moved strings to flash

* refactor ip form outputs

* adds disconnect method for users

non persistent disconnect

* publicized debug helpers

* ugh aliases

* moved all tokens to strings.h

* adds toggle for scan quality as percentage

`setScanDispPerc` until we have decent remplating

* oops

* defaulting to icons

* cleanup

* some more strings in progmem

* fix sketch size

* editing strings

* more strings cleanup

* refix memsketch

* more string cleanup

* left in debug

* comments

* typo

* dup define

* moved _wifissidprefix to progmem

* esp32 strings progmem

* strings

* file headers

* missed one file header

* Update ISSUE_TEMPLATE.md

* Update ISSUE_TEMPLATE.md

* documenting source

* change wifiscan detaisl to css for toggling

* more strings progmem

* oops broke lock icons

* bugged

* tzapu#528 adds getLastConxResult

* gitignore

no gitignore? add more stuff

* fix info page and adds esp32 aphostname

* testing tzapu#527

* fixes tzapu#527

* fix tzapu#527 for esp8266

* adds getWiFiIsSaved()

* doc blocks, reformatting code

* stability tzapu#527

* clean up

* remove debugging

* add result checking tzapu#527

* remove debugging

* change some uneeded ints

* feature tzapu#533 failure details

* allow empty ssids, bail earlier

* template update

* debuggin esp32 auth fail events

* tzapu#528

using a static var for esp32 event for now to get this working and test. Probably not the best, not sure what the best option is here for esp32 onevent static member function callbacks

* tzapu#528 WL_DISCONNECTED support for testing

* tzapu#534

* change webserver pointer to using

* remove warning

* fix some minor warnings

* adding menu control, in progress

* fix bug

* finish up menu customization

* fix template

* add param help

* fix up menus

* fix param crash

* fix menu and param save

* fix resetsettings

* adds mdns support

* change defs

* simplify debug

* comments

* fix menuids

* add wifiscan preloading with cache

This uses core scan object and assumes its lifetime, I am not sure what the scope is or how long it lives, will have to convert to local copy if its being lost, caching for 60s after startweb portal and 10s after root load, refresh bypasses cache

* fix order

* add preloadscan enable

* fix webserver pointer

* comments

* tzapu#542 handler

* tzapu#546 fix?

Since I do not know how to fix the delegated constructors properly, this should fix the issue for now

* oops tzapu#546

* adds erase

* add debugging

* remove dnsserver from readme

* adds nvs erase

// #define WM_ERASE_NVS // esp32 erase() will erase NVS

* oops

* adds opt erase flag

* fix savecallback tzapu#543

* fixup tzapu#548

* fix constructor

* move routes to strings

* oops fix constructor again

* remove preallocation of params memory

* init params as null

I started gettting odd exceptions, so I thought this should be null and not on the stack or pointing to garbage. I might be totally in the wrong here.

* fix customhtml parameters

* remove debug

* fixes tzapu#551

* disable ssid input autoformatting

autocorrect='off' autocapitalize='none'

* remove serial.prints

* fix up connection result for ondemand portal

* fix autoreconnect on auth failure

* notes

* fixes tzapu#555 oops

* added debug levels

* add esp shields

* Update README.md

* add WM_RTC def for rtc.h

* Added Custom DNS, fix newlines

* fix tabs

* comments

* oops

* remove testing

* minor layout fix to config

* add setShowDnsFields, adds edge case force hide ip fields

* adds section hrs

* showinfoerase toggle

* kludge setmenu with size so it works

Prboably going to add a vector for this, I do not want to add the overhead of std::array for something optional

* debug remove

* menuids as vector to deal with size

This kind of makes it a pain in the ass for users, not sure how to make this easier, I can take in an array of string ids, with a count arg, makes it easier, but then users can pass nonsense in, this way its enum ids, but damn it sure is convoluted. Welcome to ideas here...

```c++
  std::vector<WiFiManager::menu_page_t> menu = {wm.MENU_WIFI,wm.MENU_INFO,wm.MENU_PARAM,wm.MENU_CLOSE,wm.MENU_SEP,wm.MENU_ERASE,wm.MENU_EXIT};
  wm.setMenu(menu);
```

* adds handleClose

* add bug workaround for esp8266 softap

* oops

* fix debug blank

* travis testing

* change setmenu to take vector or array of strnig tokens

* travis testing

* change varnames

* fixing travis

* datatype fixes

* fix section compile error

* fix compiler warnings

* add esp32

* add esp32

* move menutokens

* add esp32

* add esp32

* fix debug levels

* ugh

* add esp32

* add esp32

* add esp32

* add esp32

* add esp32

* make travis build again

* Delete OnDemandConfigPortal.ino.cpp

Sigh

* fix fsparam spiffs examples for esp32

* spiffs case

* refactor connectwifi, adds save timeout

wifi save now no longer uses settimeout timeout

* fixes tzapu#573

* ugh remove test example

* fix parenths tzapu#573

* add setEnableConfigPortal(boolean enable) - if false dont open condig portal from autoConnect()

* getmodestr, handleerase(bool)

* fix handleerase add softapconfig catch fail

* fix nvs erase

* fix erroneous error debug

* adds chip revision efuse

not sure what use this is, as getChipRevision is usually the same anyway... shrug

* clean up defines, removed stuff for memory

* workaround for esp32 webserver parsearguments bug

* fixup scnanetworks

* fix some error logging

* fixes tzapu#581

adds htmlentities to ssid outputs, limited replacements for now

* comment

* fix savetimeout, too short, made optional

* fix menu output

removed test menu output, removed ref , not sure why I put that there....

* comments, debugging

* fixing up setmenu docblocks
@tablatronix tablatronix reopened this Oct 12, 2018
@bitboy85
Copy link

I would also like to have this feature. Makes it more easy to open webserver by name instead of ip address. As far as i know hostname is only in station mode supported and if i remember correctly there were some issues with hostname and the esp8266 arduino library.
Can you please check with an updated one?

@tablatronix
Copy link
Collaborator

This feature already exists.. Did you read this?

@bitboy85
Copy link

bitboy85 commented Jun 22, 2019

What i had in mind is if using autoconfiguration that you can set a hostname in the "Configure Wifi" menu. Which is also saved in flash and restored during power up.
Currently its only working if hardcoded or did i miss something?

@tablatronix
Copy link
Collaborator

tablatronix commented Jun 22, 2019

yes you are correct, anything that uses flash or spiffs to store stuff has to be written by users on their own using params, wifimanager does not write to flash memory on its own by design

@markg85
Copy link

markg85 commented Jul 8, 2019

I too ended up here after having hacked this very feature in my local WiFiManager along with mDSN support.

Just to figure out that the feature is there all along, just in the development branch... Which you obviously don't get when using PlatformIO..

Could you consider making a new release, please? These two features alone would already be welcome enough for a release.

@tablatronix
Copy link
Collaborator

tablatronix commented Jul 8, 2019

I will accept PR for examples on development if anyone want to write them though.

I hope to release it (beta) soon, sorry about that you can use it on platformio, you can install anything on platformio using git urls

@markg85
Copy link

markg85 commented Jul 8, 2019

I will accept PR for examples on development if anyone want to write them though.

I hope to release it (beta) soon, sorry about that you can use it on platformio, you can install anything on platformio using git urls

Yes, that will work. But then i lose the update feature... This is only a good solution as long as you haven't made a release. As soon as you do, it requires me (and all who used git clone) to modify it again.

@tablatronix
Copy link
Collaborator

Can you not override libraries in platformio.ini? I have not tried yet

@tablatronix
Copy link
Collaborator

Yeah you just add lib deps and use the custom branch
https://docs.platformio.org/en/latest/librarymanager/quickstart.html#project-dependencies

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion Further Discussion ongoing enhancement Feature Request QA Quality Assurance testing needed
Projects
None yet
Development

No branches or pull requests

4 participants