22

I was finally able to get my Raspberry Pi connected to a hidden SSID network (WPA2 Personal) using the below settings (not using wpa_supplicant.conf).

However, after a few hours it disconnects and does not reconnect.

  • Raspberry Pi B+, running NOOBS.
  • USB powered WiFi card (Ralink RT5370 chipset)
  • Connected to a hidden SSID (I'm not sure the hidden SSID has anything to do with this issue, might be a red herring)

Here is the log:

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

Here is the /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 *********************************************************
Micah
  • 441
  • 1
  • 3
  • 10
  • 1
    can you share you output of `sudo iwconfig wlan0` does it show `Power Mgmt: On`? If so then You need to disable it `sudo iwconfig wlan0 power off`which should solve your problem – Shan-Desai Mar 06 '16 at 21:47
  • @Shan-Desai solution fixed my problem. My raspberry Pi W will disconnect every 3-5 minutes. Thanks a lot! – David Morabito Nov 12 '17 at 04:42

8 Answers8

12

The only way I as able to resolve this issue was to write a shell script that is run every minute by a cron job. It checks if the network is down, if so, reconnects it. It has worked very well for the last week.

#!/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
Micah
  • 441
  • 1
  • 3
  • 10
  • 1
    Hi. Before using `ifup --force wlan0` why you are using `ifdown wlan0` – S Andrew Aug 28 '17 at 08:08
  • @Andrew My guess is that it would otherwise just do nothing. And if `ifup` does nothing, it also doesn't cause an automatic reconnect. Either this is the reason, or it was easier to code it this way than to test if it would work otherwise. – lucidbrot Mar 07 '18 at 19:43
  • In my case, the reconnection part seems unnecessary. Pinging Google every minute keeps the connection 100% stable. – birgersp Nov 30 '18 at 07:50
7

This is expected behaviour; WiFi can not be guaranteed 100% of the time.

This applies to Raspbian Wheezy prior to 2015-05-05 for later (and Jessie) See How do I set up networking/WiFi/Static IP

If you want it to reconnect automatically after loss of connectivity use wpa-roam in conjunction with wpa_supplicant.conf)

PS It is not sensible to publish your SSID and 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
}
Milliways
  • 54,718
  • 26
  • 92
  • 182
  • Can you give an example of using wpa-roam in conjunction with wpa_supplicant.conf? I'm not using the conf file anymore because when I put the creds in there it would never connect to the hidden SSID for some reason. BTW, that SSID and PSK are not valid, though I'll remove them as they are a distraction. Thanks. – Micah Feb 10 '15 at 03:27
  • 2
    I have listed mine above. the secret to hidden SSID is `scan_ssid=1` – Milliways Feb 10 '15 at 12:17
4

As suggested you can use wpa-roam, though I would recommend to use wicd or network manager. They take care of all the settings, they also deal with multiple networks and are more user friendly.

For instance wicd has a curses gui that you can install with:

sudo apt-get install wicd-curses

And run with:

wicd-curses
tfjgeorge
  • 151
  • 2
2

Check your power_save settings; e.g.:

pi@pebbles:~ $ sudo iw dev wlan0 get power_save
Power save: on

If it's on, you can temporarily disable it with sudo iw dev wlan0 set power_save off.

To permanently disable it, see this answer for details.

  • Note that running this command is a temporary fix, and the change will be lost when the pi is turned off (or loses power). More permanent fixes are found in the linked answer. – Shadow Jan 05 '22 at 10:27
2

was having the same issues with disconnect... has to do with the wireless adapter. My linksys ae3000 disconnects every few days. I slightly modified it to work with my motion usb cameras and nfs share plus added email notification.

Crontab entry:

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

Modified Script:

#!/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
1

I changed the time settings and it all started working for me.

Preferences-> Raspberry Pi Configuration-> Localisation Tab

I made sure all 4 of the options were set correctly for my location.

plyons126
  • 11
  • 1
0

disable wifi power management should help, as discussed here: https://discourse.osmc.tv/t/pi-3-wifi-unstable/14171/25

0

Had the same problem, solved it by making my PI ping Google once every minute.

run sudo crontab -e

Add this to the end of the file

* * * * * /bin/ping -c2 -I wlan0 8.8.8.8 >/dev/null
birgersp
  • 111
  • 3