Arduino icon indicating copy to clipboard operation
Arduino copied to clipboard

Add callback to allow Static IP per SSID in WiFiMulti

Open Sojourneer opened this issue 11 months ago • 7 comments

Callback before WiFi.begin allows user to configure selected SSID.

Sojourneer avatar Feb 25 '25 16:02 Sojourneer

Wouldn't extending 'add' method arguments be more a appropriate solution? Internally, only ssid & pass are stored. No reason not to keep 'IPAddress'es for static config as well

mcspr avatar Feb 27 '25 15:02 mcspr

Wouldn't extending 'add' method arguments be more a appropriate solution? Internally, only ssid & pass are stored. No reason not to keep 'IPAddress'es for static config as well

That is the more obvious solution. But it has a higher impact on existing API and is less flexible. This solution adds two lines to the code (and two lines of declaration), and zero impact on existing API.

Sojourneer avatar Feb 28 '25 01:02 Sojourneer

Meaning, there are other use-cases besides config() call?

fwiw, default arguments passed at the end of the method can be omitted and .add() call stays the same. IPAddress has default constructor, ::isSet() would notify whether IPAddress was set by the user or not.

mcspr avatar Feb 28 '25 13:02 mcspr

Meaning, there are other use-cases besides config() call?

In my use-case, I am setting the config parameters based on the MAC address (because of various router issues). Yes, that could be done upfront rather than when the SSID is decided. But it seems cleaner, as well as more efficient, to have the config calculated when needed rather than preemptively. I have a library that takes a JSON config (IP, as well as optionally MQTT etc.) and applies it in the callback to call config per the found SSID. Again, decoupling that from the code for the physical connection is beneficial.

Sojourneer avatar Mar 01 '25 10:03 Sojourneer

Ok, agreed

Style suggestion then - use onSsidSelected(...) as one word without underscores. This is also the style used for other event-related things in the WiFi class. Can you also update the example .ino (sketch) and documentation, or do you want me to do it?

mcspr avatar Mar 01 '25 18:03 mcspr

Ok, I'll do it, and change the name as you recommend. Do I need to redo the pull (I'm a noobie at this process)?

Sojourneer avatar Mar 01 '25 23:03 Sojourneer

Just push more commits to Sojourneer:master

mcspr avatar Mar 02 '25 14:03 mcspr