home-assistant / operating-system

:beginner: Home Assistant Operating System
Apache License 2.0
4.93k stars 971 forks source link

Allow setting WiFi regulatory domain #1530

Open agners opened 3 years ago

agners commented 3 years ago
$ ha os info
board: rpi4
boot: A
update_available: false
version: "6.2"
version_latest: "6.2"
$ ha network scan wlan0 | grep -i frequency
- frequency: 2437
- frequency: 2437
- frequency: 2412
- frequency: 2412
- frequency: 2412
- frequency: 2462
- frequency: 2462

I have a Unifi AP right beside it broadcasting on channel 153 / VHT80.

Originally posted by @deviantintegral in https://github.com/home-assistant/operating-system/issues/1441#issuecomment-912669650

agners commented 3 years ago

Hm, using iw list shows that only some frequencies are enabled:

        Band 1:
...
                Frequencies:                                                                                                                                                                                                                                                                                                  
                        * 2412 MHz [1] (20.0 dBm)                                                                                                                                                                                                                                                                             
                        * 2417 MHz [2] (20.0 dBm)                                                                                                                                                                                                                                                                             
                        * 2422 MHz [3] (20.0 dBm)                                                                                                                                                                                                                                                                             
                        * 2427 MHz [4] (20.0 dBm)                                                                                                                                                                                                                                                                             
                        * 2432 MHz [5] (20.0 dBm)                                                                                                                                                                                                                                                                             
                        * 2437 MHz [6] (20.0 dBm)                                                                                                                                                                                                                                                                             
                        * 2442 MHz [7] (20.0 dBm)                                                                                                                                                                                                                                                                             
                        * 2447 MHz [8] (20.0 dBm)                                                                                                                                                                                                                                                                             
                        * 2452 MHz [9] (20.0 dBm)                                                                                                                                                                                                                                                                             
                        * 2457 MHz [10] (20.0 dBm)                                                                                                                                                                                                                                                                            
                        * 2462 MHz [11] (20.0 dBm)                                                                                                                                                                                                                                                                            
                        * 2467 MHz [12] (20.0 dBm)                                                                                                                                                                                                                                                                            
                        * 2472 MHz [13] (20.0 dBm)                                                                                                                                                                                                                                                                            
                        * 2484 MHz [14] (disabled)
        Band 2:
....
                Frequencies:
                        * 5170 MHz [34] (disabled)
                        * 5180 MHz [36] (20.0 dBm)
                        * 5190 MHz [38] (disabled)
                        * 5200 MHz [40] (20.0 dBm)
                        * 5210 MHz [42] (disabled)
                        * 5220 MHz [44] (20.0 dBm)
                        * 5230 MHz [46] (disabled)
                        * 5240 MHz [48] (20.0 dBm)
                        * 5260 MHz [52] (20.0 dBm) (no IR, radar detection)
                        * 5280 MHz [56] (20.0 dBm) (no IR, radar detection)
                        * 5300 MHz [60] (20.0 dBm) (no IR, radar detection)
                        * 5320 MHz [64] (20.0 dBm) (no IR, radar detection)
                        * 5500 MHz [100] (20.0 dBm) (no IR, radar detection)
                        * 5520 MHz [104] (20.0 dBm) (no IR, radar detection)
                        * 5540 MHz [108] (20.0 dBm) (no IR, radar detection)
                        * 5560 MHz [112] (20.0 dBm) (no IR, radar detection)
                        * 5580 MHz [116] (20.0 dBm) (no IR, radar detection)
                        * 5600 MHz [120] (20.0 dBm) (no IR, radar detection)
                        * 5620 MHz [124] (20.0 dBm) (no IR, radar detection)
                        * 5640 MHz [128] (20.0 dBm) (no IR, radar detection)
                        * 5660 MHz [132] (20.0 dBm) (no IR, radar detection)
                        * 5680 MHz [136] (20.0 dBm) (no IR, radar detection)
                        * 5700 MHz [140] (20.0 dBm) (no IR, radar detection)
                        * 5720 MHz [144] (disabled)
                        * 5745 MHz [149] (disabled)
                        * 5765 MHz [153] (disabled)
                        * 5785 MHz [157] (disabled)
                        * 5805 MHz [161] (disabled)
                        * 5825 MHz [165] (disabled)

