RPi3 wireless screen. Configure WiFi as AP

This is tested on Raspbian Stretch Lite.

This is second and last part how to use phone as an raspberry pi 3 screen via RPi3 build in WiFi connection. At first TightVNC server must be installed. Another way is to set up x11vnc which allows to connect to active session.

To use phone display as raspberry pi 3 monitor at first I need to configure build in WiFi to act like Access Point.

These are steps i do:

Move to the root account:
sudo su
Update system:
apt-get update -y && apt-get upgrade -y
Install DNS, DHCP server and Host Access Point Daemon:
apt-get install dnsmasq hostapd -y
Set static address for wlan0 adapter:
sudo nano /etc/dhcpcd.conf
Make sure there is lines such as:
interface wlan0
static ip_address=192.168.1.201/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1
Restart DHCP daemon to make sure dhcpcd.conf is OK:
service dhcpcd restart
Restart WiFi network interface:
ifdown wlan0
ifup wlan0
Install Host Access Point Daemon configuration:
cat > /etc/hostapd/hostapd.conf <<EOF
interface=wlan0
driver=nl80211
ssid=Pi3-AP
hw_mode=g
channel=6
ieee80211n=1
wmm_enabled=1
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_passphrase=raspberry
rsn_pairwise=CCMP
EOF
Here is some explanation:
# This is the name of the WiFi interface we configured above
interface=wlan0

# Use the nl80211 driver with the brcmfmac driver
driver=nl80211

# This is the name of the network
ssid=Pi3-AP

# Use the 2.4GHz band
hw_mode=g

# Use channel 6
channel=6

# Enable 802.11n
ieee80211n=1

# Enable WMM
wmm_enabled=1

# Enable 40MHz channels with 20ns guard interval
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]

# Accept all MAC addresses
macaddr_acl=0

# Use WPA authentication
auth_algs=1

# Require clients to know the network name
ignore_broadcast_ssid=0

# Use WPA2
wpa=2

# Use a pre-shared key
wpa_key_mgmt=WPA-PSK

# The network passphrase
wpa_passphrase=raspberry

# Use AES, instead of TKIP
rsn_pairwise=CCMP
Now it is time to celebrate something. Execute this command:
/usr/sbin/hostapd /etc/hostapd/hostapd.conf
This should output:
Configuration file: /etc/hostapd/hostapd.conf
Failed to create interface mon.wlan0: -95 (Operation not supported)
wlan0: Could not connect to kernel driver
Using interface wlan0 with hwaddr b8:27:eb:69:f2:10 and ssid "Pi3-AP"
random: Only 18/20 bytes of strong random data available from /dev/random
random: Not enough entropy pool available for secure operations
WPA: Not enough entropy in random pool for secure operations - update keys later when the first station connects
wlan0: interface state UNINITIALIZED->ENABLED
wlan0: AP-ENABLED
Take the phone an look if "Pi3-AP" really appears. Do not try to connect.
It is not possible now. Only make sure "Pi3-AP" WiFi network is listed as an option ;)


Hit CTRL+C to brake operation.

Set Host Access Point Daemon to start his job at system startup:
sed -i "s/^.*DAEMON_CONF=.*$/DAEMON_CONF=\"\/etc\/hostapd\/hostapd.conf\"/" /etc/default/hostapd
Install DHCP and DNS server configuration:
cat > /etc/dnsmasq.conf <<EOF
interface=wlan0
listen-address=192.168.1.255
bind-interfaces
server=8.8.8.8
domain-needed
bogus-priv
dhcp-range=192.168.1.50,192.168.1.60,12h
EOF
Enable IPv4 packet forwarding instantly:
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
Enable IPv4 packet forwarding at system startup:
sed -i "s/^.*net\.ipv4\.ip_forward=.*$/net\.ipv4\.ip_forward=1/" /etc/sysctl.conf
Restart wireless network interface, Host Access Point Daemon, DHCP and DNS server:
ifdown wlan0
ifup wlan0
service hostapd restart
service dnsmasq restart
Now take the phone and install VNC Viewer.
Disconnect existing WiFi network and connect to to Pi3-AP.
Use password raspberry.
Open VNC Viewer.

If RPi3 has tightvncserver installed then I use IP address 172.24.1.201:1.
If RPi3 has x11vnc installed then I use IP address 172.24.1.201:0.

No comments: