Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Idea: Use Raspberry Pi Imager to configure WLAN country, time zone & keyboard layout
#1
Hi,

When you install Moode following the official Setup Guide, Raspberry Pi Imager settings are used to activate SSH and provide a user id, password and (optionally) host name.

The Raspberry Pi Imager additionally knows settings to configure the WLAN country, time zone and keyboard layout. These settings are, however, currently ignored by Moode (version 8.3.7). Of course you can provide the respective information later when Moode is running via Configure -> Network (WLAN country) and Configure -> System (time zone & keyboard layout).

Idea: Would it be possible (i.e. without too much effort) to enhance the installation process so that it (optionally) uses the Rapberry Pi Imager settings to configure WLAN country, time zone and keyboard layout?  

Thanks & best regards
Jens
Reply
#2
I'll add to the TODO list for upcoming 8.3.8
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#3
There is already some code in worker.php for timezone and kbd layout but perhaps it's not working correctly.

// Pi Imager: Import time zone and keyboard layout
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#4
Hmm, you are right. The code was introduced in May 2023 and actually works correctly for time zone and keyboard layout (just retested in version 8.3.7).  I must have picked an older image version in my previous test or maybe forgot to set the right check mark in the Imager. Sorry for posting wrong information and asking for something which was already implemented ...

The same commit also added code to set the WLAN country (some lines later). That part, however, is indeed not working for me. When I set the WLAN country to "DE" in the Pi Imager, I still get "US" in Moode.

Code:
pi@moode:~ $ moodeutl -q "select wlan_country from cfg_network"

US

whereas the file firstrun.sh which the Pi Imager created correctly contains "DE" as the WLAN country:

Code:
if [ -f /usr/lib/raspberrypi-sys-mods/imager_custom ]; then
  /usr/lib/raspberrypi-sys-mods/imager_custom set_wlan '<ssid>' '<psk>' 'DE'
else
cat >/etc/wpa_supplicant/wpa_supplicant.conf <<'WPAEOF'
country=DE

Regards
Jens
Reply
#5
I can repro @jenzd's result.

I told the Pi Imager I wanted WiFi country "DE" and locale settings "Europe/Berlin" and "de". Burnt the uSD card and booted.

In addition to the WiFi country still being set to "US" in wpa_supplicant.conf I notice the locale variables all still have US-based values. I don't know if this matter if the install is used strictly as a moOde player.


Code:
pi@moode837:~ $ timedatectl show
Timezone=Europe/Berlin
LocalRTC=no
CanNTP=yes
NTP=yes
NTPSynchronized=yes
TimeUSec=Wed 2024-01-03 04:04:47 CET
pi@moode837:~ $ more /etc/default/keyboard
# KEYBOARD CONFIGURATION FILE

# Consult the keyboard(5) manual page.

XKBMODEL="pc105"
XKBLAYOUT="de"
XKBVARIANT=""
XKBOPTIONS=""

BACKSPACE="guess"
pi@moode837:~ $ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
pi@moode837:~ $ sudo more /etc/wpa_supplicant/wpa_supplicant.conf
#########################################
# This file is automatically generated by
# the player Network configuration page.
#########################################

country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
ssid="Krypton"
priority=100
scan_ssid=1
psk=…
}


Regards,
Kent
Reply
#6
What happens if u make same Imager settings and just burn a Bookworm image?

I'll investigate the wifi country code bug.
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#7
I verified the code in worker.php that extracts the country code from pi-imager generated wpa_supplicant.conf file and then updates cfg_network table works correctly.

What doesn't seem right is the wpa_supplicant.conf file generated by the Pi Imager. It has country = US even though /boot/firstrun.sh shows country = GB which I specified in the imager.

Here's my test

1. Prep image using Pi-Imager 1.8.4
2. Set WiFi country to something other than US
3. Write the image
4. Insert USB-uSD dongle into a moOde Pi

# Save firstrun.sh file and examine it, verify country code
5. sudo cp /media/boot/firstrun.sh ./

# Add debug line to worker.php
6. sudo nano /media/rootfs/var/www/daemon/worker.php and add the bolded line 

