I have an IMX8MP board running a Yocto Poky build image. It's running a small HTTP server in order for a user to input an SSID_NAME and a PASSPHRASE. Once the server receives those, I want to connect to the Wi-Fi that the user inputs. I tried creating the file in /var/lib/connman/wifi_XXXXX_YYYYY_managed_psk/settings. The content of the file is:
[wifi_XXXXX_YYYYY_managed_psk]
SSID=YYYYY
Name=SSID_NAME
Passphrase=PASSPHRASE
AutoConnect=true
However, I get an error when I try to connect by doing connmanctl connect wifi_XXXXX_YYYYY_managed_psk:
Error /net/connman/service/wifi_XXXXX_YYYYY_managed_psk: Not registered
The reason why I'm creating the file and then executing the connect command, is because the connmanctl connect wifi_XXXXX_YYYYY_managed_psk asks for a Passphrase, and I don't know how to pass it with a script.
This is the script I'm using to connect
#!/bin/sh
NAME=$1
PASSWORD=$2
mac=$(ifconfig wlan0 | grep ether | awk '{print $2}' | sed 's/://g')
connmanctl scan wifi
# Match the wifi network with the given NAME and mac address
ssid=$(connmanctl services | grep -E "^\s*$NAME\s+wifi_$mac" | grep -o 'wifi_[0-9a-fA-F]*_[0-9a-fA-F]*_managed_psk')
path=/var/lib/connman/$ssid
echo "Setting up configuration for wifi network $NAME, $mac, $ssid"
mkdir -p $path
configuration_file=$path/settings
touch $configuration_file
cat >$configuration_file <<_EOF
[$ssid]
SSID=$ssid
Name=$NAME
Passphrase=$PASSWORD
AutoConnect=true
_EOF
connmanctl config $ssid
connmanctl connect $ssid
exit 0
I also tried using connmanctl config wifi_XXXXX_YYYYY_managed_psk --passphrase PASSPHRASE instead of creating the file. Got the exact same error.