Setup Serial 4G Modem - hydrogeologger/pyduino GitHub Wiki
Setting up 4G Serial Modem (i.e. SIM7600X) via PPP
1. Dependencies
Install ppp
sudo apt install ppp
2. PPP Configuration
2A. Copy existing provider settings for ppp
cd ~/pyduino/sim7600/ppp/peers
sudo cp optusconnect /etc/ppp/peers/optusconnect
2B. Manual setup of ppp provider example
Copy an example provider file and naming it optusconnect for editing (Optional: switch to root permission sudo su
)
sudo su
cd /etc/ppp/peers
cp provider optusconnect
Open optusconnect provider file for editing, use any prefered editor, i.e. nano instead of vim
sudo vim /etc/ppp/peers/optusconnect
Edit the following details
Replace ********
with APN of provider i.e. connect
for Optus
connect "/usr/sbin/chat -v -f /etc/chatscripts/pap -T ********"
to
connect "/usr/sbin/chat -v -f /etc/chatscripts/gprs -T connect"
Replace /dev/modem
with serial port modem is connected to. Most likely /dev/ttyS0
Append the following to the file
# Accept new IP addresses from IPCP negotiations (default)
ipcp-accept-local
ipcp-accept-remote
# Do not ask the remote to authenticate.
noauth
# No hardware flow control on the serial link with GSM modem
nocrtscts
# No modem control lines with GSM modem
local
3. Testing the connection
Start connection
sudo pon optusconnect
To turn device serial connection off
sudo poff optusconnect
Can check syslog if connection was successfull tail -n 30 /var/log/syslog
Or check if the modem interface ppp0
appears in ifconfig
Now add the modem as a default route and try to ping a public IP or address (e.g. Google DNS)
NOTE: If connected via wifi, route add
may terminate ssh connection as all traffic will be routed via 4G
Routes all traffic via ppp0 network interface
# Test connection via ppp0 interface
ping -I ppp0 8.8.8.8
ping -I ppp0 www.google.com
traceroute -i ppp0 www.google.com
# Only use following if ssh connection is not over wifi
sudo route add default dev ppp0
or
sudo route add -net 0.0.0.0 ppp0
ping 8.8.8.8
ping www.google.com
traceroute www.google.com
To remove
sudo route del default dev ppp0
Note: Routing information does not persist on reboot, continue reading to set it up
4. Setup automatic connection and network routing on boot
Note: If connection is turned off manually during session, need to reboot or follow previous "testing the connection" to set up routing info for current session
- Need to edit
/etc/network/interfaces
file
sudo vim /etc/network/interfaces
- Include the following before the line
source-directory /etc/network/interfaces.d
# Load ppp0 optusconnect as an interface
auto optusconnect
iface optusconnect inet ppp
provider optusconnect
Example:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Load ppp0 optusconnect as an interface
auto optusconnect
iface optusconnect inet ppp
provider optusconnect
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
5. Configuring modem to power on boot
PWR Modes by jumper settings
Modes | Description |
---|---|
3v3 | Device power up on connection to power (No configuration needed) |
D6 | Control device using rpi GPIO (BCM-GPIO6, WPI-GPIO22) |
No Jumper | Manual powering of device using PWRKEY button |
ONLY PERFORM THE FOLLOWING if PWRKEY is shorted on device between PWR and D6 by jumper setting
Need to edit /etc/rc.local
to trigger the power key
sudo vim /etc/rc.local
Add the following before the line Exit 0
5A. Using python
&
at end of line is to fork the python process to allow boot sequence to continue, or else boot will hold until python script finish executing
- Without Logging
# Initialize SIM7600 on BCM-GPIO6, WPI-GPIO22
python /home/pi/sim7600.py &
- With logging, initializes a second bash process to execute script
# Initialize SIM7600 on BCM-GPIO6, WPI-GPIO22
sudo bash -c "python /home/pi/sim7600.py > /home/pi/sim7600.log 2>&1" &
5B. Using shell
Toggle rpi GPIO to send "power on" signal via PWR breakout pin, module remains on if already on
#TODO: Needs testing for validation
# Initialize module, BCM-GPIO6, wPI-gpio22
printf "Initialize SIM7600 Module"
if [ ! -e /sys/class/gpio/gpio6 ]; then
sudo echo "6" > /sys/class/gpio/export
fi
sudo echo "out" > /sys/class/gpio/gpio6/direction
sleep 0.1
sudo echo "1" > /sys/class/gpio/gpio6/value
sleep 0.5 # Min time of 0.1sec and less than 2.5sec
sudo echo "0" > /sys/class/gpio/gpio6/value
sleep 0.1
sudo echo "6" > /sys/class/gpio/unexport
SIM7600 Python Utility Script Content
Located in ~/pyduino/sim7600
folder
Default operation on launch of python script sim7600.py
is to power on the module via GPIO
To power on module, uses gpio to toggle pwrkey
python sim7600.py
Reboot, uses AT commands to reboot modem
python sim7600.py reboot
Check status of module, uses AT command
python sim7600.py status
Opens a serial session to be able to send custom AT commands to 4G module
python sim7600.py serial
To power off module, uses gpio to toggle pwrkey
NOTE will actually toggle power, so if module is off will turn on module, DO NOT USE if device connection is soley over 4G network
python sim7600.py off