As you can see, channel 149 is disabled currently.

It seems this is because the regulatory domain is set to global by default:

/config # iw reg get
global
country 00: DFS-UNSET
        (2402 - 2472 @ 40), (N/A, 20), (N/A)
        (2457 - 2482 @ 20), (N/A, 20), (N/A), AUTO-BW, PASSIVE-SCAN
        (2474 - 2494 @ 20), (N/A, 20), (N/A), NO-OFDM, PASSIVE-SCAN
        (5170 - 5250 @ 80), (N/A, 20), (N/A), AUTO-BW, PASSIVE-SCAN
        (5250 - 5330 @ 80), (N/A, 20), (0 ms), DFS, AUTO-BW, PASSIVE-SCAN
        (5490 - 5730 @ 160), (N/A, 20), (0 ms), DFS, PASSIVE-SCAN
        (5735 - 5835 @ 80), (N/A, 20), (N/A), PASSIVE-SCAN
        (57240 - 63720 @ 2160), (N/A, 0), (N/A)

You can set the default regulatory domain used by the kernel by adding cfg80211.ieee80211_regdom=<COUNTRY_CODE> e.g. cfg80211.ieee80211_regdom=US to cmdline.txt (present in the first partition of your SD card, or in /mnt/boot/cmdline.txt through the OS shell).

Ideally we should set the regulatory domain through OS Agent using information the user entered during onboarding.

regevbr commented 3 years ago

@agners I just tried your workaround and sadly it doesn't work...

# cat /mnt/boot/cmdline.txt 
dwc_otg.lpm_enable=0 console=tty1
cfg80211.ieee80211_regdom=US

Did I do something wrong here? I logged in vi 22222 changed the file and did a reboot on the host.... image

regevbr commented 3 years ago

After some investigation, it seems that you need to have it as a one liner to make it work:

# cat /mnt/boot/cmdline.txt 
dwc_otg.lpm_enable=0 console=tty1 cfg80211.ieee80211_regdom=US
Vlad-Star commented 3 years ago

After some investigation, it seems that you need to have it as a one liner to make it work:

# cat /mnt/boot/cmdline.txt 
dwc_otg.lpm_enable=0 console=tty1 cfg80211.ieee80211_regdom=US

Correct, these are the options supplied to Linux kernel at boot, must be one-liner.

deviantintegral commented 2 years ago

This would still be a nice addition to the OS. If it's unlikely to be implemented, would a docs update be OK instead?

Once set, I had to re-join the Wifi network. Otherwise, it still preferred the 2.4GHz band.

TonsiTT commented 1 year ago

Coming from issue #2755, whenever I create the file /mnt/boot/cmdline.txt and set the option, the cmdline file gets deleted on reboot. Any idea how to fix this?

agners commented 1 year ago

How do you create that file?

Note you can't use the SSH and Web Terminal add-on as this runs in a container. The file is on the host system.

Probably the easiest is to shutdown your Home Assistant installation and edit the file on the first partition from a differenc Computer.

tyeth commented 5 months ago

Bumping this issue, as a new user to Home-Assistant (RPi) I felt it was unreasonable that I couldn't configure wifi from the CLI (I don't have a spare usb stick and didn't spot that technique in Getting Started guide), and even then my network is on a UK specific band which I'd like to obviously use as part of setting up network connectivity.

Some access points don't allow manually defining the channel/band as they auto-optimise to the least noisy channel, or like mine the ISP resets the settings to auto-optimise with every update they silently push.

Editing cmdline.txt is fine for me, I have other linux devices, but I wouldn't expect a normal user to accomplish this.