Raspberry LTE guide (WIP)
Create a hotspot with wifi->wifi with fallback to LTE
For my usecase I wanted to create a hotspot for all my IOT devices, have "VaneyVanson" available from everywhere to my phone and wanted to use my home network when I parked outside my home.
Pre-requirements
install
hat
other stuff
Setup Wifi to Wifi hotspot
I didn't want to add a Wifi dongle to my setup and wanted the integrated wifi module on the raspberry to both act as a client and as an Access point, this complicates things but is duable.
1.
sudo apt-get update
sudo apt-get upgrade
2. Edit /etc/dhcpcd.conf
sudo nano /etc/dhcpcd.conf
Insert the below into the bottom of the file:
interface uap0
static ip_address=192.168.70.1/24
nohook wpa_supplicant
3. Backup /etc/dnsmasq.conf
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
4. Create a new /etc/dnsmasq.conf
sudo nano /etc/dnsmasq.conf
interface=lo,uap0 #Use interfaces lo and uap0
bind-interfaces #Bind to the interfaces
server=8.8.8.8 #Forward DNS requests to Google DNS
domain-needed #Don't forward short names
bogus-priv #Never forward addresses in the non-routed address spaces
# Assign IP addresses between 192.168.70.50 and 192.168.70.150 with a 12-hour lease time
dhcp-range=192.168.70.2,192.168.70.150,12h
4. Create file /etc/hostapd/hostapd.conf and add the following
change the channel to your current channel, you can see the current channel with:
# Set the channel (frequency) of the host access point
channel=1
# Set the SSID broadcast by your access point (replace with your own, of course)
ssid=yourSSIDhere
# This sets the passphrase for your access point (again, use your own)
wpa_passphrase=passwordBetween8and64charactersLong
# This is the name of the WiFi interface we configured above
interface=uap0
# Use the 2.4GHz band (I think you can use in ag mode to get the 5GHz band as well, but I have not tested this yet)
hw_mode=g
# 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
wpa_pairwise=TKIP
rsn_pairwise=CCMP
driver=nl80211
# I commented out the lines below in my implementation, but I kept them here for reference.
# Enable WMM
#wmm_enabled=1
# Enable 40MHz channels with 20ns guard interval
#ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
5. Edit file /etc/default/hostapd and add the following over the #DAEMON_CONF line:
DAEMON_CONF="/etc/hostapd/hostapd.conf"
6. Create a startup script
#!/bin/bash
# Redundant stops to make sure services are not running
echo "Stopping network services (if running)..."
systemctl stop hostapd.service
systemctl stop dnsmasq.service
systemctl stop dhcpcd.service
#Make sure no uap0 interface exists (this generates an error; we could probably use an if statement to check if it exists first)
echo "Removing uap0 interface..."
iw dev uap0 del
#Add uap0 interface (this is dependent on the wireless interface being called wlan0, which it may not be in Stretch)
echo "Adding uap0 interface..."
iw dev wlan0 interface add uap0 type __ap
#Modify iptables (these can probably be saved using iptables-persistent if desired)
echo "IPV4 forwarding: setting..."
sysctl net.ipv4.ip_forward=1
echo "Editing IP tables..."
iptables -t nat -A POSTROUTING -s 192.168.70.0/24 ! -d 192.168.70.0/24 -j MASQUERADE
# Bring up uap0 interface. Commented out line may be a possible alternative to using dhcpcd.conf to set up the IP address.
#ifconfig uap0 192.168.70.1 netmask 255.255.255.0 broadcast 192.168.70.255
ifconfig uap0 up
# Start hostapd. 10-second sleep avoids some race condition, apparently. It may not need to be that long. (?)
echo "Starting hostapd service..."
systemctl start hostapd.service
sleep 10
#Start dhcpcd. Again, a 5-second sleep
echo "Starting dhcpcd service..."
systemctl start dhcpcd.service
sleep 5
echo "Starting dnsmasq service..."
systemctl start dnsmasq.service
echo "wifistart DONE"
7. Edit rc.local system script
Add the following to your /etc/rc.local script above the exit 0 line (note the spacing between "/bin/bash" and "/usr/local/bin/wifistart"):
/bin/bash /usr/local/bin/wifistart
8. Disable the network services:
(you'll lose internet doing this part so best do it locally)
sudo systemctl stop hostapd
sudo systemctl stop dnsmasq
sudo systemctl stop dhcpcd
sudo systemctl disable hostapd
sudo systemctl disable dnsmasq
sudo systemctl disable dhcpcd
9. Reboot and enjoy
sudo reboot
Setup LTE Hat with qmi
Prepare LTE HAT
If you're using Raspbian Bullseye
disable modemmanager
3. Create a startup script
#!/bin/bash
#make sure module is ready
qmicli -p -d /dev/cdc-wdm0 --dms-set-operating-mode='online'
#configure interface for raw ip protocol
ip link set wwan0 down
echo 'Y' | tee /sys/class/net/wwan0/qmi/raw_ip
ip link set wwan0 up
#connect
qmicli -p -d /dev/cdc-wdm0 --wds-start-network="apn='internet',ip-type=4" --client-no-release-cid
#configure ip address and route
udhcpc -q -f -n -i wwan0
ip li set mtu 1400 dev wwan0
ifmetric wlan0 300
ifmetric wwan0 500
4. Edit rc.local system script
Add the following to your /etc/rc.local script above the exit 0 line (note the spacing between "/bin/bash" and "/usr/local/bin/qmi_reconnect.sh"):
/bin/bash /usr/local/bin/qmi_reconnect.sh
Troubleshooting
Access point trouble shooting
-
-
-
LTE HAT troubleshooting
-
-
-
Credits
-https://forums.raspberrypi.com/viewtopic.php?t=211542 inspiration for access point setup