0

I want to use the Raspberry Pi Zero W as an embedded controller for a device that a third party could use by configuring WiFi connection via USB or hot spot, like you would configure a wireless printer. I've been unable to find any way to do this. I've been able to use USB to SSH into the R Pi. Linux commands can then be used to search WiFi seen on wlan0, but I haven't found a way to use Linux to then configure for a selected WiFi. The python wifi module also searches WiFi but does not successfully configure the R Pi, and is no longer supported. raspi-config doesn't seem to work, and is anyway too complex for the users I have in mind. I'd appreciate any help.

Update with additional information from a comment:
I want to use the Raspberry Pi to send video over a WIFi router. The Raspberry Pi is completely enclosed. I cannot attach a keyboard or monitor. I do not know which WiFi network I will want to connect to until I have physically moved it to the desired location. Then I have to search for the new WiFi and log in with its password, all without connecting a keyboard or monitor, only using either USB or hot spot. This would be similar to connecting a wireless printer to a WiFi network using a USB connection.

Ingo
  • 42,107
  • 20
  • 85
  • 197
fperkins
  • 29
  • 1
  • 4
  • I do not understand your question. If there is a hot spot running on the RasPi you just connect to it. Why is there a need to configure it (again)? – Ingo May 14 '19 at 22:24
  • Thanks Ingo. I want to use the Raspberry Pi to send video over a WIFi router. The Raspberry Pi is completely enclosed. I cannot attach a keyboard or monitor. I do not know which WiFi network I will want to connect to until I have physically moved it to the desired location. Then I have to search for the new WiFi and log in with its password, all without connecting a keyboard or monitor, only using either USB or hot spot. This would be similar to connecting a wireless printer to a WuFi network using a USB connection. Is that clearer? – fperkins May 16 '19 at 01:24

3 Answers3

1

Question Update with additional information from a comment: I want to use the Raspberry Pi to send video over a WIFi router.

Answer

1) Search your network

sudo iw dev wlan0 scan ssid [UNKNOWN FILTER] ?...
sudo iw dev wlan0 scan ssid AccessPointSSID ?...

... this only check the presence of the access point ...

2) Auth with A.P (specify your network name and password,certs if needed etc...) Example for WPA2 with PSK :

wpa_passphrase AccessPointSSID > wpa_supplicant.conf
wpa_supplicant -C wpa_supplicant.conf... (man wpa_supplicant) 

3) Get an ip address (man dhcpcd)

dhcpcd... 

* Here I recommand you to check your NETWORK ROUTING:*

ip r

* check your dns*

cat /etc/resolv.conf or nslookup
  • Now you are connected with the Access Point -

Here you can try:

ping XX.XX.XX.XX 

for see if you have Access Point response (but It is not guaranted, depend on firewall rules etc...)

4) Send your movie from your raspberry to a computer , now on the same network as yours... (real play stream ? just store a file ?) on your remote target you must have an FTP, HTTP, SSH or other server having files transfert capabilities, then for stroring a file :

echo -e "HTTP HEADER AND HTTP BODY\n" | nc ...
or FTP command ftp open ...
or using SSH (BEST for security) :
scp -P 22 /home/pi/mymovie.mp4 remote@ipv4:/tmp/mymovie

[RPI ZERO] --- 802.11 ---> [AP] <---> [REMOTE]    
SSH client                            SSH Server

Now with all this informations you can write a shell script doing the job as you want as an system unit file for start-up job (man systemctl). In any case you must know in advance the name of the network (SSID) or its MAC address (BSSID) and of course the access password. If both of these information are correctly specified in the wpa_supplicant configuration file, this should work for Wi-Fi authentication, for the IP address it is the DHCP server of the access point that will give you the ip address (you can use : ip a).

Otherwise, if you want your RPI zero to be same as Wi-Fi "Network Printer", you must create an AccessPoint with the SoftAP feature of wlan0 on your RPI. Your RPI also becomes the SSH server, just invert my little schema and specify if you want your RPI as server or client.

Ephemeral
  • 2,157
  • 1
  • 6
  • 19
0

The problem is that you do not know the WiFi that the RasPi should later connect to so you cannot pre configure it. On location you want to connect to the RasPi and configure its WiFi. Of course this cannot be done with WiFi so you have to use an independent connection. On the Raspberry Pi Zero W you can use a pre configured access point or the OTG Gadget mode which emulates an USB connection as network interface. Or in general you should be able to use a pre configured WiFi-Direct connection but I haven't tested it so far.

I would not use a pre configured access point because it is changed to a client connection and you have only one attempt. You are lost on a failed configuration, maybe a simple typo in ssid or password. You can try to use an access point together with a client connection as described in Access point as WiFi repeater, optional with bridge. But as noted in section Details - general there are complex conditions to use it so it's not an easy task to make it failsave if a normal user reconfigure it with a "simple" tool. So I will focus on the Gadget mode.

How to connect to the RasPi using Gadget mode is a well known task and should be doable by a normal user. Now it is up to you to present him a simple non graphical setup tool. I don't understand why raspi-config should not work. If it's too complex for the user you may consider to strip it down to just the needed options. /usr/bin/raspi-config is a bash script and with some scripting skills it should be possible. Otherwise it's a programming job, preferable with python3. If there are problems belonging to Raspberry Pi you should make a new specific question.

Ingo
  • 42,107
  • 20
  • 85
  • 197
0

Thanks Ingo and Ephemeral.

First connect to Raspberry Pi Zero W SSH which you can do via USB.

Then 'sudo iwlist wlan0 scan' returns a list of WiFi information that can be parsed for the SSIDs.

Next rewrite wpa_supplicant.conf with the desired SSID and password.

Next 'sudo systemctl daemon-reload'.

Next 'sudo systemctl restart dhcpcd'.

Raspberry Pi will now be connected to the desired WiFi without a reboot over a USB connection.

Programming GUI's using tkinter. Need to address Gadget Mode. If I can find a programmable way to control Hot Spot I might be able to free up wlan0 for WiFi scan and continued user access. Gadget mode might get me where I want to be.

fperkins
  • 29
  • 1
  • 4