1

My Pi Zero has a USB WiFi Adapter attached.

I want it to automatically connect to my home wifi network using a static IP. When I take it out and about... for walks, or whatever... I want to have it automatically connect to my iPhone hotspot.

At the moment, the Pi Zero automatically connects to my hotspot, so that's good. But, when I bring it home, it is given a random IP, rather than the Static IP I assigned it.

This is what I have so far:

In /etc/network/interfaces I have:

auto lo
iface lo inet loopback

allow-hotplug wlan0

iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

iface phone inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

iface home inet static
address 192.168.1.123
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.254

and in /etc/wpa_supplicant/wpa_supplicant.conf I have:

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

network={
        ssid="MY SSID"
        scan_ssid=1
        psk="MY PSK"
        id_str="home"
        priority=15
}

network={
        ssid="MY HOTSPOT NAME"
        psk="HOTSPOT PSK"
        id_str="phone"
}
RPi user
  • 21
  • 2
  • what version of Raspbian are you running – Steve Robillard Jan 13 '16 at 20:09
  • Latest Jessica 8.0 – RPi user Jan 13 '16 at 20:11
  • 1
    Jessie (dyac!)... – RPi user Jan 13 '16 at 20:12
  • 2
    http://raspberrypi.stackexchange.com/q/37920/5538 – goldilocks Jan 13 '16 at 20:18
  • the network settings and files have changed for Raspbian recently the short version only the ssid and psk go in the wpa_supplicant.conf file and the static details go in /rtc/dhcpcd.conf file more info can be found in my answer here. Especially the link for further info at the bottom. If that solution works let me know and I will mark this question as a dupe. – Steve Robillard Jan 13 '16 at 20:18
  • Thank you, for the quick responses. I'll check all that out and report back :) – RPi user Jan 13 '16 at 20:21
  • @SteveRobillard Did you mean to put a link on the 'here' ? – RPi user Jan 13 '16 at 20:32
  • sorry http://raspberrypi.stackexchange.com/questions/40622/raspberry-seems-to-ignore-static-ip-setting/40624#40624 – Steve Robillard Jan 13 '16 at 20:38
  • @SteveRobillard Thanks. No worrries. Followed the link from goldilocks (thought that was your pseudonym!) and now cannot see the Zero on my network at all. Will try your method at work tomorrow (when I can get it on a monitor) and report back... – RPi user Jan 13 '16 at 20:49
  • @SteveRobillard Will your solution allow me to use my Zero as stated? I want to be able to have it connect to my hotspot automatically when on the road and then, when I get home, have it connect to my home router with a Static IP...? – RPi user Jan 13 '16 at 21:03
  • it should it basically just moves things to the new places the link at the bottom of my answer goes into some of the details – Steve Robillard Jan 13 '16 at 21:05
  • Steve, please would you explain what the '/24' is in: static ip_address=192.168.1.23/24 – RPi user Jan 14 '16 at 09:32
  • @SteveRobillard So, I added the Static address settings to /etc/dhcpcd.conf and the Pi Zero could not connect to the iPhone hotspot until I commented that out. Does this mean that it is still trying to use a static IP for the Hotspot (which it can't)? So, with only wlan0 available as an interface, how do I get it to switch to static 'only' when it is connecting to my home router? Or have I missed something? – RPi user Jan 14 '16 at 10:37
  • So why do you need a static IP at home? You could set an IP reservation in your router. You could setup the home network to use Ehernet (which is also faster) only. If you are assigning a static IP to make SSH easier etc. there are ways to solve that as the issue. – Steve Robillard Jan 14 '16 at 11:36
  • No ethernet port on a Pi Zero. It is to enable me to ssh/vnc remotely. What are other ways? I'll try IP reservation. But, essentially, is what I want not possible? – RPi user Jan 14 '16 at 18:22

0 Answers0