0
0
Raspberry Piprogramming~20 mins

Headless deployment setup in Raspberry Pi - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Headless Deployment Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Raspberry Pi headless Wi-Fi setup script?
Consider this script snippet that configures Wi-Fi on a Raspberry Pi without a monitor. What will be the output after running it?
Raspberry Pi
import os
ssid = "HomeNetwork"
password = "mypassword"
wpa_supplicant_conf = f"""
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US

network={{
    ssid=\"{ssid}\"
    psk=\"{password}\"
    key_mgmt=WPA-PSK
}}
"""

with open("/etc/wpa_supplicant/wpa_supplicant.conf", "w") as f:
    f.write(wpa_supplicant_conf)

print("Wi-Fi configuration file created.")
AWi-Fi configuration file created.
BPermission denied error
CFile not found error
DSyntax error in configuration file
Attempts:
2 left
💡 Hint
Think about file writing permissions on Raspberry Pi OS.
🧠 Conceptual
intermediate
1:30remaining
Which file enables SSH access on a Raspberry Pi in headless mode?
When preparing a Raspberry Pi SD card for headless setup, which file must be created or modified to enable SSH access on boot?
Awpa_supplicant.conf
Bssh (empty file in boot partition)
Ccmdline.txt
Dconfig.txt
Attempts:
2 left
💡 Hint
This file is placed in the boot partition and has no extension.
🔧 Debug
advanced
2:30remaining
Why does this headless Wi-Fi setup script fail to connect?
This Python script writes a wpa_supplicant.conf file but the Raspberry Pi does not connect to Wi-Fi. Identify the bug.
Raspberry Pi
ssid = "MyWiFi"
password = "pass1234"
wpa_conf = f"""
network={{
ssid="{ssid}"
psk="{password}"
key_mgmt=WPA-PSK
}}
"""
with open("/etc/wpa_supplicant/wpa_supplicant.conf", "w") as f:
    f.write(wpa_conf)
print("Config written")
Assid and psk lines lack indentation
BDouble quotes inside f-string cause syntax error
CMissing country code line in config
DFile path is incorrect
Attempts:
2 left
💡 Hint
Check the indentation inside the network block.
📝 Syntax
advanced
1:30remaining
What error does this Raspberry Pi headless setup script produce?
What error will this Python code produce when run on Raspberry Pi to create wpa_supplicant.conf?
Raspberry Pi
with open('/etc/wpa_supplicant/wpa_supplicant.conf', 'w') as f
    f.write('network={ssid="MyWiFi" psk="pass1234"}')
AIndentationError: expected an indented block
BFileNotFoundError: no such file or directory
CPermissionError: [Errno 13] Permission denied
DSyntaxError: expected ':' after 'with' statement
Attempts:
2 left
💡 Hint
Check the syntax of the with statement.
🚀 Application
expert
2:00remaining
How many lines will the Raspberry Pi read from wpa_supplicant.conf after this script runs?
This script writes a wpa_supplicant.conf file for headless Wi-Fi setup. How many lines will the file contain?
Raspberry Pi
conf = '''ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=GB

network={
    ssid="OfficeWiFi"
    psk="securepass"
    key_mgmt=WPA-PSK
}
'''
with open('/etc/wpa_supplicant/wpa_supplicant.conf', 'w') as file:
    file.write(conf)
A8
B10
C9
D7
Attempts:
2 left
💡 Hint
Count all lines including blank lines in the triple-quoted string.