一段时间后,WiFi在Raspberry Pi上断开连接,不会重新连接


14

我终于可以使用以下设置(不使用wpa_supplicant.conf)将Raspberry Pi连接到隐藏的SSID网络(WPA2 Personal)。

但是,几个小时后,它会断开连接并且不会重新连接。

  • Raspberry Pi B +,运行NOOBS。
  • USB供电的WiFi卡(Ralink RT5370芯片组)
  • 已连接至隐藏的SSID(我不确定此隐藏的SSID与该问题有关,可能是红色鲱鱼)

这是日志:

Feb  6 14:36:01 raspberrypi wpa_supplicant[1641]: wlan0: CTRL-EVENT-DISCONNECTED bssid=90:72:40:1c:ed:c8 reason=4
Feb  6 14:36:01 raspberrypi kernel: [33883.785257] cfg80211: Calling CRDA to update world regulatory domain
Feb  6 14:36:01 raspberrypi ifplugd(wlan0)[1634]: Link beat lost.
Feb  6 14:36:11 raspberrypi ifplugd(wlan0)[1634]: Executing '/etc/ifplugd/ifplugd.action wlan0 down'.
Feb  6 14:36:11 raspberrypi dhclient: Internet Systems Consortium DHCP Client 4.2.2
Feb  6 14:36:11 raspberrypi ifplugd(wlan0)[1634]: client: Internet Systems Consortium DHCP Client 4.2.2
Feb  6 14:36:11 raspberrypi dhclient: Copyright 2004-2011 Internet Systems Consortium.
Feb  6 14:36:11 raspberrypi ifplugd(wlan0)[1634]: client: Copyright 2004-2011 Internet Systems Consortium.
Feb  6 14:36:11 raspberrypi dhclient: All rights reserved.
Feb  6 14:36:11 raspberrypi ifplugd(wlan0)[1634]: client: All rights reserved.
Feb  6 14:36:11 raspberrypi dhclient: For info, please visit https://www.isc.org/software/dhcp/
Feb  6 14:36:11 raspberrypi ifplugd(wlan0)[1634]: client: For info, please visit https://www.isc.org/software/dhcp/
Feb  6 14:36:11 raspberrypi dhclient: 
Feb  6 14:36:11 raspberrypi dhclient: Listening on LPF/wlan0/00:0f:60:01:de:14
Feb  6 14:36:11 raspberrypi ifplugd(wlan0)[1634]: client: Listening on LPF/wlan0/00:0f:60:01:de:14
Feb  6 14:36:11 raspberrypi dhclient: Sending on   LPF/wlan0/00:0f:60:01:de:14
Feb  6 14:36:11 raspberrypi ifplugd(wlan0)[1634]: client: Sending on   LPF/wlan0/00:0f:60:01:de:14
Feb  6 14:36:11 raspberrypi dhclient: Sending on   Socket/fallback
Feb  6 14:36:11 raspberrypi ifplugd(wlan0)[1634]: client: Sending on   Socket/fallback
Feb  6 14:36:11 raspberrypi dhclient: DHCPRELEASE on wlan0 to 192.168.128.254 port 67
Feb  6 14:36:11 raspberrypi ifplugd(wlan0)[1634]: client: DHCPRELEASE on wlan0 to 192.168.128.254 port 67
Feb  6 14:36:12 raspberrypi wpa_supplicant[1641]: wlan0: CTRL-EVENT-TERMINATING - signal 15 received
Feb  6 14:36:12 raspberrypi ifplugd(wlan0)[1634]: Program executed successfully.
Feb  6 14:36:14 raspberrypi ntpd[2157]: Deleting interface #2 wlan0, 192.168.128.122#123, interface stats: received=389, sent=396, dropped=0, active_time=33841 secs
Feb  6 14:36:14 raspberrypi ntpd[2157]: 192.96.207.244 interface 192.168.128.122 -> (none)
Feb  6 14:36:14 raspberrypi ntpd[2157]: 178.18.16.124 interface 192.168.128.122 -> (none)
Feb  6 14:36:14 raspberrypi ntpd[2157]: 204.2.134.164 interface 192.168.128.122 -> (none)
Feb  6 14:36:14 raspberrypi ntpd[2157]: 216.152.240.220 interface 192.168.128.122 -> (none)
Feb  6 14:36:14 raspberrypi ntpd[2157]: peers refreshed

这是/ etc / network / interfaces

auto lo
iface lo inet loopback
iface eth0 inet dhcp
auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
    wpa-scan-ssid 1
    wpa-ap-scan 1
    wpa-key-mgmt WPA-PSK
    wpa-proto RSN WPA
    wpa-pairwise CCMP TKIP
    wpa-group CCMP TKIP
    wpa-ssid "Na*****"
    wpa-psk *********************************************************

1
您可以分享sudo iwconfig wlan0显示的输出Power Mgmt: On吗?如果是这样,那么您需要禁用它sudo iwconfig wlan0 power off,这应该可以解决您的问题
Shan-Desai

