openhab / openhabian

openHABian - empowering the smart home, for Raspberry Pi and Debian systems
https://community.openhab.org/t/13379
ISC License
818 stars 251 forks source link

Illogical WiFi configuration in openhabian-config #1693

Closed Nadahar closed 1 month ago

Nadahar commented 2 years ago

Issue information:

Something is "off" with the logic regarding the WiFi configuration. The Disable WiFi option will run: https://github.com/openhab/openhabian/blob/5a5110ef01fadbfa2cd252c8b1f13e70cf9fe9e6/functions/wifi.bash#L105-L115 ...which will call enable_disable_wifi() here: https://github.com/openhab/openhabian/blob/5a5110ef01fadbfa2cd252c8b1f13e70cf9fe9e6/functions/helpers.bash#L114-L132

This will (physically) disabled the onboard WiFi adapter in the Raspberry Pi as far as I can understand. I assume it will do nothing to WiFi dongles..? If so, it should probably be named a little differently, to make sure it is clear that this is about the onboard WiFi.

After rebooting, as instructed to, wlan0 is gone and all is well in that sense. But, the WiFi configuration in /etc/wpa_supplicant/wpa_supplicant.conf is left untouched, still containing the SSID and PSK from the previous configuration if it was previously configured. I would assume this means that WiFi dongles would continue to work even after a reboot.

Now comes the problem. If you enter openhabian-config again, the System Settings under 37 are still the same. You can choose between WiFi setup and Disable WiFi, although both these options will fail. It's not possible to disable the (onboard) WiFi adapter, since it already is disabled. The option won't complain, it will actually falsely assert that WiFi is still enabled:

                    ┌────────────────────────┤ WiFi is currently enabled ├─────────────────────────┐
                    │                                                                              │
                    │ WiFi is currently enabled on your box.                                       │
                    │                                                                              │
                    │ ATTENTION:                                                                   │
                    │ Would you like to disable WiFi and use Ethernet?                             │
                    │                                                                              │
                    │                     <Yes>                        <No>                        │
                    │                                                                              │
                    └──────────────────────────────────────────────────────────────────────────────┘

...it will then continue to pretend to do something and ask you to reboot.

The other option WiFi setup is more troubling though, as it will present you with this error:

                    ┌──────────────────────────────────────────────────────────────────────────────┐
                    │                                                                              │
                    │ There was an error or interruption during the execution of:                  │
                    │   "30 | System Settings"                                                     │
                    │                                                                              │
                    │ Please try again. If the error persists, please read                         │
                    │ /opt/openhabian/docs/openhabian-DEBUG.md or                                  │
                    │ https://github.com/openhab/openhabian/blob/main/docs/openhabian-DEBUG.md how │
                    │ to proceed.                                                                  │
                    │                                                                              │
                    │                                                                              │
                    │                                    <Ok>                                      │
                    │                                                                              │
                    └──────────────────────────────────────────────────────────────────────────────┘

...which doesn't actually tell you anything about "what is going on". A further look at the script will reveal what really happens: https://github.com/openhab/openhabian/blob/5a5110ef01fadbfa2cd252c8b1f13e70cf9fe9e6/functions/wifi.bash#L35-L104

This is where the "lacking" logic all comes together to make everything very confusing. The "WiFi setup" actually starts by enabling the (onboard) WiFi adapter. But it doesn't stop and ask for a reboot if the adapter really is disabled in /boot/config.txt. Thus, the next steps will fail, specifically this part: https://github.com/openhab/openhabian/blob/5a5110ef01fadbfa2cd252c8b1f13e70cf9fe9e6/functions/wifi.bash#L58-L70

What has actually happened is that the (onboard) WiFi adapter has been enabled, and if you reboot and then enter openhabian-config and run WiFi setup again it will actually work. But, the way to get there is highly illogical and confusing.

Suggested fix

I really don't know bash scripting, so I would probably spend a lot of time trying to get something working put together. But, since your EULA/DCO is impossible for me to comply with, this would be futile to attempt anyway. I'm therefore going to try to explain what I think should be done instead.

I think making this logical would require:

System information:

OpenHABian 1.7.3 on a Raspberry Pi 4.

Nadahar commented 2 years ago

I forgot to mention that the reason this isn't a problem the first time you run Setup WiFi is that the onboard WiFi adapter is enabled "out of the box". The reason it isn't "active" if you do an installation without configuring SSID/PSK is simply the lack of configuration in /etc/wpa_supplicant/wpa_supplicant.conf. So, the WiFi adapter will be there, but it won't connect to any AP.

mstormi commented 1 year ago

@Nadahar if you could come up with a PR I would merge it but I don't have the time to cope with it

Just provide the code don't bother with signing etc I'll do.

mstormi commented 1 month ago

Given networking setup changed a lot in bookworm, I've removed the WiFi setup options from the menu for now.

Anyone feel free to contribute a PR to re-add them.

Nadahar commented 1 month ago

Does that mean that we must prevent openhabian from updating or things will break, or does it only concern new installations?

mstormi commented 1 month ago

I don't understand your question. I've only removed the options why would that break anything.

You will only get bookworm on fresh installs.

Nadahar commented 1 month ago

You will only get bookworm on fresh installs.

Ok, that's basically what I needed to know.

I don't understand your question. I've only removed the options why would that break anything.

I'm dealing with so many different systems, and it's been a long time since I did the openhabian setup now, so I simply don't remember how it works. What I do remember is that some things openhabian "leave alone", while other things get overwritten by scripts or something (like my SMB shares that keep breaking/getting their permissions removed). Since I don't have any overview of what is what, I just wanted to know if I needed to take special care to prevent Wi-Fi from breaking or not, without having to dive into all the details right now.