1

Current setup are 2 "RaspberriPi 3" models

On the first one I am trying to establish an ad-hoc network with the following commands

ifconfig wlan0 down
iwconfig wlan0 mode ad-hoc
iwconfig wlan0 essid RPInet
ifconfig wlan0 10.0.0.200 netmask 255.255.255.0
/usr/sbin/dhcpd wlan0

/etc/network/interfaces

auto lo wlan0
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet manual

/etc/default/isc-dhcp-server

INTERFACES="wlan0"

/etc/dhcp/dhcpd.conf

DHCPDARGS=wlan0;
default-lease-time 600;
max-lease-time 7200;
option subnet-mask 255.255.255.0;
option broadcast-address 10.0.0.255;
option domain-name "RPi-Network";
option routers 10.0.0.1;
authoritative;

subnet 10.0.0.0 netmask 255.255.255.0 {
    range 10.0.0.2 10.0.0.20;
}

On the second RPi I want to use wpa_supplicant and dhclient to obtain a lease from the first one

wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/example.conf

/etc/network/interfaces

auto lo
iface lo inet loopback
iface eth0 inet manual
auto lo wlan0
iface lo inet loopback
allow-hotplug wlan0
iface wlan0 inet manual

/etc/wpa_supplicant/example.conf

ctrl_interface=/run/wpa_supplicant
update_config=1

network={
    ssid="RPInet"
}

Why is RPI 2 not obtaining an IP address from the DHCP?

Another question: Why is the DHCP not going into active state after using /usr/sbin/dhcp wlan0 ?

Raspberr Pi 1

RaspberryPi 2

The dhcpdiscover and offer in syslog from pi 1 are from itself. the mac address is its own, so why does it send itself requests?

migrated from stackoverflow.com Aug 9 '16 at 7:35

This question came from our site for professional and enthusiast programmers.

  • which channel are your pis connected on? do the channels match when you do iwconfig wlan0 on both Pis? – Shan-Desai Aug 9 '16 at 10:05
  • 2.412 Ghz the first one, none on the second. Both iwconfigs are in the pictures below my post. – wa112 Aug 11 '16 at 11:19
  • can you fix your Rpis iwconfig as sudo iwconfig wlan0 mode ad-hoc channel 1 essid RPinet this can majorly solve problems at times. if you want some help I have written a blogpost here – Shan-Desai Aug 11 '16 at 11:34
  • on the first one i used iwconfig wlan0 channel 1 and I configured wpasupplicant on the other one to ctrl_interface=/var/run/wpa_supplicant ctrl_interface_group=root update_config=1 ap_scan 2 network={ssid="RPi" scan_freq=2412 scan_ssid=1 key_mgmt=NONE mode=1 priority=1} when starting it and starting wpa_cli it says trying to associate with SSID "RPi", Association request to the driver failed – wa112 Aug 12 '16 at 9:54
  • when I use iwconfig wlan0 mode ad-hoc iwconfig wlan0 essid RPi and ifconfig wlan0 10.0.0.201 netmask 255.255.255.0 up I can ping the first one on 10.0.0.200 successfully – wa112 Aug 12 '16 at 10:10
0

I read through your Logs which you have posted for your Pis.

Here are some bits that I would like to point out:

  1. I am really not sure if you should be using really high txpower. Yours is 31 dBm which is extremely high. Chances are that this signal might cause a lot of interference on the channel if there is some wireless activity going on. I suggest you reduce it something like 10 to 15 dBm this is an acceptable value.

  2. Also if you are using Edimax 7811UN adapters and using Raspbian Wheezy with versions less than 7.10/7.11 then there will definitely be an incompatibility issue, since the older Raspbian versions did cause a lot of problems when running the Edimax in ad-hoc mode. (I did some experiments and this was evident for me). However in Raspbian Jessie or Wheezy 7.10 and 7.11 this compatibility driver issue is resolved and the adapters work in ad-hoc mode

  3. If you are not receiving any DHCP offers chances are likely that your Pis are on two different frequencies of the spectrum. I strongly suggest creating a small bash function in your /etc/rc.local where you atleast set initial iwconfig parameters the same.

     createNetwork(){
               ifconfig wlan0 down
               iwconfig wlan0 mode ad-hoc essid RpiNet channel 1
               ifconfig wlan0 up
     }
     createNetwork
     exit 0
    
  4. One more thing is that not a lot of people realize that appropriate channel selection for WLAN is really important. You should definitely first do a scan/sweep on your vicinity and see which Routers or hot spots are using the same channels. Do a iwlist wlan0 scanning and go through all the channels and chose an appropriate channel for your ad-hoc network

I have a white-paper which proposes that in order to have minimal interference among the WLAN channels selection of Channels 1, 6, 11 are the best. For instance, if you scan and find channel 1 and 11 occupied it is suggested to use Channel 6 to avoid interference.

Comprehensive Look

Create a setup function in your /etc/rc.local like follows:

 # network connectivity..
 createNetwork(){

          ifconfig wlan0 down
          iwconfig wlan0 mode ad-hoc essid Pi-Net txpower 10 dBm channel 6
          ifconfig wlan0 up
 }

 createNetwork

 exit 0

Your DHCP server settings look right to me. Maybe do something like auto enable on reboot of the Pi

   sudo systemctl enable dhcpcd.service # For Jessie

or

   sudo update-rc.d isc-dhcp-server enable # For Wheezy

This is what I can make of from your situation. I suggest getting updated to Jessie or atleast Wheezy 7.10/7.11 for proper functioning of Ad-Hoc networking.

Also one thing is switch off your power-management of your WiFi dongle in order to avoid making your dongle sleep when Idle.

  iwconfig wlan0 power off

This solution is based on the assumptions of your situation, and the best of my knowledge to help you solve it through

  • It now works without using wpa_supplicant at all. All I am using is iwconfig wlan0 mode ad-hoc, iwconfig wlan0 essid RPi and dhclient -1 wlan0. With just those commands I am able to receive an IP from DHCP. Thank you very much! I will have a look into power ratio and channel selection, thank you for pointing that out! – wa112 Aug 17 '16 at 9:49
  • Is that a good thinG? – Shan-Desai Aug 17 '16 at 9:51
  • desirably I would have wanted wpasupplicant to set the parameters and connect, but this will be just fine – wa112 Aug 17 '16 at 9:53
  • All I am wondering now is why /usr/sbin/dhcp wlan0 command wont start DHCP. When checking status it tells me it is in "inactive". So I use service isc-dhcp-server restart and it becomes active... – wa112 Aug 17 '16 at 9:59
  • chances are you dhcp might not be right executable available on the Pi. I was also once confused as to which dhcp service was to be used isc-dhcp-server or dhcpcd configuration. I am sure a little research would get the answer on the table. – Shan-Desai Aug 17 '16 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.