我想用树莓派尝试一些网络项目,我只需要在一对树莓派之间发送数据包。作为第一步,我很高兴能够以临时模式在 Raspberry Pis 之间进行 ping 操作。尽管在线查看了几个教程和示例,但我还没有成功地做到这一点。
我有 2 个安装了 Debian Wheezy OS 的 Raspberry Pi。我正在使用以下 USB 适配器,我在两个 pi 上都安装了固件,并通过以托管模式将它们连接到路由器来测试它们是否工作:总线 001 设备 004:ID 050d:945a Belkin Components F7D1101 v1 Basic Wireless Adapter [Realtek RTL8188SU]
以下是有关网络信息的一些打印输出:
每个 pi 的 /etc/network/interfaces:
pi1@raspberrypi ~ $ cat /etc/network/interfaces
auto lo
iface lo inet loopback
iface eth0 inet dhcp
auto wlan0
iface wlan0 inet manual
address 192.168.2.1
netmask 255.255.255.0
wireless-channel 4
wireless-essid pi-ad-hoc
wireless-mode ad-hoc
pi2@raspberrypi ~ $ cat /etc/network/interfaces
auto lo
iface lo inet loopback
iface eth0 inet dhcp
auto wlan0
iface wlan0 inet manual
address 192.168.2.2
netmask 255.255.255.0
wireless-channel 4
wireless-essid pi-ad-hoc
wireless-mode ad-hoc
每个 pi 上的 ifconfig:
pi1@raspberrypi ~ $ ifconfig wlan0
wlan0 Link encap:Ethernet HWaddr ec:1a:59:46:8e:5a
inet addr:192.168.2.1 Bcast:192.168.2.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:26 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)
pi2@raspberrypi ~ $ ifconfig wlan0
wlan0 Link encap:Ethernet HWaddr ec:1a:59:46:59:0a
inet addr:192.168.2.2 Bcast:192.168.2.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:6 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)
每个 pi 上的 iwconfig:
pi1@raspberrypi ~ $ iwconfig wlan0
wlan0 IEEE 802.11bg ESSID:"pi-ad-hoc" Nickname:"rtl_wifi"
Mode:Ad-Hoc Cell: 02:11:87:FA:4A:02 Bit Rate:54 Mb/s
Sensitivity:0/0
Retry:off RTS thr:off Fragment thr:off
Power Management:off
Link Quality:0 Signal level:0 Noise level:0
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
pi2@raspberrypi ~ $ iwconfig wlan0
wlan0 IEEE 802.11bg ESSID:"pi-ad-hoc" Nickname:"rtl_wifi"
Mode:Ad-Hoc Cell: 02:11:87:C4:F2:01 Bit Rate:54 Mb/s
Sensitivity:0/0
Retry:off RTS thr:off Fragment thr:off
Power Management:off
Link Quality:0 Signal level:0 Noise level:0
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
在一个 pi 上的路线(在另一个 pi 上相同):
pi1@raspberrypi ~ $ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
192.168.2.0 * 255.255.255.0 U 0 0 0 wlan0
在每个 pi 上进行 iwlist 扫描:
pi1@raspberrypi ~ $ sudo iwlist wlan0 scan
wlan0 Scan completed :
Cell 01 - Address: 02:11:87:FA:4A:02
ESSID:"pi-ad-hoc"
Protocol:IEEE 802.11bg
Mode:Ad-Hoc
Frequency:2.427 GHz (Channel 4)
Encryption key:off
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s; 36 Mb/s
48 Mb/s; 54 Mb/s
Quality:0 Signal level:0 Noise level:0
Cell 04 - Address: 02:11:87:C4:F2:01
ESSID:"pi-ad-hoc"
Protocol:IEEE 802.11bg
Mode:Ad-Hoc
Frequency:2.427 GHz (Channel 4)
Encryption key:off
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s; 36 Mb/s
48 Mb/s; 54 Mb/s
Signal level=100/100
pi2@raspberrypi ~ $ sudo iwlist wlan0 scan
wlan0 Scan completed :
Cell 01 - Address: 02:11:87:C4:F2:01
ESSID:"pi-ad-hoc"
Protocol:IEEE 802.11bg
Mode:Ad-Hoc
Frequency:2.427 GHz (Channel 4)
Encryption key:off
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s; 36 Mb/s
48 Mb/s; 54 Mb/s
Quality:0 Signal level:0 Noise level:0
Cell 02 - Address: 02:11:87:FA:4A:02
ESSID:"pi-ad-hoc"
Protocol:IEEE 802.11bg
Mode:Ad-Hoc
Frequency:2.427 GHz (Channel 4)
Encryption key:off
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s; 36 Mb/s
48 Mb/s; 54 Mb/s
Signal level=100/100
Ping 不起作用,并且它们之间似乎没有网络工作。从 iwconfig 中,您可以看到它们每个都有不同的“Cell”地址(与 iwlist 扫描中的 Cell 不同),这是用于定义 ad-hoc 网络的伪基站 ID(我的最佳理解来自我读过的)。此外,从 iwlist 中,每个 pi 都可以看到自己的以及其他 pi 的 ad-hoc 网络。我假设他们需要选择相同的 Cell id 进行通信,但我不确定如何让他们自动执行此操作。我尝试在每个 pi 上静态强制这些与以下命令相同,该命令不会更改单元格 ID,因此不起作用:
sudo iwconfig wlan0 ap (some address)
我还尝试了一个在 wpa_supplicant 配置中使用 ap_scan=2 的解决方案,这似乎没有帮助。
有人知道我做错了什么吗?
谢谢,安迪。