Reputation: 21
I am pretty naive to this topic, so please excuse any dumb reply from my side. I want to connect my raspberry pi 3 to my android phone through Wifi Direct(or P2P), while maintaining its normal wifi connection. Whenever i run wpa_cli command, it disconnects from the normal wifi connection, while P2P commands work fine. I know for the fact that this is possible as all recent android have this feature. I tried searching the internet a lot for this, but no one seems to discuss this. My wpa_supplicant.conf is -
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
device_name=RPi_3
device_type=1-0050F204-1
country=GB
network={
ssid="Sarthak"
psk="sam.s.home_9h"
key_mgmt=WPA-PSK
}
After a cold start, i generally start using wpa_cli without any prior wpa_supplicant command, so maybe thats problem. You might have already judged how little knowledge i have, so please explain it in simple terms why this happening.
Upvotes: 1
Views: 2660
Reputation: 135
I think it depends on how you use wpa_cli to setup a connection. You did not mention the issued commands, but I presume you are using the following:
wpa_cli -i wlan0 list_networks # list all configured networks; in you example, you appeared to have just defined network n. 0
wpa_cli -i wlan0 select_network 0
The select_network 0
command is not using P2P and it just connects the Raspberry Pi to the Access Point defined in the network profile 0.
Alternatively, you might have created a second network using for instance the following commands:
wpa_cli -i wlan0 add_network # this returns the new network profile number; let us consider that 1 is returned
wpa_cli -i wlan0 set_network 1 ssid \"MYSSID\"
wpa_cli -i wlan0 set_network 1 psk \"passphrase\"
wpa_cli -i wlan0 enable_network 1 # alternatively to these commands, you might have added a new network profile by editing wpa_supplicant.conf
wpa_cli -i wlan0 list_networks # in this example, we added network 1
wpa_cli -i wlan0 save_config # optional command to save the newly defined network profile 1 into wpa_supplicant.conf
wpa_cli -i wlan0 select_network 1 # this leaves network 0 and connects to network 1
These commands are again not using P2P and just switch the connection of the Raspberry Pi from the Access Point defined in network profile 0 to the other AP defined in profile 1.
Wi-Fi Direct uses different wpa_cli commands and allows compliant devices to form ad-hoc communication groups without interrupting conventional access point-based Wi-Fi communication.
You should change device_name=RPi_3
to device_name=DIRECT-RPi_3
.
You can then use wpa_cli -i p2p-dev-wlan0 p2p_connect <addr> <8-digit password> display
to negotiate the group with the Android device. Alternatively, you can define an autonomous group, or a persistent group.
Example of group negotiation mode:
wpa_cli -i p2p-dev-wlan0
set config_methods keypad
p2p_find
p2p_connect <addr> <8-digit password> display
Example of persistent group mode (assuming that p2p_group_add creates group p2p-wlan0-0):
wpa_cli -i p2p-dev-wlan0
set config_methods keypad
set_network 0 mode 3
set_network 0 disabled 2
p2p_group_add persistent=0
interface p2p-wlan0-0
With the Wi-Fi Direct interface of the Android device, select DIRECT-RPi_3. Insert PIN 00000000 through the keypad panel of the Android smartphone to enroll.
interface p2p-wlan0-0
wps_pin any 00000000
Check Connect Android smartphone with Wi-Fi Direct to a Raspberry Pi for further information.
Upvotes: 1
Reputation: 199
This happens because Wi-Fi Direct means that your phone is creating a separate Wi-Fi network (see Wi-Fi Direct on Wikipedia) when opening a Wi-Fi Direct connection, which is different from the Wi-Fi network you are already connected to (normally created by you router). However, the Wi-Fi interface on the Raspberry Pi can only connect to one network at a time.
So when you are connecting to you phone via Wi-Fi Direct, the Raspberry Pi first leaves the network created by the router to connect to the Wi-Fi network created by the phone.
If you want to connect to different Wi-Fi networks at the same time, you can add another Wi-Fi interface to the Raspberry Pi, for example, using a Wi-Fi USB stick. With two interfaces, you could connect to the two different networks without switching the connection to one of the networks off.
Upvotes: 0