简体   繁体   English

在Raspberry Pi中几秒钟后,Wifi直接连接会自动断开连接

[英]Wifi direct connection disconnects automatically after a few seconds in Raspberry Pi

I am using this configuration for wifi direct connection in Raspberry PI 2 B+ 我在Raspberry PI 2 B +中使用此配置进行wifi直接连接

ctrl_interface=DIR=/var/run/wpa_supplicant
driver_param=use_p2p_group_interface=1
update_config=1
device_name=Raspberry_pi
device_type=1-0050F204-1
p2p_go_intent=1
p2p_go_ht40=1
country=IN

and then started wpa supplicant using 然后启动wpa请求者使用

sudo wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant/p2p.conf -B

and then add new group using 然后使用添加新组

sudo wpa_cli -iwlan0 p2p_group_add

and then set an IP using 然后使用设置IP

ifconfig p2p-wlan0-0 192.168.1.20

and then set the pin using 然后使用设置引脚

sudo wpa_cli -ip2p-wlan0-0 wps_pin any 0000

up to this, everything is working fine and I am able to connect to the Raspberry Pi over wifi direct from an Android device. 到目前为止,一切正常,我可以直接从Android设备通过wifi连接到Raspberry Pi。 Now I am facing two problems, 现在我面临两个问题,

  1. The connection automatically gets disconnected after a few seconds 几秒钟后连接自动断开连接
  2. When I tried to reconnect the Android device, it shows invited forever (but disconnecting and connecting n times between 2 Android devices works fine and the connections are not getting disconnected). 当我尝试重新连接Android设备时,它会永久显示邀请(但在2个Android设备之间断开和连接n次工作正常并且连接没有断开连接)。 I am able to connect to the Raspberry Pi only after terminating wpa supplicant and starts the process again. 只有在终止wpa请求者后才能连接到Raspberry Pi并再次启动该过程。 What is wrong with this configuration? 这个配置有什么问题? What changes should be made to make the connection persistent? 应该进行哪些更改才能使连接持久化?

Edit 1: 编辑1:

When I restart the wpa supplicant and connects for the first time, this is what I get in the log 当我重新启动wpa请求者并第一次连接时,这就是我在日志中获得的内容

CTRL-EVENT-EAP-STARTED 2a:3f:69:1d:ed:c5
<3>CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=1
<3>CTRL-EVENT-EAP-PROPOSED-METHOD vendor=14122 method=254
<3>WPS-REG-SUCCESS 2a:3f:69:1d:ed:c5 884efa75-0a98-52c6-85aa-07527f4a9c35
<3>WPS-SUCCESS 
<3>CTRL-EVENT-EAP-FAILURE 2a:3f:69:1d:ed:c5
<3>AP-STA-CONNECTED 2a:3f:69:1d:ed:c5 p2p_dev_addr=2a:3f:69:1d:ed:c5

and after the automatic disconnection 并在自动断开后

AP-STA-DISCONNECTED 2a:3f:69:1d:ed:c5 p2p_dev_addr=2a:3f:69:1d:ed:c5

if I try to reconnect without restarting this is printed in the console 如果我尝试重新连接而不重新启动,则会在控制台中打印出来

CTRL-EVENT-EAP-STARTED 2a:3f:69:1d:ed:c5
<3>CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=1
<3>CTRL-EVENT-EAP-PROPOSED-METHOD vendor=14122 method=254
<3>WPS-PIN-NEEDED 884efa75-0a98-52c6-85aa-07527f4a9c35 2a:3f:69:1d:ed:c5 [Xperia XA |MediaTek Inc.|MTK Wireless Model|1.0|2.0|10-0050F204-5]
<3>CTRL-EVENT-EAP-FAILURE 2a:3f:69:1d:ed:c5

Your Raspberry Pi is probably in the P2P Group Owner (GO) role since you are manually creating a group with the p2p_group_add command (autonomous GO) rather than letting the devices negotiate based on their GO intent values. 您的Raspberry Pi可能属于P2P组所有者(GO)角色,因为您使用p2p_group_add命令(自主GO)手动创建组,而不是让设备根据其GO意图值进行协商。 p2p_go_intent=1 in your config would likely have no effect in this case. 在这种情况下,配置中的p2p_go_intent=1可能没有效果。