// Pi Imager: Import SSID/PSK/Country
if (file_exists('/etc/wpa_supplicant/wpa_supplicant.conf')) {
    $moodeHeader = sysCmd('cat /etc/wpa_supplicant/wpa_supplicant.conf 2>&1 | grep "This file is automatically generated"');
    sysCmd('cp /etc/wpa_supplicant/wpa_supplicant.conf /home/pi/');

7. Boot a Pi with the modified uSD card
8. SSH

# Examine country code
9. sudo cat ./wpa_supplicant.conf
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#8
(01-03-2024, 04:03 PM)Tim Curtis Wrote: I verified the code in worker.php that extracts the country code from pi-imager generated wpa_supplicant and then updates cfg_network table works correctly.

What doesn't seem right is the wpa_supplicant file generated by the Pi Imager. It has country = US even though /boot/firstrun.sh shows country = GB which I specified in the imager.

Here's my test

1. Prep image using Pi-Imager 1.8.4
2. Set WiFi country to something other than US
3. Write the image
4. Insert USB-uSD dongle into a moOde Pi

# Save firstrun.sh file and examine it, verify country code
5. sudo cp /media/boot/firstrun.sh ./

# Add debug line to worker.php
6. sudo nano /media/rootfs/var/www/daemon/worker.php and add the bolded line 

// Pi Imager: Import SSID/PSK/Country
if (file_exists('/etc/wpa_supplicant/wpa_supplicant.conf')) {
    $moodeHeader = sysCmd('cat /etc/wpa_supplicant/wpa_supplicant.conf 2>&1 | grep "This file is automatically generated"');
    sysCmd('cp /etc/wpa_supplicant/wpa_supplicant.conf /home/pi/');

7. Boot a Pi with the modified uSD card
8. SSH

# Examine country code
9. sudo cat ./wpa_supplicant.conf

It gets weirder---at least to me.

With vanilla (e.g., no moOde) Bullseye 64-bit Lite flashed with Imager options set for Germany, wpa_supplicant.conf ends up with no country code line at all.

Similarly with vanilla Bookworm 64-bit Lite, where the connection info is stored in /etc/NetworkManager/system-connections, I find no country code associated with the WiFi subsystem.

I suppose in managed (aka infrastructure) mode this perhaps doesn't matter because it's the detectable APs which dictate which frequencies are acceptable for connection. Still, I don't understand the inner workings well enough to make any definitive statement.

And in neither case is the locale properly set. In the bookworm test I'm running ATM I get (because RaspiOS comes configured for the UK)
Code:
pi@bookworm-test:~ $ locale
LANG=en_GB.UTF-8
LANGUAGE=
LC_CTYPE="en_GB.UTF-8"
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_PAPER="en_GB.UTF-8"
LC_NAME="en_GB.UTF-8"
LC_ADDRESS="en_GB.UTF-8"
LC_TELEPHONE="en_GB.UTF-8"
LC_MEASUREMENT="en_GB.UTF-8"
LC_IDENTIFICATION="en_GB.UTF-8"
LC_ALL=

yet the time zone is Europe/Berlin and the default keyboard settings include XKBLAYOUT="de" due to  firstrun.sh.

Regards,
Kent

PS - For what it's worth, I'm running Imager v1.8.4 on a Linux laptop.
Reply
#9
Scary :-0

When I walked the code in firstrun.sh to see what was happening I looked at this path

firstrun.sh
 /usr/lib/raspberrypi-sys-mods/imager_custom set_wlan <ssid> <psk> <country>
   set_wlan()
     set_wlan_country ()
       raspi-config nonint do_wifi_country "$COUNTRY"

Maybe the desired wifi country code in firstrun.sh is getting overridden with "US" which is what is set when the moOde image is built. Prolly in the raspi-config part...
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#10
Also played around with a vanilla bullseye 64-bit lite image. I get the same result as @TheOldPresbyope, no country code in /etc/wpa_supplicant/wpa_supplicant.conf. Yet the country code is set correctly in /etc/default/crda

Code:
# Set REGDOMAIN to a ISO/IEC 3166-1 alpha2 country code so that iw(8) may set
# the initial regulatory domain setting for IEEE 802.11 devices which operate
# on this system.
#
# Governments assert the right to regulate usage of radio spectrum within
# their respective territories so make sure you select a ISO/IEC 3166-1 alpha2
# country code suitable for your location or you may infringe on local
# legislature. See `/usr/share/zoneinfo/zone.tab' for a table of timezone
# descriptions containing ISO/IEC 3166-1 alpha2 country codes.

REGDOMAIN=DE

It also shows up correctly when running the command iw reg get

Code:
global
country DE: DFS-ETSI
       (2400 - 2483 @ 40), (N/A, 20), (N/A)
       (5150 - 5250 @ 80), (N/A, 23), (N/A), NO-OUTDOOR, AUTO-BW
       (5250 - 5350 @ 80), (N/A, 20), (0 ms), NO-OUTDOOR, DFS, AUTO-BW
       (5470 - 5725 @ 160), (N/A, 26), (0 ms), DFS
       (5725 - 5875 @ 80), (N/A, 13), (N/A)
       (5945 - 6425 @ 160), (N/A, 23), (N/A), NO-OUTDOOR, AUTO-BW
       (57000 - 66000 @ 2160), (N/A, 40), (N/A)

phy#0
country 99: DFS-UNSET
       (2402 - 2482 @ 40), (6, 20), (N/A)
       (2474 - 2494 @ 20), (6, 20), (N/A)
       (5140 - 5360 @ 160), (6, 20), (N/A)
       (5460 - 5860 @ 160), (6, 20), (N/A)


So maybe /etc/default/crda is the correct location to look up the country?

The locale settings are not so important from my point of view. It's probably even best to stick to en_US.UTF-8 here to have consistent formats ...

Regards
Jens
Reply


Forum Jump: