I am making a program and I need this program to get WIFI Credentials before anything else. Kind of like when you buy an Alexa and it has you connect to the internet before you can do anything with it. How could i go about this or is there any code out there that someone has already created that i could look at and could be directed to??


WIFI Configuration Before Complete Boot-up Of Pi

You cannot usefully do anything network related before the Pi boots up properly. I think you have just misconstrued the concept of "booting", and what you really mean is you want the Pi to boot up the first time in a state where the goal is to get a wifi configuration somehow.

Kind of like when you buy an Alexa and it has you connect to the internet

That's not what happens. Alexa and similar devices initially run their own hotspot which you can connect to; you then provide an SSID and password so that they can connect to your WLAN. The first thing you want to do is configure the Pi to run either an open/unencrypted hotspot, or else one with a default password that can be used to connect to it. Along with that you need it to run a server application which will:

  • Handle interfacing with a remote client to get the SSID and password, and then apply that to Pi's networking configuration.

  • Attempt to connect to the WLAN using the new configuration.

  • On failure, revert to the original state, possibly storing a message to inform the user on next connect to the hotspot that the original attempt failed.

  • On success the server application exits and leaves the Pi connected to the WLAN configured such that on next boot it will do so automatically.

So, there's a bit of work. It requires you understand how networking is configured on the pi, and are able to create a simple server app which fulfils the above requirements.

| improve this answer | |
  • thanks for the great explanation. Can you share how one would go about with 'forgeting' a wifi network? Say I have 2 networks and already connected my service to the first network. How do I connect it to the second network? In your flow it would always connect since it finds network 1. Keep in mind at this point the pi will have already rebooted and is now on wifi network 1. – Terence Chow Jun 4 '18 at 16:30
  • That's really a question of understanding "how networking is configured on the pi", which I am not much help with since what it really means is "on the platform you intend to use" which, regardless of which GNU/Linux flavour that is (Raspbian, Arch, Ubuntu, etc.), I do not use the conventional networking services; I have my own stuff that I use built on low level tools (wpa_supplicant, dhclient, etc. -- conventional networking services manage these for you). – goldilocks Jun 5 '18 at 12:09
  • Anyway, based on that: A system will not automagically connect to any given WLAN unless it is configured to do so. To clarify the flow above: Initially, the Pi (like Alexa devices) would be functioning as an access point or router on its own network, which is not connected to anything else (which is why I'd call it an access point and not a router). It is not on the internet. It is totally alone, until you pick up its SSID and connect to it. Now there are two nodes, you and the device.. – goldilocks Jun 5 '18 at 12:10
  • ..The device runs an application (likely a web application, making it easy to access) you connect to and enter the details for your WLAN. After this, the device shuts down its temporary little network and tries to connect to your WLAN. If subsequently you want it to connect to something else somewhere that WLAN is not accessible, it could do this by going back to the initial state and awaiting configuration. If you want it to connect to something else when there are multiple WLANs it could access, you'll have to implement that (via configuring the networking service or your own software). – goldilocks Jun 5 '18 at 12:10
  • Yea I am not really thinking of having multiple WLANs, just thinking about if someone chooses the wrong WLAN but it works. (For example when a network provides you a 3g and a 5g service and you accidentally connect to 3g but obviously want the 5g service. Configuring networking service manually isn't a great solution since I don't want the user I give the product to, to have to configure the PI manually... – Terence Chow Jun 5 '18 at 15:03

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.