Wireless mesh networking on Raspberry Pi using bat

2020-02-26 11:28发布

So I'm trying to setup a wireless mesh network using Raspberry Pi's, with the Edimax EW-7811Un WLAN Adapter and the batman-adv protocol.

I've tried following the basic setup guides from:

Unfortunately, when I get to the point where I need to ping one node from the other, I get

Destination Host Unreachable.

Running the batctl o command displays

'no batman nodes in range'

However, when running iwconfig, both nodes appear to be associated with the network I've setup, and when running iwlist wlan0 scan, the network I've setup appear as cells on both nodes.

I'm now at a loss as to how to proceed. I have read some articles on issues with ad-hoc support for Linux WLAN adapter drivers. My adapter is using the RTL8192CU driver. Could this be the cause of the issue?

P.S. I have looked at the following post, but this was no help, unfortunately.

Edit: contents of /etc/network/interfaces:

Both currently setup nodes have the same contents:

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

Edit: contents of /etc/wpa_supplicant/wpa_supplicant.conf for both nodes:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

Edit: ifconfig, iwconfig, and route for both nodes:

Node 1

ifconfig

wlan0    Link encap: Ethernet  HWaddr 80:1f:02:9b:bc:6c
         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:1  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)

iwconfig

wlan0    IEEE 802.11bg  ESSID:"pi-ad-hoc" Nickname:"<WIFI@REALTEK>"
         Mode:Ad-Hoc  Frequency:2.412 GHz  Cell: 02:11:87:A1:CD:FF
         Bit Rate:54 Mb/s   Sensitivity:0/0
         Retry:off    RTS thr:off    Fragment thr:off
         Encryption key:off
         Power Management:off
         Link Quality=2/100  Signal level=2/100  Noise level=0/100
         Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
         Tx excessive retries:0  Invalid misc:0  Missed beacon:0

route

Kernel IP routing table
Destination    Gateway        Genmask        Flags  Metric  Ref    Use  Iface
192.168.2.0    *              255.255.255.0  U      0       0        0  wlan0

Node 2

ifconfig

wlan0    Link encap:Ethernet  HWaddr 80:1f:02:da:2e:ee
         inet addr:192.168.2.3  Bcast:192.168.2.255  Mask:255.255.255.0
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:0  errors:0  dropped:0  overruns:0  frame:0
         TX packets:6  errors:0  dropped:0  overruns:0  carrier:0
         collisions:0  txqueuelen:1000
         RX bytes:0  (0.0 B)  TX bytes:0  (0.0 B)

iwconfig

wlan0    IEEE 802.11bg ESSID:"pi-ad-hoc"  Nickname:"<WIFI@REALTEK>"
         Mode:Ad-Hoc  Frequency:2.412 GHz  Cell: 02:11:87:2F:D6:FF
         Bit Rate:54 Mb/s   Sensitivity:0/0
         Retry:off  RTS thr:off  Fragment thr:off
         Encryption key:off
         Power Management:off
         Link Quality=2/100  Signal level=2/100  Noise level=0/100
         Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
         Tx excessive retries:0  Invalid misc:0  Missed beacon:0

route

Kernel IP routing table
Destination    Gateway        Genmask        Flags  Metric  Ref     Use   Iface
192.168.2.0    *              255.255.255.0  U      0       0         0   wlan0

6条回答
Juvenile、少年°
2楼-- · 2020-02-26 12:15

I dont have anywhere to test at the moment so sorry for the lack of screenshots :(

If you are still interested and have set up several mesh networks using batman-adv and catwoman and faced similar issues (I have done mixed devices like android phones, foneras, openwrt devices, etc, etc to work together).

First thing to check when using batman-adv is the compatibility version, check on your dmesg which one is using each node when you load de batman-adv module, it should match in both or they will not see each other even with both setup propertly! (this has given me quite some headaches in the past hehe)

If the nodes still can't see each other you need to check that you dont have any issues when changing the mode to ad-hoc.

Now, once the nodes see each other remenber that batman-adv works in layer 2, batctl has a ping tool to ping on this layer even when the nodes can't see each other.

Im not really sure why you have wpa-supplicant here, mesh networks doesnt need it, to set up your mesh just chose a channel and an ESSID; all nodes should have this same parameter, then just put the wifi interfaces in ad-hoc mode and on batctl add the interfaces to the bat0 interface.

bat0 interface? thats the actual mesh interface, not wlan0. You did put an ip on the wlan0 interfaces, but that would not work, you need to give bat0 an ip and that the one the mesh will use. By memory the command would be: batctl ifadd wlan0, but check the batctl help just in case :)

If you want to share internet connection you need to follow below steps, then on the node connected to the internet create a bridge between bat0 and the interface with internet (remenber to leave wlan0 or whatever interface is using the mesh alone) and to finish go to batctl on that node and switch the gw (gateway) mode on (batctl gw on, I think). then you can run dhcp over bat0 on all the nodes and it should work just fine.

Just in case, be sure that the batman-adv module is loaded hehe

I think I have covered all sides when it comes to setting up a batman-adv mesh. If you need any doubts I will try to help :D

Best regards and hope your mesh works fine! :)

查看更多
等我变得足够好
3楼-- · 2020-02-26 12:17

You try to setup an adhoc network. However I suggest to start with a simpler approach -- Wifi Access Point and then switch over to adhoc network.

From my point of view it is easier to connect the raspi to a wireless accesspoint. Because the accesspoint will hand over the IP adresses through DHCP. Where in adhoc mode you have to care about the IPs yourself (as far as I know).

Therefore the config for the accespoint based solution would be like

