Sunday, 17 May 2020

Using a Raspberry Pi as an Access Point

Most of the simple solutions I found for using a Raspberry Pi to act as an Access Point used NAT and hosted a DHCP server for the WiFi clients.
But.. What if you want to bridge the ethernet and wifi interfaces and let your existing router handle DHCP and routing?

Well here's my solution taken from a few sources.

Update stuff.
sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get dist-upgrade && sudo reboot now

Set the wifi locale
sudo raspi-config

Install hostapd for the access point
sudo apt-get install hostapd bridge-utils
sudo systemctl stop hostapd

Create a config file for the access point
#sudo nano /etc/hostapd/hostapd.conf
interface=wlan0
bridge=br0
driver=nl80211
ssid=ras
hw_mode=g
channel=1
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=changeme
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

Have a test
sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf

Tell hostapd which config file to user
#sudo nano /etc/default/hostapd
DAEMON_CONF="/etc/hostapd/hostapd.conf"

Enable the service
sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl start hostapd

Stop dhcp from allocating eth0 and wlan0 IP addresses
#sudo nano /etc/dhcpcd.conf
denyinterfaces eth0 wlan0

Add the bridge between the interfaces and let it have a dhcp address
#sudo nano /etc/network/interfaces
auto br0
iface br0 inet dhcp
bridge_ports eth0 wlan0

Add a bridge
sudo brctl addbr br0

Reboot -
sudo reboot

You should have br0 on dhcp now

Extras

Add these lines to the /boot/config.txt to disable the onboard hardware
dtoverlay=disable-wifi
dtoverlay=disable-bt


Refs
https://github.com/billz/raspap-webgui/blob/master/includes/hostapd.php
https://www.raspberrypi.org/forums/viewtopic.php?t=193770 http://www.d3noob.org/2018/12/raspberry-pi-setup-as-bridged-wifi.html?m=1 https://davidtavarez.github.io/2018/re4son_kernel_raspberry_pi/
https://elinux.org/RPI-Wireless-Hotspot
https://github.com/raspberrypi/linux/issues/2619
https://github.com/igorpecovnik/hostapd/issues/1
https://github.com/gnab/rtl8812au/issues/6
https://github.com/aircrack-ng/rtl8812au/issues/408

5G config

ssid=raspi
wpa_passphrase=changeme

bridge=br0
country_code=US

interface=wlan0
driver=nl80211

wpa=2
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP

macaddr_acl=0

logger_syslog=0
logger_syslog_level=4
logger_stdout=-1
logger_stdout_level=0

hw_mode=a
wmm_enabled=1

# N
ieee80211n=1
require_ht=1
ht_capab=[MAX-AMSDU-3839][HT40+][SHORT-GI-20][SHORT-GI-40][DSSS_CCK-40]

# AC
ieee80211ac=1
require_vht=1
ieee80211d=0
ieee80211h=0
vht_capab=[MAX-AMSDU-3839][SHORT-GI-80]
vht_oper_chwidth=1
channel=36
vht_oper_centr_freq_seg0_idx=42


Thursday, 13 February 2020

CNCjs on a Raspberry Pi 3A+

Having read and tried to follow the official CNCjs help file on installing, this was the short version that worked for me.


Headless boot

1, Add a linux format file to the boot partition of the ssd ( using lf not crlf) containing

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

network={
    ssid="«your_SSID»"
    psk="«your_PSK»"
    key_mgmt=WPA-PSK
}

2, Add an empty 'ssh' file to the boot partition to enable ssh

Install the SD card and power on. (wait quite a while the first time)

Installing node and CNCjs

1, Do a
sudo raspi-config 
and disable console on serial but enable hardware serial

2, Run the following

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
nvm install 10
nvm use 10
npm install -g cncjs


Also
https://learn.watterott.com/hats/rpi-uno-hat/arduino/
https://cnc.js.org/docs/rpi-setup-guide/
https://learn.adafruit.com/program-an-avr-or-arduino-using-raspberry-pi-gpio-pins/programming

Gotchas
PM2 didn't work, used crontab
didn't need sudo for npm commands

To flash GRBL
Follow the install instructions on watterott.com to get avrdude installed then
wget <latest grbl hex file>
sudo avrdude -p atmega328p -P /dev/ttyS0 -c arduino -v -U flash:w:<latest grbl hex file>:i


Extras
Set GPIO on while the PI is running
Edit /boot/config.txt
Add 
dtoverlay=gpio-poweroff,gpiopin=26,active_low

After 4 secs or so the IO pulls low and when the PI is shudown, goes off