openhabian icon indicating copy to clipboard operation
openhabian copied to clipboard

Illogical WiFi configuration in openhabian-config

Open Nadahar opened this issue 2 years ago • 2 comments

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:

  • Isolating enabling/disabling of the onboard WiFi adapter from the WiFi configuration. I would imagine that making the "second option" under 37 "dynamic" would be the most elegant and logical option - so that it would check the state before populating the menu, and then display either Enable onboard WiFi or Disable onboard WiFi accordingly. Devices without onboard WiFi shouldn't have this option at all.
  • Establish a way to "deconfigure" the SSID and PSK. I imagine that an extra option under WiFi setup would suffice - that instead of entering a SSID there would be a way to chose "clear configuration" or similar. This option should make /etc/wpa_supplicant/wpa_supplicant.conf be in a "default" state with no SSID/PSK configured.

System information:

OpenHABian 1.7.3 on a Raspberry Pi 4.

Nadahar avatar Jun 19 '22 17:06 Nadahar

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.

Nadahar avatar Jun 19 '22 17:06 Nadahar

@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 avatar Feb 14 '23 12:02 mstormi

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.

mstormi avatar May 12 '24 19:05 mstormi

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

Nadahar avatar May 12 '24 19:05 Nadahar

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.

mstormi avatar May 12 '24 19:05 mstormi

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.

Nadahar avatar May 12 '24 19:05 Nadahar