@ Shan-Desai解决方案解决了我的问题。我的树莓派W每3-5分钟就会断开一次连接。非常感谢!
戴夫

Answers:


10

我能够解决此问题的唯一方法是编写由cron作业每分钟运行一次的shell脚本。它检查网络是否断开,如果是,则重新连接。在过去的一周里,它运行得非常好。

#!/bin/bash

MY_PATH="`dirname \"$0\"`"              # relative
LOG_PATH="`( cd \"$MY_PATH\" && cd .. && pwd )`/log/network.log"
now=$(date +"%m-%d %r")

# Which Interface do you want to check
wlan='wlan0'
# Which address do you want to ping to see if you can connect
pingip='google.com'

# Perform the network check and reset if necessary
/bin/ping -c 2 -I $wlan $pingip > /dev/null 2> /dev/null
if [ $? -ge 1 ] ; then
    echo "$now Network is DOWN. Perform a reset" >> $LOG_PATH
    /sbin/ifdown $wlan
    sleep 5
    /sbin/ifup --force $wlan
else
    echo "$now Network is UP. Just exit the program." >> $LOG_PATH
fi

1
你好 使用前ifup --force wlan0为什么要使用ifdown wlan0
小号安德鲁

@Andrew我的猜测是,否则它将什么都不做。如果ifup不执行任何操作,也不会导致自动重新连接。要么是原因,要么是通过这种方式进行编码比测试它是否可以更容易进行。
lucidbrot

就我而言,重新连接部分似乎是不必要的。每分钟对Google Ping一次,以保持连接100%稳定。
gromit190 '18

6

这是预期的行为;无法保证100%的时间提供WiFi。

这适用于2015年5月5日之前的Raspbian Wheezy(以及后来的Jessie),请参阅如何设置网络/ WiFi /静态IP。

如果您希望它在失去连接后自动重新连接wpa-roam,请与wpa_supplicant.conf)

PS发布您的SSID和PSK是不明智的

/ etc / network / interfaces

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
auto wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

iface home inet dhcp
iface default inet dhcp

/etc/wpa_supplicant/wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    scan_ssid=1
    ssid="xxx"
    psk="yyy"
    id_str="home"
    proto=RSN
    key_mgmt=WPA-PSK
    pairwise=CCMP
    auth_alg=OPEN
    eap=MD5
}

您能否举一个将wpa-roam与wpa_supplicant.conf结合使用的示例?我不再使用conf文件,因为当我在其中放置凭据时,由于某种原因它永远不会连接到隐藏的SSID。顺便说一句,SSID和PSK无效,尽管我会删除它们,因为它们会分散注意力。谢谢。
米卡

2
我在上面列出了我的。隐藏的SSID的秘诀是scan_ssid=1
Milliways

3

按照建议,您可以使用wpa-roam,尽管我建议使用wicd或网络管理器。他们负责所有设置,还处理多个网络,并且更加用户友好。

例如,wicd有一个curses gui可以安装:

sudo apt-get install wicd-curses

并运行:

wicd-curses

1

断开连接存在相同的问题...与无线适配器有关。我的linksys ae3000每隔几天就会断开连接。我对其进行了少许修改,使其可以与运动USB摄像机和nfs共享一起使用,并添加了电子邮件通知。

Crontab条目:

*/1 * * * * /root/netcheck.sh > /dev/null 2>&1

修改后的脚本:

#!/bin/bash

LOG_PATH="/var/log/network.log"
now=$(date +"%m-%d %r")

# Which Interface do you want to check (wlan = wireless, eth0 = ethernet)
iface='eth0'
# Which address do you want to ping to see if you can connect
pingip='google.com'

# Perform the network check and reset if necessary
/bin/ping -c 2 -I $iface $pingip > /dev/null 2> /dev/null
if [ $? -ge 1 ] ; then
    echo "$now Network is DOWN. Perform a reset" >> $LOG_PATH
    /sbin/ifdown $iface
    sleep 5
    /sbin/ifup --force $iface
    sleep 5
    /bin/mount -o remount /data (reconnects my NAS nfs share)
    sleep 2
    /etc/init.d/motion restart  (restarts motion to clean hung processes)
    sleep 3
    /etc/init.d/motion restart  (2nd restart for sanity sake, sometimes 1st restart doesn't pan out)
    mail -s "`hostname` $iface recovered" xxxxxxxxx@gmail.com < /dev/null  (send me an email so I know about this)
fi

0

我更改了时间设置,一切都开始为我工作。

首选项-> Raspberry Pi配置->本地化选项卡

我确保为我的位置正确设置了所有4个选项。



0

遇到相同的问题,请每分钟让我的Google Ping Ping一次,以解决此问题。

sudo crontab -e

将此添加到文件末尾

* * * * * /bin/ping -c2 -I wlan0 8.8.8.8 >/dev/null

这基本上与接受的答案相同吗?
德克

本质上是。实际上,没有。我的PI不需要重新连接,因为它不需要。OP也不可能。
gromit190
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.