mdsh.com/wiki


RecentChanges

TextFormattingRules
AllWikiTopics
OrphanedWikiTopics
ToDoWikiTopics
WikiLockList
RSS
Export2HTML

WikiSearch

SetUsername

StartingPoints
Home
MF627 @May 16, 2013 9:24:15 PM

3G USB dongle


Packages we will require:
  • eject - for converting the device from a CD-ROM into a modem
  • ppp - for pppd and chat applications
  • gammu and gammu-smsd - for receiving SMS text messages and running commands
  • postfix - for sending email messages
sudo apt-get update
sudo apt-get install -y eject ppp gammu gammu-smsd postfix


Configure postfix as an Internet mail server.

Convert from CD-ROM to modem


The '3' 3G USB dongle I'm connecting to my Raspberry Pi is a ZTE MF627. It has two modes, when it's originally plugged in it appears as a USB CD-ROM, for automatically installing software drivers, and has to be ejected before it turns into a network device. When the device is a CD-ROM it's ID is 19d2:2000, when it's a network device the ID is 19d2:0031.

Run from udev

Here's an easy way to eject the CD-ROM device to turn the dongle into a network device:

Create:
/etc/udev/rules.d/ZTE_MF627.rules
with this contents:
SYSFS{idVendor}=="19d2", SYSFS{idProduct}=="2000", RUN+="/usr/bin/eject %k", OPTIONS+="last_rule"

Now when the dongle is inserted the udev daemon spots the device and sends the eject command. You can check the device ID with lsusb.

We can test the device now with chat:

chat -s -v ATZ OK AT+CSQ OK >/dev/ttyUSB2 </dev/ttyUSB2

in the output you'll see the current signal strength.

Run pppd


First we'll create a pppd config file and it's associated modem chat file.

Create:
/etc/ppp/peers/giffgaff
with this contents:
/dev/ttyUSB2
460800
user giffgaff
password password

defaultroute
connect "/usr/sbin/chat -v -f /etc/ppp/peers/giffgaff.chat"
ipparam giffgaff
hide-password
lock
maxfail 0
mtu 1492
noauth
noipdefault
persist
usepeerdns


Create:
/etc/ppp/peers/giffgaff.chat
with this contents:
ABORT BUSY ABORT 'NO CARRIER'
ABORT VOICE ABORT 'NO DIALTONE'
ABORT 'NO DIAL TONE' ABORT 'NO ANSWER'
ABORT DELAYED
ATZ
OK ATQ0V1E1S0=0&C1&D2+FCLASS=0
OK AT+CGDCONT=1,"ip","giffgaff.com"
OK-AT-OK ATDT*99***1#
CONNECT \d\c


Create:
/etc/ppp/ip-up.d/default_route
with this contents:
#!/bin/sh -e
# Called when a new interface comes up

/sbin/route del default

and test with
pon giffgaff

Run from udev


Create:
/usr/local/bin/ZTE_MF627
with this contents:
#!/bin/sh -e

logger "$0" "$ACTION"

case $ACTION in
add )
sleep 2
service gammu-smsd stop
sleep 2
pon giffgaff
sleep 10
service gammu-smsd start
;;
remove )
service gammu-smsd stop
poff giffgaff
;;
esac


KERNEL=="ttyUSB0", SUBSYSTEM=="tty", ATTRS{idVendor}=="19d2", ATTRS{idProduct}=="0031", RUN+="/usr/local/bin/ZTE_MF627", OPTIONS+="last_rule"

VeryQuickWiki Version 2.8.1 | Admin

All contents copyright mdsh.com (C) 2011-2023.