valnurat
Posts: 7
Joined: Wed May 21, 2014 7:07 am

Reconnect WiFi after power off

Tue Sep 12, 2017 8:20 am

Hi.

I have a RPi2 running Debian.

I'm trying to setup WiFi on this device. When my RPi is running I get WiFi connection, but if I turn off power, it will not reconnect to my WiFi. If I do a: sudo reboot it will connect again.

How can I get it to reconnect with out me typing that command?

I have using the following in my /etc/network/interfaces

Code: Select all

auto lo
iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet wlan0
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
In my wpa_supplicant.conf I have this:

Code: Select all

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

network={
    ssid="network1"
    psk="pw1"

    ssid="network2"
    psk="pw2"
}
I have looked at this for help
https://www.raspberrypi.org/documentati ... ess-cli.md

valnurat
Posts: 7
Joined: Wed May 21, 2014 7:07 am

Re: Reconnect WiFi after power off

Wed Sep 13, 2017 11:23 am

Is there no one who had this problem?

User avatar
davidcoton
Posts: 2378
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Reconnect WiFi after power off

Wed Sep 13, 2017 1:36 pm

valnurat wrote:Is there no one who had this problem?
Apparrently not amongst those who have read your post so far.
valnurat wrote: In my wpa_supplicant.conf I have this:

Code: Select all

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

network={
    ssid="network1"
    psk="pw1"

    ssid="network2"
    psk="pw2"
}
Shouldn't that be:

Code: Select all

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

network={
    ssid="network1"
    psk="pw1"
}

network={
    ssid="network2"
    psk="pw2"
}
(Just checking, I'm not an expert.)
You should also have a "country=xx" line to set the correct radio regulations.
valnurat wrote: if I turn off power, it will not reconnect to my WiFi. If I do a: sudo reboot it will connect again.
Don't turn power off without doing a shutdown first, the SDCard can get corrupted. It may think you are connected when you restart, because no disconnect was processed.
"If it ain't broke, fix it until it is."
“Raspberry Pi is a trademark of the Raspberry Pi Foundation”
The Pink Unicorn is a symbol of commitment to sensible discussion of future versions of the Raspberry Pi ™

valnurat
Posts: 7
Joined: Wed May 21, 2014 7:07 am

Re: Reconnect WiFi after power off

Wed Sep 13, 2017 2:45 pm

davidcoton wrote:
Wed Sep 13, 2017 1:36 pm
valnurat wrote:Is there no one who had this problem?
Apparrently not amongst those who have read your post so far.
Thank for clearing that out. :)
davidcoton wrote: (Just checking, I'm not an expert.)
You should also have a "country=xx" line to set the correct radio regulations.
What is that?
davidcoton wrote:
valnurat wrote: if I turn off power, it will not reconnect to my WiFi. If I do a: sudo reboot it will connect again.
Don't turn power off without doing a shutdown first, the SDCard can get corrupted. It may think you are connected when you restart, because no disconnect was processed.
Yes, I know, but it could happen if someone just press the powerswhich off

User avatar
davidcoton
Posts: 2378
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Reconnect WiFi after power off

Wed Sep 13, 2017 10:04 pm

valnurat wrote:
Wed Sep 13, 2017 2:45 pm
davidcoton wrote: You should also have a "country=xx" line to set the correct radio regulations.
What is that?
See here for an example.
valnurat wrote:
davidcoton wrote:
valnurat wrote: if I turn off power, it will not reconnect to my WiFi. If I do a: sudo reboot it will connect again.
Don't turn power off without doing a shutdown first, the SDCard can get corrupted. It may think you are connected when you restart, because no disconnect was processed.
Yes, I know, but it could happen if someone just press the powerswhich off
But that may be causing your problem. You can't expect a Pi always to recover from a power cut. One of the possible problems is that the state data for WiFi connection is inconsistent. At least you know how to recover.
"If it ain't broke, fix it until it is."
“Raspberry Pi is a trademark of the Raspberry Pi Foundation”
The Pink Unicorn is a symbol of commitment to sensible discussion of future versions of the Raspberry Pi ™

valnurat
Posts: 7
Joined: Wed May 21, 2014 7:07 am

Re: Reconnect WiFi after power off

Thu Sep 14, 2017 7:50 pm

But if I have the info about my wifi in wpa_supplicant.conf, why should RPi not connect again? And why is there any different between power on - reboot after and just a power on?

User avatar
davidcoton
Posts: 2378
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Reconnect WiFi after power off

Thu Sep 14, 2017 8:24 pm

valnurat wrote:
Thu Sep 14, 2017 7:50 pm
But if I have the info about my wifi in wpa_supplicant.conf, why should RPi not connect again? And why is there any different between power on - reboot after and just a power on?
Because, if you cut the power, the state stored may include the fact that WiFi is connected. Since the OS thinks it is connected, it won't try to reconnect. The hardware thinks differently, it disconnects and stays disconnected, expecting the OS to tell it to reconnect. If you shutdown properly, it will disconnect and remember at next boot that it disconnected, but you want it connected, so it reconnects.

The reboot supplies the proper shutdown sequence so the OS state is corect at the restart. The problem is with power off vs proper shutdown, not with the power on.

Just a theory.
"If it ain't broke, fix it until it is."
“Raspberry Pi is a trademark of the Raspberry Pi Foundation”
The Pink Unicorn is a symbol of commitment to sensible discussion of future versions of the Raspberry Pi ™

valnurat
Posts: 7
Joined: Wed May 21, 2014 7:07 am

Re: Reconnect WiFi after power off

Fri Sep 15, 2017 7:26 am

Ok., but I also tried to shutdown properly. It's the same result.

Return to “General discussion”

Who is online

Users browsing this forum: MiataCory, shtrnzn and 69 guests