1

I have been trying to add a wifi network with these commands inside a script:

adb shell wpa_cli -p /data/misc/wifi/sockets/ -i wlan0

# Get to wpa_cli prompt
adb shell wpa_cli -p /data/misc/wifi/sockets/ -i wlan0

# Add new WiFi network
adb shell add_network

adb shell set_network 0 auth_alg OPEN 
adb shell set_network 0 key_mgmt WPA-PSK 
adb shell set_network 0 ssid "Password" 
adb shell set_network 0 proto RSN
adb shell set_network 0 mode 0 
adb shell set_network 0 psk "Mynetwork name"

# Connect to it
adb shell select_network 0 
adb shell enable_network 0
adb shell reassociate 

# Check the status
adb shell status

but after the first command the terminal stays always in adb shell prompt and the other commands are not executed

1
  • 1
    Is ssid "Password" and psk "Mynetwork name" intentional, or should these parameters be reversed?
    – PassKit
    Commented Jun 3, 2016 at 5:26

1 Answer 1

1
WPACLI="adb shell wpa_cli -p /data/misc/wifi/sockets/ -i wlan0"

# Add new WiFi network
NETWORK=$($WPACLI add_network)

$WPACLI set_network $NETWORK auth_alg OPEN 
$WPACLI set_network $NETWORK key_mgmt WPA-PSK 
$WPACLI set_network $NETWORK ssid "Password" 
$WPACLI set_network $NETWORK proto RSN
$WPACLI set_network $NETWORK mode 0 
$WPACLI set_network $NETWORK psk "Mynetwork name"

# Connect to it
$WPACLI select_network $NETWORK
$WPACLI enable_network $NETWORK
$WPACLI reassociate 

# Check the status
$WPACLI status
2
  • 1
    Agree with the answer, but worth mentioning WHY: Each call to adb shell opens a new shell. It is not a way to interact with the same shell over and over again, and once you call adb shell wpa_cli -p /data/misc/wifi/sockets/ -i wlan0, without a command, wpa_cli will start in interactive mode and wait for your input. Specifying each command invokes wpa_cli in non interactive mode, thus returns to you directly.
    – MByD
    Commented Jun 1, 2015 at 5:54
  • Don't know if Is ssid "Password" and psk "Mynetwork name" is intentional or is an oversight from the original poster.
    – PassKit
    Commented Jun 3, 2016 at 5:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.