Wifi 直接连接在 Raspberry Pi 几秒钟后自动断开 [英] Wifi direct connection disconnects automatically after a few seconds in Raspberry Pi

查看:124
本文介绍了Wifi 直接连接在 Raspberry Pi 几秒钟后自动断开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Raspberry PI 2 B+ 中使用此配置进行 wifi 直接连接

I am using this configuration for wifi direct connection in Raspberry PI 2 B+

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

然后使用

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

然后使用

sudo wpa_cli -iwlan0 p2p_group_add

然后使用

ifconfig p2p-wlan0-0 192.168.1.20

然后使用

sudo wpa_cli -ip2p-wlan0-0 wps_pin any 0000

到目前为止,一切正常,我可以通过 wifi 直接从 Android 设备连接到 Raspberry Pi.现在我面临两个问题,

up to this, everything is working fine and I am able to connect to the Raspberry Pi over wifi direct from an Android device. Now I am facing two problems,

  1. 连接在几秒钟后自动断开
  2. 当我尝试重新连接 Android 设备时,它始终显示受邀(但在 2 个 Android 设备之间断开和连接 n 次工作正常,并且连接没有断开).只有在终止 wpa 请求者并再次启动该过程后,我才能连接到 Raspberry Pi.这个配置有什么问题?应该进行哪些更改才能使连接持久?

编辑 1:

当我重新启动 wpa 请求者并第一次连接时,这是我在日志中得到的内容

When I restart the wpa supplicant and connects for the first time, this is what I get in the log

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

和自动断开连接后

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

推荐答案

您的 Raspberry Pi 可能处于 P2P 组所有者 (GO) 角色中,因为您正在使用 p2p_group_add 命令手动创建组(自主 GO),而不是让设备根据它们的 GO 意图值进行协商.在这种情况下,您的配置中的 p2p_go_intent=1 可能不起作用.

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. p2p_go_intent=1 in your config would likely have no effect in this case.

处于 GO 角色的设备应运行 DHCP 服务器,以便为连接的 P2P 客户端分配 IP 地址.相应地,每个客户端都应该运行一个 DHCP 客户端以接收 IP 地址.

The device in the GO role should run a DHCP server in order to assign IP addresses to the connecting P2P Clients. Correspondingly, each client should run a DHCP client in order to receive an IP address.

摘自 Wi-Fi P2P 技术规范第 3.2.6.1 节:

Excerpt from Section 3.2.6.1 of the Wi-Fi P2P Technical Spec:

高层数据服务可能使用IP.P2P 组所有者应充当 DHCP 服务器,为使用 IP 的连接的 P2P 客户端提供 IP 地址.DHCP 服务器应至少支持 Internet 协议版本 4 (IPv4) 和 IP 地址分配、子网掩码...

Higher-layer data services may use IP. The P2P Group Owner shall act as a DHCP server to provide IP addresses to the connected P2P Clients that use IP. The DHCP Server shall at a minimum support Internet Protocol version 4 (IPv4) and assignment of an IP address, subnet mask...

...使用 IP 的 P2P 客户端应能够充当 DHCP 客户端.

...A P2P Client that uses IP shall be capable of acting as a DHCP Client.

注意 — 虽然 P2P 设备可以为其作为 P2P 组所有者的每个 P2P 组选择不同的 IP 子网,但连接到多个 P2P 组的 P2P 设备最终可能会出现子网冲突.在选择 IP 子网时使用随机组件可能会降低(但不会消除)这种情况发生的可能性

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. Use of a random component in the selection of IP subnet may reduce the probability of (but not eliminate) this situation occurring

我认为您会发现 Android 设备在进入连接状态之前正在等待通过 DHCP 接收 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.

要使连接持久,需要将组创建为持久组.您应该能够在使用 p2p_group_add persistent 的自主 GO 场景中做到这一点.在协商的 GO 场景中,您应该能够执行类似 p2p_connect 的操作.<pbc|pin|PIN#|p2ps>[display|keypad|p2ps] 持久 go_intent=15.有关更多详细信息,请参阅 wpa_supplicant README-P2P:https://w1.fi/cgit/hostap/plain/wpa_supplicant/README-P2P.

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. 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. See the wpa_supplicant README-P2P for further details: https://w1.fi/cgit/hostap/plain/wpa_supplicant/README-P2P.

最后,命令 wps_pin any 允许任何设备使用提供的 PIN 进行连接,但将 PIN 限制为一次性使用.要么使用 wps_pin

;<PIN> 再次运行 wps_pin any 形成或设置新的 PIN.

Finally, the command wps_pin any <PIN> allows any device to connect using the provided PIN but restricts the PIN to one-time-use. Either use the wps_pin <address> <PIN> form or set a new PIN by running wps_pin any <PIN> again.

这篇关于Wifi 直接连接在 Raspberry Pi 几秒钟后自动断开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