How to make Raspberry Pi automatically connect to the specified wifi, but no password

A very difficult issue

Writing this blog is because I have encountered a thorny issue, I think a lot of people using the Raspberry Pi should come across a similar problem, the problem is described as follows:
We did a project with the Raspberry Pi control the printer, our tree berry pie need to connect the router 5G we specify, but my raspberry pie which even had a good number of wifi hotspots, this time, when our raspberry pie boot time, it will be from the first scan, and with it the system calendar inside the recording of password, if successful landing, I would not even go to wifi hotspots we want , how to solve this problem?

How to edit wpa_supplicant.conf

In fact, the Raspberry Pi, controlled by wpa_supplicant.conf this document wifi connection, or I should say so, to control each of wifi ssid name and password when linux system via wpa_supplicant.conf, all wifi name and password when you save here, here it is my raspberries come in the wpa_supplicant.conf file

pi@xiajiashan:~$ sudo cat /etc/wpa_supplicant/wpa_supplicant.conf 
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=CN
network={
        ssid="4GPRINTER"
        psk="12345678"
        key_mgmt=WPA-PSK
}
network={
        ssid="CKKJ"
        psk="a1234567"
        key_mgmt=WPA-PSK
}
network={
        ssid="xiajiashan"
        psk="12345678"
        key_mgmt=WPA-PSK
}
network={
        ssid="CMCC-Kqzn"
        psk="88888888"
        key_mgmt=WPA-PSK
}
network={
        ssid="4G UFI_A6D"
        psk="1234567890"
        key_mgmt=WPA-PSK
}
network={
        ssid="zjzj"
        psk="123456789"
        key_mgmt=WPA-PSK
}
pi@xiajiashan:~$ 

To solve this problem - let me specify raspberry sent even wifi, how to do it?
We just need to we do not want raspberries sent wifi hotspot passwords change it, the purpose is to make changes because the password when connecting the right and find another wifi hotspot, until we find the hot spots of the specified printer 4GPRINTER, some people will say, hey, you do this hotspot is not the first, raspberry pie should first find is that it ah, ha ha, in fact, raspberry Pi is displayed on the screen when that order is not in accordance with our file to be displayed.

How to make Raspberry Pi boot configuration script automatically performs wpa_supplicant.conf

Well next, how to make it execute this document?
We only need to add a rc.local the following command on the line
wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
like this:

pi@xiajiashan:~$ cat /etc/rc.local 
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
exit 0
pi@xiajiashan:~$

Well, this is over, I hope to help You!

Published 39 original articles · won praise 14 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_27320195/article/details/105174606