Bosse_B
Posts: 980
Joined: Thu Jan 30, 2014 9:53 am

Jessie on RPi3 - can a script trigger WiFi connect?

Thu Jun 30, 2016 10:07 am

I think I need to control the state of the RPi3 WiFi programmatically in order to ensure that the RPi3 will connect to a given SSID as soon as it is present.
Currently I have several WiFi networks defined in the supplicant file but only one actually will appear on the air (when power to the device is switched on).
When it does appear I want my RPi3 to connect to it ASAP.
What happens now is that it takes about 6-7 minutes after the SSID is on the air before the Pi connects, way too slow for the automation project I am working on. :(
Is there a way for a script to tell the Pi to immediately connect to the SSID if it is available?
Or is there a Jessie setting somewhere which forces the WiFi system to connect quickly?
Bo Berglund
Sweden

epoch1970
Posts: 5131
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Jessie on RPi3 - can a script trigger WiFi connect?

Thu Jun 30, 2016 12:39 pm

Do you have wifi power saving enabled? I would try to disable power saving.
Otherwise I suppose "ifup wlan0" or "ifup --force wlan0" should relaunch the whole setup for the interface, including association.

To reply to your other post (...), I suppose I would write a daemon that runs scans from time to time. If you use "trigger/dump" it will be non-blocking, but the dump will be either empty of full of crusty details according to the presence or not of the AP you seek.

Code: Select all

root@berck:~# iw wap0 scan trigger ssid nonexistent 
root@berck:~# iw wap0 scan dump
root@berck:~# iw wap0 scan trigger ssid Livebox-9996
root@berck:~# iw wap0 scan dump
BSS 18:62:2c:a0:99:96(on wap0)
	TSF: 0 usec (0d, 00:00:00)
	freq: 2462
	beacon interval: 100 TUs
...
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Bosse_B
Posts: 980
Joined: Thu Jan 30, 2014 9:53 am

Re: Jessie on RPi3 - can a script trigger WiFi connect?

Thu Jun 30, 2016 1:06 pm

Thanks for replying.
Yes I posted in Troubleshooting as well but then figured it was probably also relevant to target the Raspbian forum...
The sequence of events which will lead to the WiFi connection is this:
- A control program is started by cron
- It checks if a measurement is due. If not it exits and nothing further happens
- If due then it sets a GPIO pin to start up the system via a few relays
- In about 3-4 seconds the system is ready and has started the WiFi AP
- Now the program on the Pi needs to connect to the system via WiFi but has to wait for the RPi to connect to the target SSID (here is the problem since I have no control over this step)
- After the connection and data exchange the RPi shuts down the external system via the relays and exits the cron job

My problem is that following the power up there is an unknown time before the WiFi network is actually connected and nothing further can be done until such a time...

Hence a way to force the RPi to connect to the SSID is needed.

Concerning WiFi power down I have already disabled it.
And the RPi has its wlan0 enabled. It also has Ethernet connection, that is where I communicate with the RPi (SSH via PuTTY).

Note: the system is now at a remote location so I need to perform everything via the Ethernet network...
Bo Berglund
Sweden

Bosse_B
Posts: 980
Joined: Thu Jan 30, 2014 9:53 am

Re: Jessie on RPi3 - can a script trigger WiFi connect?

Sat Jul 02, 2016 8:51 am

I found a workaround for the delays:
1) After powering down the instrumentation I issue the following from my program to shut down the WiFi interface:

Code: Select all

sudo ifdown wlan0
2) After powering up the instrumentation I issue the following to re-enable WiFi:

Code: Select all

sudo ifup wlan0
This causes WiFi to start operating and it connects to the configured SSID in about 12-15 seconds. Still a bit slow but much better than 6 minutes...
Bo Berglund
Sweden

User avatar
bensimmo
Posts: 4622
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Jessie on RPi3 - can a script trigger WiFi connect?

Sat Jul 02, 2016 10:39 am

I'm just thinking, I don't think my phones, tablets etc are tha much faster.
It has to scan, see it, have a chat and then configure the link.

Maybe assign IP address first?
Is it possibly to use an agressive scanning option ?
Time you relauch of the Wi-Fi perfectly to the AP making it a live connection ? (e.g. constantly scan and as soon as it's seen, initial a connect, rather than just guess)
Could even log time between events and then pick a best prelauch time for both to happen at the same time, the majority of time...
:lol:
could well be overkill.

ifconfig and iwconfig may be quicker methods to look at ?


EDIT/ looks like iw is the new way to do things.
perhaps something in here can be used https://wireless.wiki.kernel.org/en/use ... ntation/iw
I've never tried 'iw'

Return to “Raspberry Pi OS”