Connecting to Wi-Fi with adb

To connect your board to Wi-Fi, first access a shell prompt on the device. You can use either of the following methods:

  • Open a shell over adb with the adb shell command.

    For the Raspberry Pi, first connect your board to your Wi-Fi router or development computer to assign it an IP address. Run the adb connect <ip-address> command to connect to this IP address using the adb tool.

  • Connect to the serial console. Refer to the Get Started page for the particular board.

Once you can access a shell prompt, follow these steps:

  1. Send an intent to the Wi-Fi service that includes the SSID of your local network. Your board must support the network protocol and frequency band of the wireless network in order to establish a connection.

    $ am startservice \
        -n \
        -a WifiSetupService.Connect

    The following arguments are supported with this command:

    Argument Description
    -e ssid network_ssid Connect to the wireless network SSID specified by network_ssid. This argument is required.
    -e passphrase network_pass Optional argument to use the passcode specified by network_pass to connect to the network SSID. This argument is not necessary if your network doesn't require a passcode.
    -e passphrase64 encoded_pass Optional argument used in place of passphrase for passcodes with special characters (space, !, ", $, &, ', (, ), ;, <, >, `, or |). Use base64 encoding to specify the value for encoded_pass.
    --ez hidden true Optional argument to indicate that the SSID specified in this command is hidden. If omitted, this value defaults to false.
  2. Verify that the connection was successful through logcat:

    $ logcat -d | grep Wifi
    V WifiWatcher: Network state changed to CONNECTED
    V WifiWatcher: SSID changed: ...
    I WifiConfigurator: Successfully connected to ...
  3. Test that you can access a remote IP address:

    $ ping
    PING ( 56(84) bytes of data.
    64 bytes from icmp_seq=1 ttl=57 time=6.67 ms
    64 bytes from icmp_seq=2 ttl=57 time=55.5 ms
    64 bytes from icmp_seq=3 ttl=57 time=23.0 ms
    64 bytes from icmp_seq=4 ttl=57 time=245 ms
  4. Check that the date and time are set correctly on the device:

    $ date

If you want to clear all of the saved networks on the board:

$ am startservice \
    -n \
    -a WifiSetupService.Reset