上週六向露天賣家
鎰盛購買的 Raspberry Pi B+ 到貨後, 興沖沖地跑去長明街禾樺買了兩個小散熱片 (20 元), 回來貼到板子上的兩顆 IC 後, 迫不及待地將灌好 NOOBS/RASBIAN 的 Micro SD 卡插入後接電測試, Bravo! 功能均正常, 而且 B+ 的韌體似乎已經有瑞昱 Realtek 8188u 晶片的驅動程式, 所以我僅剩的一顆迅捷 FAST FW150US 網卡插入後用 lsusb 指令就發現已可驅動, 再用 ifconfig 也可看到 wlan0, 但因為時間不夠, 就帶回鄉下再測試.
原本打算四天連假就可以將這塊 B+ 搞定, 然後把它放在鄉下, 透過分享器防火牆設定可以從遠端登入樹莓派的 Linux. 但是我照之前這篇作法卻一直連不上鄉下的 WiFi :
#
樹莓派的 Wifi 設定 : 使用迅捷 FW150US
用 ifconfig 指令查詢 wlan0 都只顯示 IPv6 網址, 沒有 Inet4 網址, 表示根本沒有連上 WiFi 分享器 :
pi@raspberrypi:~ $ ifconfig
eth0 Link encap:Ethernet HWaddr b8:27:eb:2d:74:39
inet addr:192.168.2.114 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::f6a5:9334:bd66:f9a7/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1193 errors:0 dropped:3 overruns:0 frame:0
TX packets:785 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:490303 (478.8 KiB) TX bytes:88818 (86.7 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:200 errors:0 dropped:0 overruns:0 frame:0
TX packets:200 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:16656 (16.2 KiB) TX bytes:16656 (16.2 KiB)
wlan0 Link encap:Ethernet HWaddr 08:57:00:16:87:15
inet6 addr: fe80::c953:521c:d1c:85e4/64 Scope:Link
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
無奈之餘只好暫停, 跑去忙菜園 (所以才能忙完許多農事). 昨天回高雄後又繼續測試還是找不出原因, 即使 SD 卡格式化後重灌也還是沒辦法, 更換為 EDIMAX EDUP 8508 網卡也是一樣 (其實 FW150US 可以顯示 wlan0 應該就不是網卡的問題了).
晚上在下面文章讀到關於 WPA 實體重複可能導致 WiFi 可能無法連線問題 :
#
I can not get my WiFi connection to work (WPA 行程重複問題)
#
multiple instances of wpa_supplicant after boot [Solved]
我下 ps ax 指令去查, 發現還真有多個 WPA 實體 :
pi@raspberrypi:~ $
ps ax | grep wpa_supplicant
326 ? Ss 0:00 /sbin/wpa_supplicant -s -B -P /run/wpa_supplicant.wla n0.pid -i wlan0 -D nl80211,wext -C /run/wpa_supplicant
926 pts/0 S+ 0:00 grep --color=auto wpa_supplicant
再用 killall 指令殺掉全部 WPA 實體, 這時再用 ifconfig 去看, 會發現 wlan0 不見了 :
pi@raspberrypi:~ $
sudo killall wpa_supplicant
pi@raspberrypi:~ $
ps ax | grep wpa_supplicant
943 pts/0 S+ 0:00 grep --color=auto wpa_supplicant (只剩下一個了)
pi@raspberrypi:~ $
ifconfig
eth0 Link encap:Ethernet HWaddr b8:27:eb:2d:74:39
inet addr:192.168.2.114 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::f6a5:9334:bd66:f9a7/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:379 errors:0 dropped:0 overruns:0 frame:0
TX packets:301 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:31352 (30.6 KiB) TX bytes:44102 (43.0 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:200 errors:0 dropped:0 overruns:0 frame:0
TX packets:200 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:16656 (16.2 KiB) TX bytes:16656 (16.2 KiB)
接著以下列指令查詢無線韌體 :
pi@raspberrypi:~ $
apt-cache search firmware wireless (搜尋韌體)
ap-utils - Access Point SNMP Utils for Linux
hostap-utils - Utility programs for Host AP driver for Intersil Prism2/2.5/3
ipxe - PXE boot firmware
ipxe-qemu - PXE boot firmware - ROM images for qemu
linux-wlan-ng - utilities for wireless prism2 cards
wmaloader - firmware downloader for Linksys WMA11B media adapter
firmware-b43-installer - firmware installer for the b43 driver
firmware-b43legacy-installer - firmware installer for the b43legacy driver
atmel-firmware - Firmware for Atmel at76c50x wireless networking chips.
firmware-atheros - Binary firmware for Atheros wireless cards
firmware-ipw2x00 - Binary firmware for Intel Pro Wireless 2100, 2200 and 2915
firmware-iwlwifi - Binary firmware for Intel Wireless cards
firmware-libertas - Binary firmware for Marvell Libertas 8xxx wireless cards
firmware-
realtek - Binary firmware for Realtek wired and wireless network adapters
firmware-zd1211 - binary firmware for the zd1211rw wireless driver
libertas-firmware - Firmware for Marvell's libertas wireless chip series (dummy package)
firmware-brcm80211 - Binary firmware for Broadcom 802.11 wireless cards
firmware-ralink - Binary firmware for Ralink wireless cards
firmware-ti-connectivity - Binary firmware for TI Connectivity wireless network adapters
發現確實已經有 Realtek 韌體, 但我還是以下列指令重新安裝 :
pi@raspberrypi:~ $
sudo apt-get install firmware-realtek (安裝瑞昱韌體)
以下列指令重新啟動網路介面結果還是一樣無法連上 :
pi@raspberrypi:~ $
sudo /etc/init.d/networking restart
然後我又找到下列文章, 照其說明用指令手動連線 :
#
Ubuntu 如何使用指令啟用無線網路 ?
$iwconfig (找無線網卡代號)
$sudo ifconfig wlan0 up (啟用無線網卡)
$sudo iwlist wlan0 scan | more (掃描附近基地台)
$sudo iwconfig wlan0 essid "EDIMAX-tony" (連線基地台)
$sudo iwconfig wlan0 12345678 (基地台密碼)
$sudo dhclient wlan0 (取得 IP)
結果還是連不上.
好吧! 那就照前一次作法重新下載安裝 8188cu 的驅動程式, 然後重開機, 結果還是連不上 :
#
樹莓派的 Wifi 設定 : 使用迅捷 FW150US
最後檢查 /etc/network/interfaces, 才發現原來 wpa-ssid 與 wpa-psk 參數的內容不是用雙引號括起來的, 而是奇怪的符號 :
pi@raspberrypi:~ $ cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
auto wlan0
iface wlan0 inet dhcp
wpa-ssid
¨EDIMAX-tony
¨
wpa-psk
¨123456789
¨
原來如此! 我是用迷你小鍵盤編輯 interfaces 檔的, 按 Ctrl + " 鍵時都要按兩次才會出現此類似雙引號的符號, 但因為太像了看不出來, 我用筆電透過 Putty SSH 連線來檢查才發現, 經修改後重新啟動網路介面就可正常獲得 Inet 網址了 :
pi@raspberrypi:~ $
sudo nano /etc/network/interfaces (編輯檔案)
pi@raspberrypi:~ $ cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
auto wlan0
iface wlan0 inet dhcp
wpa-ssid
"EDIMAX-tony
" (正常的雙引號)
wpa-psk
"1234567890
" (正常的雙引號)
pi@raspberrypi:~ $
sudo /etc/init.d/networking restart (重啟網路介面)
[....] Restarting networking (via systemctl): networking.serviceWarning: Unit file of networking.service changed on disk, 'systemctl daemon-reload' recommended.
. ok
pi@raspberrypi:~ $ ifconfig
eth0 Link encap:Ethernet HWaddr b8:27:eb:2d:74:39
inet addr:192.168.2.114 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::f6a5:9334:bd66:f9a7/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:898 errors:0 dropped:1 overruns:0 frame:0
TX packets:632 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:75720 (73.9 KiB) TX bytes:89779 (87.6 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:200 errors:0 dropped:0 overruns:0 frame:0
TX packets:200 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:16656 (16.2 KiB) TX bytes:16656 (16.2 KiB)
wlan0 Link encap:Ethernet HWaddr 08:57:00:16:87:15
inet addr:
192.168.2.115 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::fc58:61fc:b069:9a5e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:36 errors:0 dropped:50 overruns:0 frame:0
TX packets:59 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6524 (6.3 KiB) TX bytes:13020 (12.7 KiB)
終於搞定了! But, 到底關鍵原因是啥? 因為胡亂測試所以也說不準, 當然 SSID 帳號與密碼的雙引號是最後的障礙, 但我記得在鄉下測試時不是用迷你小鍵盤, 而是標準鍵盤, 那時所編輯的雙引號應該是正確的, 為何還是連不上? 所以我覺得重複的 WPA 實體可能是主要原因.
參考資料 :
sudo dhclient -v wlan0
iwconfig wlan0
wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
/etc/wpa_supplicant/wpa_supplicant.conf:ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="Nerd"
psk="SECRET"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
group=CCMP TKIP