Search code examples
network-programmingraspberry-piwifihotspot

raspberry, switch between wifi and hotspot


I am working on a raspberry for a POC demo. My raspberry needs to be set up as a hotspot and that went fine following this tutorial: https://www.raspberrypi.org/documentation/configuration/wireless/access-point.md

However I can't get to easily switch between a "normal" wifi and the hotspot. I need to get back to a normal behavior to download packages to the raspberry for instance. I found : http://sirlagz.net/2013/01/22/script-starting-hostapd-when-wifi-goes-down/ . Typing the same command does not seem to do the job.

What I've tried is :

  • Raspberry set up as hotspot
  • Stop dnsmasq and hostapd
  • edit /etc/dhcpcd.conf (to remove the static ip configuration)
  • restart dhcpd

I can see the raspberry is connected to the correct wifi but apparently I have no internet connection and can't download any packages.

Maybe there is something more to do about the iptables but I really don't know much about that and I prefer not screwing all my configuration.

Any idea about the procedure to switch between the two "modes"?

Cheers


Solution

  • I have found a solution that works perfectly.

    Disable access point :

    • sudo systemctl disable hostapd dnsmasq

    • comment the static ip config in /etc/dhcpcd.conf

    • sudo reboot

    Enable access point

    • sudo systemctl enable hostapd dnsmasq

    • comment the static IP config in /etc/dhcpcd.conf

    • sudo reboot

    The difference is instead of just stopping the 2 services I completely disable them.