7

I am working on a RPi radio project, and I'd like to be able to switch between a "setup mode" where the RPi acts as a Wi-Fi access point, allowing the user to send his/her home Wi-Fi credentials via a dedicated mobile app then write them into the wpa_supplicant file, and a "normal mode" where the board becomes a Wi-Fi client and connects to the Wi-Fi network the user specified while using the setup mode.

Is it possible?

7

It is possible, I suggest you to use a lighttpd with a webservice for your app. After that - just switch between hostapd(AP mode) and wpa_supplicant(client mode). It is as simple as stop one service and start another wia shell command.

UPDATE: Some tips. What is the simplest way is to use a systemd as a triggerhappy switcheroo, and let it be done like this :

  • use wpa_supplicant as a service
  • a hostapd is already a service in ubuntu/debian, so you don't have tо do anything about it.

Next, configure ISC-DHCPD and hostapd for your AP mode, check them to be working as AP, i.e. you can join a network and obtain an IP address, DNS from your DHCP is pingable from a device and working. After that use this cheatsheet on SystemD to make dhcpd and hostapd not start automatically on boot :

#systemctl disable hostapd.service
#systemctl disable isc-dhcp-server.service

and stop thoose SoB's ;) just like that :

#systemctl stop hostapd.service
#systemctl stop isc-dhcp-server.service

after that by a link I've pointed upstrings make wpa_supplicant ( install it like that : apt-get install wpasupplicant ) a service too, and set it up to be working as you wish, i.e. your RPi associates with AP you're about to use, receives IP+DNS, can ping/wget, e.t.c. After that - disable and stop the service just like we did it upstrings :

#systemctl stop wpa_supplicant.service
#systemctl disable wpa_supplicant.service   

After that here goes the magic :) to switch from mode to another just stop the services from a previous mode and start the needed ones(i.e. stop wpa_supplicant and start hostapd and isc-dhcp-server) like this:

#systemctl stop wpa_supplicant.service && systemctl start hostapd.service && systemctl start isc-dhcp-service.service

Yes, in one single string. The secret here is in "&&" construction - it's a type of queue when the next element will be executed only if the previous one haven't failed. So wherever from you'll make a call for this pipe, check for exitcode 0. It will guarantee you that everything was OK switching the modes. That's it, feel free to ask questions if you need more help!

  • Thanks for your answer. That's what I was thinking of, but I am not that good with shell scripting. I'll try to find some examples, because I think I'll have to fiddle with dhcpd.conf, /etc/default/isc-dhcp-server and /etc/network/interfaces as suggested in this article link – Zbam Mar 16 '16 at 13:28
  • @Zbam need more info to help you out? – Alexey Vesnin Mar 16 '16 at 14:10
  • some insight on the way I could switch from one mode to the other would be great, because from what I've seen it involves many files – Zbam Mar 16 '16 at 17:23
  • @Zbam take a look at my edit, I've updated my answer – Alexey Vesnin Mar 16 '16 at 20:20
  • This has been very useful for my own "turtles" project... but I am still unclear on one detail: I ideally want to "try" to connect to a known wifi connection, and if it fails, then default to AP mode. Is there an easy way to do this with SystemD, or should I be writing a shell script that will attempt the connection, and then do the above? Any guidance would be helpful! (Or let me know if you would prefer this as a separate question) – Aerophilic Nov 20 '16 at 20:11

protected by Community Mar 26 '17 at 22:47

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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