hertohe
Posts: 6
Joined: Wed Oct 26, 2016 6:57 am

Automating wifi configuration

Wed Oct 26, 2016 9:05 am

Hello,

I'm looking at the best way to do enable my pi zero to connect to a new wifi in order to access to internet (without direct keyboard/screen/mouse linked to the pi).
I'm not sure of the method to make the wifi configuration as easy as possible so that the pi can easily connect to a new wifi (unknown).

I was thinking of doing a solution like this:
1. By default, pi is acting like an Access Point on a defined ssid
2. Software/admin connects to the wifi of the pi and registers the details of the new wifi (with internet access) (through a site, app..)
3. pi receives a request and executes a script to update the wifi configuration file with the new details
3. if wifi connection is OK then it stops to act as an access point and is now connected to internet

What do you think? Do you see any other solution? Is there already some implementation of that?

Thanks.

RAZERZ
Posts: 57
Joined: Mon Jun 13, 2016 4:56 pm

Re: Automating wifi configuration

Wed Oct 26, 2016 11:48 am

Use ssh? Connect to a known network (maybe use your mobile phones mobile data to tether) and just install connect bot or something, set up a static ip (search Google on how to do that) and now you have the same ip so connectbot will work. For example, I have 192.168.1.77 so I can just leave it from the first connect instead of looking at ip addresses etc.
Raspberry pi 3 set up as desktop with raspbian.
I guess you can say I am not newbie with linux but I am not a master at it either.
I will always try to help you as much as I can because I know how hard it is to run into problems :D

hertohe
Posts: 6
Joined: Wed Oct 26, 2016 6:57 am

Re: Automating wifi configuration

Wed Oct 26, 2016 12:12 pm

Thanks for your feedback.

I'm not sure how this is solving my issue, as the question is about how to connect to a known network..

Maybe better summarized:

1) I know a wifi connection (ssid/pass)
2) I don't want to connect to the pi directly (so I don't want to use keyboard, mouse, screen on the pi)
3) It is a pi zero with wifi adapter (so no ethernet)

=> Is there a way to set up the wifi of the pi with another computer, app, .. ? connect with usb on the pi? setup the pi as access point to be able to connect to it from another computer?

User avatar
davidcoton
Posts: 5834
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: Automating wifi configuration

Wed Oct 26, 2016 12:53 pm

hertohe wrote:I'm not sure how this is solving my issue, as the question is about how to connect to a known network..
You are correct, a static IP is not helpful and can cause further problems unless the address is reserved on any network you might use.
hertohe wrote:=> Is there a way to set up the wifi of the pi with another computer, app, .. ? connect with usb on the pi? setup the pi as access point to be able to connect to it from another computer?
If you can edit the correct file on the SDCard, you can set the network up. Doing that requires a system that can read/write the SDCard and has a screen and keyboard. So, you can:
1) Connect a keyboard and screen to the Pi0 just for initial setuip
2) Use a card reader on another Linux system
3) Use Ethernet to connect via ssh -- but not on a Pi0

