Saturday, 1 February 2020

Raspberry Pi Ad-Hoc wireless configuration

If you want to use the Raspberry Pi wirelessly without having an access point, you have to configure the Pi as its own Access Point. This is how I did it with links to information at the end.

------------
Will your Wireless dongle work in this mode? Luckily the R-pi Zero W does, but my Aqprox dongles don't.  This tells you how to find out, and also how to configure it. https://wiki.archlinux.org/index.php/software_access_point

------------
Most dongles will  work directly with the R-Pi, but my Zyxel one doesn't any more under Raspbian Buster.   It was necessary to  sudo apt-get install firmware-zd1211.

2022-08-28 New R-Pi OS. Cannot find this package.

------------
 Initial Wireless configuration [under Buster] to connect to my home network

in /etc/ the file dhcpcd.conf:  my changes are in italics

# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.

# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel

# Inform the DHCP server of our hostname for DDNS.
raspberry_pi

# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
#duid

# Persist interface configuration when dhcpcd exits.
persistent

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate Stable Private IPv6 Addresses instead of hardware based ones
# slaac private

# Example static IP configuration:
interface eth0
static ip_address=192.168.1.9/27
static routers=192.168.1.1
static domain_name_servers=192.168.011 8.8.8.8

interface wlan0
static ip_address=192.168.1.8/27
static routers=192.168.1.1
static domain_name_servers=192.168.1.1  8.8.8.8

# It is possible to fall back to a static IP if DHCP fails:
# define static profile
#profile static_eth0
#static ip_address=192.168.1.23/24
#static routers=192.168.1.1
#static domain_name_servers=192.168.1.1

# fallback to static profile on eth0
#interface eth0
#fallback static_eth0

-- -- --
in /etc/wpa_supplicant/wpa_supplicant.conf

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

network={
ssid="bmth-upstairs"
psk="password"
# proto=RSN
key_mgmt=WPA-PSK
# pairwise=TKIP
# auth_alg=OPEN
}


---------- 
Preparing for Ad-hoc operation  (taken from Robot-7-flask.doc page 5)
[connect via Ethernet or Wifi]
programs to load: Hostapd, dnsmasq

sudo apt-get install dnsmasq hostapd    

stopped dnsmasq and hostapd, and rebooted. 


sudo systemctl stop dnsmasq
sudo systemctl stop hostapd

Edit dhcpcd.conf as described in the link above to assign a newIP address for the AP. 
This bit then looks like:


interface wlan0
    static ip_address=192.168.4.1/24
    nohook wpa_supplicant

Wpa_supplicant.conf now looks like this:

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

network={
ssid="rc-car"
psk="Ashmeads"
key_mgmt=WPA-PSK
}



restart the dhcpcd daemon.

edit the dnsmasq file to set the dhcp ranges. 

Continue following the instructions in the link to set up other parameters. 

My file /etc/hostapd/hostapd.conf  looks like this:

interface=wlan0
driver=nl80211
ssid=rc-car
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=Ashmeads
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP


----------  
Use Wifi analyser and fing on a tablet to see if the SSID Rc-car is present. 

---------- 

This is a part that was omitted from the Raspberry Pi documentation :
We still have to show the system the location of the configuration file:
sudo nano /etc/default/hostapd
In this file, track down the line that says #DAEMON_CONF=”” – delete that # and put the path to our config file in the quotes, so that it looks like this:

DAEMON_CONF="/etc/hostapd/hostapd.conf"
I got this from  https://thepi.io/how-to-use-your-raspberry-pi-as-a-wireless-access-point/
And don't forget to edit rc.local to change the IP address used by Flask.
LINKS

https://wiki.archlinux.org/index.php/software_access_point

To set up  Access Point:





No comments: