Configure WIFI client via sketch

I’ve tried to do this using the bridge console by hand (just as a POC) and cannot seem to figure it out.

Here is what I try:
/sbin/uci set wireless.@wifi-iface[0].mode=sta
/sbin/uci set wireless.@wifi-iface[0].ssid=
/sbin/uci set wireless.@wifi-iface[0].encryption=psk2
/sbin/uci set wireless.@wifi-iface[0].key=
/sbin/uci commit wireless

But I get error message:
“command failed: Device or resource busy (-16)”
when I run the wifi command.

Any thoughts? Anyone have a script for this? It seemed like the wifi shield has libraries for this.

Configuring it manually though the wifi http config utility works fine.

Thank you,