There is meant to be a way to put the network details on a file in /boot (which can be accessed with a cardreader on a Win PC), but AFAIK there are still problems with that method (aka, it doesn't work).

For the details of what to change, see this topic.
Location: 345th cell on the right of the 210th row of L2 cache

jbudd
Posts: 1641
Joined: Mon Dec 16, 2013 10:23 am

Re: Automating wifi configuration

Wed Oct 26, 2016 4:46 pm

Use your phone as a wifi hotspot.
As long as the Pi knows your SSID and password, it will connect to the phone.
Then you can use Juice SSH , or another app to edit wpa_supplicant.conf on the Pi, append the credentials of the network you are visiting.
Turn off the phone hotspot, the Pi will connect to the new network (hopefully!).

User avatar
HawaiianPi
Posts: 6212
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Automating wifi configuration

Wed Oct 26, 2016 8:44 pm

There is a file called wpa_supplicant.conf that contains the WiFi network info. If you set that file up in advance, you can boot the Pi headless and it will connect, then you can SSH in using the Pi's hostname.

The full path the file is:

Code: Select all

/etc/wpa_supplicant/wpa_supplicant.conf
Which is located on a Linux ext4 partition on the Raspbian SD card.

Unfortunately, neither Windows or Mac OS can read/write ext4 natively. You could use another Raspberry Pi, or any computer running Linux. Most Linux distributions have a "Live" version that can run off of a USB flash drive without making any permanent changes to the host computer.

If you are using the full version of Raspbian Jessie you can copy the wpa_supplicant.conf file to the /boot partition (the only partition visible to Windows) and it will be moved to the correct location when Raspbian boots (does not work with Jessie-Lite).

/etc/wpa_supplicant/wpa_supplicant.conf should look like this:

Code: Select all

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

network={
	ssid="network1-service-set-identifier"
	psk="network1-WPA-security-key"
	key_mgmt=WPA-PSK
}

network={
	ssid="network2-service-set-identifier"
	psk="network2-WPA-security-key"
	key_mgmt=WPA-PSK
}
The Pi should automatically connect to any network you add to this file.

Hope that's what you were looking for.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

hertohe
Posts: 6
Joined: Wed Oct 26, 2016 6:57 am

Re: Automating wifi configuration

Thu Oct 27, 2016 12:11 pm

Hey,

thanks for your replies. I know about that file wpa_supplicant.conf, but my idea was to avoid having to use it directly.

I want to offer the pi as an IoT device to people.. so I want to allow the "clients" to easily configure their IoT device for the internet...
And having to configure a file on sd card is not really user friendely :p

Any other idea?

Thanks.

jbudd
Posts: 1641
Joined: Mon Dec 16, 2013 10:23 am

Re: Automating wifi configuration

Thu Oct 27, 2016 1:45 pm

How about this then?

Write a script which runs when the Pi is booted.

It looks for a USB flash drive with a file on it called "wifi.txt"
If the file contains a single line containing an SSID and a password,
and it can see an access point matching the SSID,
then
Either add or edit the relevant stanza in /etc/wpa_supplicant/wpa_supplicant.conf
Delete the file from the USB stick
Reboot.
fi

hertohe
Posts: 6
Joined: Wed Oct 26, 2016 6:57 am

Re: Automating wifi configuration

Thu Oct 27, 2016 9:02 pm

Yep, that's not a bad idea indeed!

Is there a way to connect pi to another windows/mac computer and to modify files inside it? It's pi zero..

Kind regards,

Henry

mitchind
Posts: 40
Joined: Sat Jul 02, 2016 1:11 am

Re: Automating wifi configuration

Fri Oct 28, 2016 4:45 pm

hertohe wrote: Is there a way to connect pi to another windows/mac computer and to modify files inside it? It's pi zero..
Not sure why you'd need this to be done? You didn't want that as a requirement before (using SSH).

You can setup the the SD image before handing over the Pi - make sure it has a uDev rule that mounts a USB drive
automatically, looks for a specific config file, loads the SSID/pwd combination, restarts wifi, and dismounts the USB drive

I've written up a process something similar that describes the uDev rule and running a script to load config file.
You could modify it for WiFi setup
edit: it's on the CodeReview site at stackoverflow
http://codereview.stackexchange.com/que ... tomounting

bludin
Posts: 6
Joined: Thu May 12, 2016 9:34 pm

Re: Automating wifi configuration

Tue Aug 28, 2018 10:48 am

Your original idea is exactly what I'm looking for. Have you worked out a way to implement it in the meantime?
TIA, Beat

macgyverapi
Posts: 2
Joined: Sun Feb 17, 2019 3:22 pm

Re: Automating wifi configuration

Sun Feb 17, 2019 3:25 pm

Also Note: Raspberry Pi Zero WH does not support 5G wireless networks, so if you try that it just won't work.

Full tutorial of setting this up is here: https://www.youtube.com/watch?v=3VO4vGlQ1pg

Return to “Troubleshooting”