Raspberry Pi ad-hoc networking

后端 未结 3 1404
长情又很酷
长情又很酷 2020-12-24 09:25

I want to try some networking projects with Raspberry Pis, and I need to just send packets between a pair of pis. I would be happy as a first step just being able to ping be

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-24 09:55

    I was unsuccessful with any adapter using the RTL8188CUS chipset. Luckily, I had a number of Ralink RT5370 dongles (from this kit) that support the nl80211 interface and ad-hoc mode.

    My solution involves using wpa_supplicant and is configured with 2 files. Ensure that the nl80211 driver is installed:

    sudo apt-get install libnl1
    

    Next, create the following wpa_supplicant configuration file called /etc/wpa_supplicant-adhoc.conf on each Pi:

    ctrl_interface=DIR=/run/wpa_supplicant GROUP=netdev
    update_config=1
    ap_scan=2
    
    network={
      ssid="pihoc_wpa"
      mode=1
      frequency=2462
      proto=WPA
      key_mgmt=WPA-NONE
      pairwise=NONE
      group=TKIP
      psk="password"
    } 
    

    where you can choose the ssid, frequency (look here for valid values), and psk. Make sure that you are part of the user group net-dev using the command

    getent group netdev
    

    and if not, you can add yourself using

    sudo usermod -a -G netdev userName
    

    Next, add the following block to the /etc/network/interfaces file on each Pi:

    auto wlan0
    allow-hotplug wlan0
    iface wlan0 inet static
       address 10.10.2.1
       netmask 255.255.255.0
    pre-up wpa_supplicant -B -D nl80211 -i wlan0 -c /etc/wpa_supplicant-adhoc.conf
    

    where each Pi has a different address field beginning with 10.10.2.. Also, if your RT5370 adapter is using an interface other than wlan0 (e.g. wlan1, wlan2, etc.), be sure to use that interface name instead.

    At this point, the Pis should automatically join the network upon being rebooted. Test the connection by pinging or using ssh, for example run the following from the agent with IP address 10.10.2.1:

    ssh 10.10.2.2
    

    to access the agent with IP address 10.10.2.2.

    The steps listed here are adapted from this Arch Linux wiki article and this Raspberry Pi forum discussion.

提交回复
热议问题