Waveshare SIM7600G-H 4G HAT Modem for Raspberry Pi Setup
This tutorial will walk you through setup of Waveshare's SIM7600G-H 4G HAT for Raspberry Pi. In addition to setup, I'll give you a script for crontab to connect automatically at startup. You can actually just run this script and it will connect the modem for you (you don't have to run through these steps to do it manually); however, if you run into errors, I recommend you go through this tutorial from the beginning to help troubleshoot. Skip to Step 4 for the script.
Special thanks to mkrzysztofowicz's post on the Raspberry Pi Forums. As I was crawling the internet for help on setting this modem up, I found many others that were just as lost as me. I still don't see a tutorial for this anywhere, so hopefully this helps you.
Step 1: Update and Install
a. Login to your root account.
b. Update and install packages:
apt install libqmi-utils udhcpc
Step 2: Configure Modem
a. Install your SIM card.
b. Connect the modem to the Raspberry Pi via micro USB cable.
c. Set modem online:
qmicli -d /dev/cdc-wdm0 --dms-set-operating-mode='online'
d. Check the name of your wan interface (probably wwan0):
e. Set your wan interface (I'm going to call it wwan0) down:
ip link set wwan0 down
f. Ensure raw ip mode is enabled:
echo 'Y' | sudo tee /sys/class/net/wwan0/qmi/raw_ip
g. Set wan interface back up:
ip link set wwan0 up
Step 3: Connect
a. Start network:
qmicli -p -d /dev/cdc-wdm0 --device-open-net='net-raw-ip|net-no-qos-header' --wds-start-network="apn='internet',ip-type=4" --client-no-release-cid
b. Get an IP assignment:
sudo udhcpc -i wwan0
c. Test your connection :
Step 4: Setup Connection at Startup
a. Install script:
Paste the following script in the file:
#!/bin/sh killall ModemManager echo "killed ModemManager" echo "trying udhcpc" udhcpc -i wwan0 interface=$(ip a|grep wwan) # The wwan0 interface will display "UNKNOWN" instead of "DOWN" if it is up if [[ $interface == *"UNKNOWN"* ]]; then : else killall ModemManager echo "setting operating mode online" qmicli -d /dev/cdc-wdm0 --dms-set-operating-mode='online' ip link set wwan0 down echo "wwan0 down" echo 'Y' | sudo tee /sys/class/net/wwan0/qmi/raw_ip ip link set wwan0 up echo "wwan0 up" echo "wds starting network" # Update apn if necessary qmicli -p -d /dev/cdc-wdm0 --device-open-net='net-raw-ip|net-no-qos-header' --wds-start-network="apn='internet',ip-type=4" --client-no-release-cid udhcpc -i wwan0 fi
Save and exit.
b. Enable executable permissions:
chmod 755 /bin/modemstart
c. Update crontab:
Paste the following in the file:
Save and exit.
Step 5: DONE!
I hope this tutorial helped! Let me know if I missed anything or you run into issues.