3

I'm using a Raspberry Pi 2 Model B with a wireless USB adapter, Raspbian jessie. Until today I only had the raspy connected to my home network, everything was fine.

Now I have the necessity to bring the raspy with me, away from home. After reading several questions on how to set multiple wifi networks, I ended up with the following configuration:

This is my wpa_supplicant.conf file:

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

network={
    ssid="SSID1"
    psk="mypw"
    key_mgmt=WPA-PSK
    id_str="home"
}

network={
    ssid="SSID2"
    psk="mypw"
    key_mgmt=WPA-PSK
    id_str="android"
}

This is what I put into my dhcpcd.conf file:

# static IP address
interface eth0
static ip_address=192.168.0.51/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

# # FOR WIFI
interface wlan0
arping 192.168.0.1
arping 192.168.43.1

# # FOR HOME
profile 192.168.0.1
static ip_address=192.168.0.52/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

# # FOR ANDROID HOTSPOT
profile 192.168.43.1
static ip_address=192.168.43.52/24
static routers=192.168.43.1
static domain_name_servers=192.168.43.1

When I'm home the raspy should connect to the home network (this works good). When I'm not home, I enable android hotspot and I power up the raspy. It should connect to the android hotspot. However, I'm not able to get a connection with VNC for Android to the static IP address I provided.

Here is what I tested so far:

  • after powering up the raspy, I opened terminal emulator and used the command ip neighbor. This is the output: 192.168.43.82 dev wlan0 FAILED. Why 192.168.43.82 and not 192.168.43.52? I tried to connect to both these addresses but it failed.
  • Then, without turning the hotspot off and keeping raspby on, I came home, plugged in the ethernet cable, connected with VNC, opened terminal and ifconfig: wlan0 IP address was set to 192.168.43.52. I tried to connect to this address with VNC from android, but it failed.
  • With raspby GUI, I switched wifi to home network, then I switched again to android hotspot. This time I was able to connect with VNC from Android, using the ip address 192.168.43.52.

What can I do to fix this problem?

2

You don't need to configure the static IP address for wlan0. By default, the Android Hotspot Tools has a DHCP server that answers the DHCP IP request of Raspberry Pi wlan0 and then it gives an IP randomly.
If you are concerned about how to connect to raspberry pi without knowing the IP address, the answer is the hostname.

Install NetX Network Tools on your android phone and try pinging raspberrypi or raspberrypi.local which is the default hostname. Obviously if you changed the hostname, ping that one.

After that you realized everything is fine, try VNC.


All you need is to comment all lines of dhcpcd.conf and change wpa_supplicant options as your environment.

| improve this answer | |
  • 1
    Android never supported link-local addresses and mDNS so pinging raspberrypi.local will always fail. – Ingo Feb 17 at 18:03
  • @Ingo I didn't know about it BUT just tested with the application that I suggested (NetX Network Tools) and it's worked. I don't know why, can the application affected to this situation? – M. Rostami Feb 18 at 6:53
  • I'm astonished but interesting. Maybe mDNS is part of the NetX Network Tools? – Ingo Feb 18 at 9:57
  • @Ingo Not sure. I pinged a WS domain controller which AD configured. The domain is mimtech on 172.16.98.3 and mimtech.local the same. – M. Rostami Feb 18 at 17:10
0

I don't know Android but making a phone a hotspot does not magically turn it into a router. Hotspots are to give you internet access.

Use a router or attempt to find a router app.

Setting a Static IP address for a hotspot seems strange. Hotspots should provide DHCP

| improve this answer | |

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.