motash
motash

Reputation: 627

Why isn't the WIFI_P2P_CONNECTION_CHANGED_ACTION being detected by the broadcast receiver?

So this the first time I work with wifi-direct, I am trying to connect my android phone to a raspberry pi zero w over wifi-direct. using this sample app on my android phone: https://github.com/ahmontero/wifi-direct-demo

I am able to get to the Connected state at the pi in the wpa_cli interface and on the phone under the device name i see "connected" behind the progressDialog box that says "Connecting to 1e:67:58:4c:78:92" which should be dismissed after connecting but it isn't since WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION isn't being triggered after connecting.

my wpa_supplicant.conf:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1
country=LB
ap_scan=1
device_name=raspberry
device_type=1-0050F204-1
driver_param=use_p2p_group_interface=1
p2p_go_intent=7
p2p_go_ht40=1
p2p_listen_reg_class=81
p2p_listen_channel=1
p2p_oper_reg_class=81
p2p_oper_channel=1

and have done the following:

on the Pi:

$sudo wpa_supplicant -B -dd -iwlan0 -Dnl80211 -c /etc/wpa_supplicant/wpa_supplicant.conf

$sudo wpa_cli p2p-dev-wlan0

p2p_group_add
OK
<3>P2P-GROUP-STARTED p2p-wlan0-0 GO ssid="DIRECT-VC" freq=2412 passphrase="JrLfUAJf" go_dev_addr=5a:d3:65:e8:fc:e7
wps_pbc
OK
<3>P2P-DEVICE-FOUND 1e:67:58:4c:78:92 p2p_dev_addr=1e:67:58:4c:78:92 pri_dev_type=10-0050F204-5 name='HUAWEI' config_methods=0x188 dev_capab=0x25 group_capab=0x0 wfd_dev_info=0x00101c440032 new=1
<3>P2P-PROV-DISC-PBC-REQ 1e:67:58:4c:78:92 p2p_dev_addr=1e:67:58:4c:78:92 pri_dev_type=10-0050F204-5 name='HUAWEI' config_methods=0x188 dev_capab=0x25 group_capab=0x0

On the Phone: I run the wifi direct sample app from google and i can see the device with its info and when i click on connect i get stuck at connecting progressDialog and cant get passed that point to connected mode eventhough i see "connected" under device name.

the app seems to work fine between two phones but with a pi this line in WiFiDirectBroadcastReceiver.java doesn't get executed when a connection has been made with the pi

} else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action))

however, when connection is lost after a timeout for example it gets triggered!

my question is what am i doing wrong here, why isn't the WIFI_P2P_CONNECTION_CHANGED_ACTION being detected by the broadcast receiver?

Note: phone is running Android 7.1 compileSdkVersion 26 targetSdkVersion 26

edit:

As Ben has pointed out in his answer below that I need to have a DHCP server running on the GO device (PI in my case), so I went ahead and installed and configured DHCP service on the pi by following the first section at this link https://www.raspberrypi.org/documentation/configuration/wireless/access-point.md but, I can no longer run sudo wpa_supplicant -B -dd -iwlan0 -Dnl80211 -c /etc/wpa_supplicant/wpa_supplicant.conf command successfully as it might be clashing with the dhcp conf? any idea how i can enable p2p while running DHCP?

Upvotes: 0

Views: 836

Answers (2)

Ben
Ben

Reputation: 156

Your Raspberry Pi is in the GO role and needs to act as a DHCP server. An Android device in the Client role will not broadcast WIFI_P2P_CONNECTION_CHANGED_ACTION until it has received an IP address from the GO via DHCP.

See my answer here for further details.

Upvotes: 0

Suchandra T
Suchandra T

Reputation: 646

Well, So as a part of GDPR (EU) implementation and similar things. From android 8 & onwards there will be a restriction on the way by which android devices receive broadcast on any event (ofcourse to hide few device specific infos/specs.)

Please have a look at this: https://developer.android.com/guide/components/broadcasts

Cheers.

Upvotes: 0

Related Questions