The device in the GO role should run a DHCP server in order to assign IP addresses to the connecting P2P Clients. GO角色中的设备应运行DHCP服务器,以便为连接的P2P客户端分配IP地址。 Correspondingly, each client should run a DHCP client in order to receive an IP address. 相应地,每个客户端应运行DHCP客户端以接收IP地址。

Excerpt from Section 3.2.6.1 of the Wi-Fi P2P Technical Spec: 摘自Wi-Fi P2P技术规范第3.2.6.1节:

Higher-layer data services may use IP. 高层数据服务可以使用IP。 The P2P Group Owner shall act as a DHCP server to provide IP addresses to the connected P2P Clients that use IP. P2P组所有者应充当DHCP服务器,以向使用IP的连接的P2P客户端提供IP地址。 The DHCP Server shall at a minimum support Internet Protocol version 4 (IPv4) and assignment of an IP address, subnet mask... DHCP服务器至少应支持Internet协议版本4(IPv4)并分配IP地址,子网掩码......

...A P2P Client that uses IP shall be capable of acting as a DHCP Client. ...使用IP的P2P客户端应能够充当DHCP客户端。

Note — While a P2P Device can select distinct IP subnets for each P2P Group for which it is P2P Group Owner, it is possible that a P2P Device connected to more than one P2P Group may end up with colliding subnets. 注 - 虽然P2P设备可以为其作为P2P组所有者的每个P2P组选择不同的IP子网,但是连接到多个P2P组的P2P设备可能最终会出现冲突的子网。 Use of a random component in the selection of IP subnet may reduce the probability of (but not eliminate) this situation occurring 在IP子网的选择中使用随机分量可以降低(但不是消除)这种情况发生的可能性

I think you will find that the Android device is waiting to receive an IP configuration via DHCP before moving on to a connected state, timing out if that does not happen. 我想你会发现Android设备正在等待通过DHCP接收IP配置,然后才能进入连接状态,如果没有发生则超时。

To make the connection persistent the group needs to be created as a persistent group. 要使连接保持持久,需要将组创建为持久组。 You should be able to do that in the autonomous GO scenario with p2p_group_add persistent . 你应该能够在p2p_group_add persistent的自治GO场景中做到这p2p_group_add persistent In the negotiated GO scenario you should be able to do something like p2p_connect <peer device address> <pbc|pin|PIN#|p2ps> [display|keypad|p2ps] persistent go_intent=15 . 在协商的GO场景中,您应该能够执行类似p2p_connect <peer device address> <pbc|pin|PIN#|p2ps> [display|keypad|p2ps] persistent go_intent=15 See the wpa_supplicant README-P2P for further details: https://w1.fi/cgit/hostap/plain/wpa_supplicant/README-P2P . 有关更多详细信息,请参阅wpa_supplicant README-P2P: https//w1.fi/cgit/hostap/plain/wpa_supplicant/README-P2P

Finally, the command wps_pin any <PIN> allows any device to connect using the provided PIN but restricts the PIN to one-time-use. 最后,命令wps_pin any <PIN>允许任何设备使用提供的PIN进行连接,但将PIN限制为一次性使用。 Either use the wps_pin <address> <PIN> form or set a new PIN by running wps_pin any <PIN> again. 使用wps_pin <address> <PIN>表单或通过再次运行wps_pin any <PIN>设置新的PIN。

I am running almost the very same scenario at the moment, follow the first section 我现在正在运行几乎相同的场景,请按照第一部分进行操作

Setting up a Raspberry Pi as an access point in a standalone network (NAT) 将Raspberry Pi设置为独立网络(NAT)中的访问点

at this link in order to install/comfigure DHCP service on the Pi: 在此链接上,为了在Pi上安装/配置DHCP服务:

https://www.raspberrypi.org/documentation/configuration/wireless/access-point.md https://www.raspberrypi.org/documentation/configuration/wireless/access-point.md

Btw, if it works for you, can you please share the order of running dhcp and enabling wifi p2p as I am sort of having trouble with p2p after enabling dhcp. 顺便说一句,如果它适合你,请你分享运行dhcp和启用wifi p2p的顺序,因为我在启用dhcp后遇到p2p问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM