I am able to connect successfully with the android device with the following wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=root


I started wpa_cli in interactive mode. Then adding a persistent group with p2p_group_add cmd as follows

p2p_group_add  persistent=0

enabling the pin by wps pin as follows

wps_pin any 12345670

with this I was able to connect a android device with Respberry pi automatically (with out giving pin in android device repeatedly).

But when I restart the pi and run the same command p2p_group_add persistent=0 not able to connect device with the preexisting persistent group.

  • What are these commands you are using? Do you use them with wpa_cli?
    – Ingo
    Sep 24, 2020 at 17:05
  • yes, i have used with wpa_cli, sorry i missed it.
    – arayan
    Sep 25, 2020 at 5:20

1 Answer 1



To summarize the issue, when restarting wpa_supplicant on the Raspberry Pi and reinvoking a previously defined persistent group, the P2P Clients (e.g., Android phones) are no more able to rejoin the saved group with fast reconnection and a new enrolling process is started instead, so that the saved group on the Android phones remains useless.

The problem occurs because, to improve security, the WLAN device driver of the Raspberry Pi 802.11 wireless interface uses randomized MAC addresses by default when starting network interfaces. Anyway, when using Wi-Fi Direct P2P persistent groups, MAC addresses shall not vary in order to avoid breaking the group restart.

A new version of wpa_supplicant now supports p2p_device_random_mac_addr=2, which allows correctly managing persistent groups on a Raspberry Pi, by reusing a previously saved MAC address.

How to compile, install and use this option is described here.

See also:

The following note shortly describes how to use a Wi-Fi Direct P2P persistent group.

A Wi-Fi Direct persistent group can be for instance created by manually editing the wpa_supplicant.conf configuration shown in the question, defining it as the first network profile (n. 0).

Add p2p_device_random_mac_addr=2 to wpa_supplicant configuration file.

Use the following commands to start the persistent group via wpa_cli:

wpa_cli -i p2p-dev-wlan0
set config_methods keypad

set config_methods keypad means that you want to enter a PIN with your smartphone and confirm it with your Rpi.

p2p_group_add persistent=0

interface lists the available interfaces; you need to find the one starting with p2p-wlan...

interface <group_name>

For instance, interface p2p-wlan0-0.

set config_methods keypad

Then, on the Android client:

Settings > Wi-Fi > Wi-Fi Direct; as soon as the SSID appears, select it and enter the PIN (say for instance 00000000, 8 digits).

Immediately after receiving the WPS-ENROLLEE-SEEN event, on that newly created interface issue the following:

wps_pin any 00000000

After some seconds, the device gets connected.


wpa_cli -i p2p-wlan0-0 wps_pin any 00000000

Notice the used interface name.

When the connection is activated, a new saved group appears on the Wi-Fi Direct Android panel, to allow fast reconnection. In fact, if you now disconnect the link on the Android phone and try to reconnect it, including Android reboot and Raspberry Pi reboot, the connection becomes immediately active without password request (i.e., reusing the same saved group).

  • Very helpful, thanks for posting this. Just for clarity, which version of Android was this for?
    – Jortstek
    Nov 7, 2021 at 21:16
  • 1
    Any Android version supporting Wi-Fi Direct works. I tested Android 11, 10, 9, 8, 7 and 6 smartphones. Wi-Fi Direct is present in most smartphones with at least Android 4.0 (API level 14); notice anyway that only recent Android versions support the local saving of persistent groups. With some Android 6 and 7 devices (depending on the ROM), enrolment is always needed when connecting a persistent group. Additional notes here.
    – ircama
    Nov 9, 2021 at 6:40
  • 1
    A persistent P2P-GO group can provide AP capabilities; also, Wi-Fi Direct does not interfere with the routing table, so you might have cellular and WiFi concurrently active with Android. The connection to a persistent group is not automatic with the Android phone: you need to click on the persistent group to connect to the Ubuntu GO. Anyway, a reconnection to the group is done without repeating the WPS authorization process.
    – ircama
    Nov 11, 2021 at 1:07
  • (Deleted my last comment cos I can't edit it and there was a glaring mistake which made it confusing. I meant I do want it to reconnect automatically.) @ircama Just to confirm, when you say you need to "click on the persistent group" in Android but "without repeating" the authorization process, that means click on it every time you lose and regain connectivity, i.e. every time the two devices come back in range of each other? I've seen this question asked elsewhere but never seen a clear answer. If it really does require constant Bluetooth-style pairing, that is going to be a deal-breaker.
    – Jortstek
    Nov 11, 2021 at 10:35
  • 1
    Once the P2P persistent group is formed, it is possible to connect to it both using WiFi Direct (which requires a confirmation when connecting through the Android user interface) and also in Infrastructure AP mode, which is the same way as for traditional infrastructure-mode Access Points. That said, It is not very clear to me your use case, whether you interface WiFi direct from the Android user interface or from an App and why you need to opt for WiFi Direct over infrastructure AP mode networking. I suggest you some simple tests, which will be much clearer to you than many comments.
    – ircama
    Nov 12, 2021 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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