/etc/network/interfaces

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

(which is by the way pretty much like yours already)

and then the /etc/wpa_supplicant/wpa_supplicant.conf which connects to a WPA2 accesspoint

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
        ssid="KBBL"
        psk=af2a9daa6cadd3434ad96db48173a04acddb04e6a8c5adf52ae78ef13XXXX
        key_mgmt=WPA-PSK
        scan_ssid=1
        proto=RSN
        pairwise=CCMP
        group=CCMP
}

Please note that the psk key needs to be generated by

$wpa_passphrase "KBBL" "YOUR_KEY"

which results in something like

network={
        ssid="KBBL"
        #psk="YOUR_KEY"
        psk=29af596e046ad450eeddd6752432d5dbd26575960b9024e5cbb99e945cdafa4e
}

just copy and paste the psk

Then reboot! I sometimes have trouble when just changing the network wifi settings on the fly. While after reboot everything is fine. Also the wifi network takes some time. At my place something between 20-40secs.

Btw. I also had trouble when trying to setup wifi without encryption or WEP encryption so I suggest to use WPA2 or WPA. Please also note that the WPA configuration of the wpa_supplicant is much different from this of WPA2. So you might start using the above example for WPA2.

查看更多
看我几分像从前
4楼-- · 2020-02-26 12:23

I can confirm, that this is an issue of the latest rtl8192cu driver. I was using an older version of that driver for edimax wlan adapters with batman working (almost) fine. But I found, that under certain circumstances (with heavy load), the connection failed. Then I upgraded to the latest version of that driver (date: September 11th 2013) but found that batman wasn't working any longer (in the exact same configuration as with the older driver). The symptoms were exactly as you described in your post.

Edit: My post was deleted, saying that I don't give an answer to the question. I disagree with that: this IS an answer to the original post. The only question in the original post was this: "My adapter is using the RTL8192CU driver. Could this be the cause of the issue?"

Again: I can confirm that using this (latest) driver causes the issue. This driver is incompatible with batman. The issue has nothing to do with the configuration file. Try to look for an older driver or -better - use a wlan adapter with a different chipset.

查看更多
劫难
5楼-- · 2020-02-26 12:24

I just checked your configuration with two Raspberries and the same Wifi Adapters (Edimax EW-7811Un) on Raspbian. Long story short: I get the same results as you do.

My findings are as follows

  1. Setting up one Raspberry for adhoc as described and connecting from IPad or Notebook ... works fine
  2. Creating an adhoc connection on the Notebook and let one Raspberry join ... works fine
  3. Setting up one Raspbery for accesspoint and connecting from IPad or Notebook ... works fine
  4. However when setting up two Raspberries either in adhoc mode or accesspoint mode wont connect to each other ... doesnt work!
  5. As you figured out by this source here the available modes of these adapters (rtl8192cu) are unclear.
  6. Other sources create adhoc connections easily with similar setup and other wifi adpater like described.

It pretty much seems like the adapters drivers won't allow this connection.

Please note: setting up an accesspoint with these adapters requires a special compiled hostapd: read here to find out how

查看更多
混吃等死
6楼-- · 2020-02-26 12:24

As wifi connections to your access point work fine. We assume drivers and hardware are fine. Now let's try to connect via -- Wifi ad-hoc.

I found here some pretty promising configuration without using wpa_supplicant. As already mentioned we have to use fixed IPs. So of course they need to be different on both raspis. Please note that I had to change "manual" to "static". Now it also works at my place (after reboot). Here it comes

/etc/network/interfaces

auto lo
iface lo inet loopback
iface eth0 inet dhcp
auto wlan0
iface wlan0 inet static
    address 192.168.2.10
    netmask 255.255.255.0
    wireless-channel 4
    wireless-essid pi-ad-hoc
    wireless-mode ad-hoc

Please note: The chosen IPs should not be in the sub net of your wired network (eth0).

Also make sure sudo ifconfig wlan0 shows the correct IP

pi@raspberrypi ~ $ sudo ifconfig wlan0
wlan0     Link encap:Ethernet  HWaddr 80:1f:02:87:77:81  
          inet addr:192.168.2.10  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:53 errors:0 dropped:29 overruns:0 frame:0
          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:6007 (5.8 KiB)  TX bytes:1042 (1.0 KiB)

and here is the sudo iwconfig wlan0

pi@raspberrypi ~ $ sudo iwconfig wlan0
wlan0     IEEE 802.11bg  ESSID:"pi-ad-hoc"  Nickname:"<WIFI@REALTEK>"
          Mode:Ad-Hoc  Frequency:2.412 GHz  Cell: 02:11:87:DF:AB:FF   
          Bit Rate:54 Mb/s   Sensitivity:0/0  
          Retry:off   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:off
          Link Quality=2/100  Signal level=2/100  Noise level=0/100
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0
查看更多
Rolldiameter
7楼-- · 2020-02-26 12:32

I had problems with the Edimax EW-7811Un in combination with the Raspberry Pi A+ It became unresponsive after a few minutes. Apache and SSH were unreachable and ping did not connect.

The iwconfig program shows: "Power Management:off" but still, it goes into an idle mode.

I found a solution from MrEngman on the raspberry forums: http://www.raspberrypi.org/forums/viewtopic.php?f=28&t=61665

This might solve it:

Make a file 8192cu.conf in directory /etc/modprobe.d/ with the command:

    sudo nano /etc/modprobe.d/8192cu.conf

add these lines:

    # Disable power management
    options 8192cu rtw_power_mgnt=0 rtw_enusbss=0
查看更多
登录 后发表回答