User Tools

Site Tools


linux:modem3g

This is an old revision of the document!


Connect with a 3G modem with command line

I have a modem Huawei E1752Cu HSPA. What I want to do is the following: 1) send and receive an SMS using the modem and 2) establish a broadband connection using the modem.

Because I don't have a concrete idea of what to do next, I am exploring both sides: 1) using sms to communicate with the raspberry and 2) using mobile broadband to communicate with the raspberry. The fares of having a mobile connected all the time (plain fare are about 15 euros/month) and in the case of the sms you only pay the sms you send, so in some cases is advisable using only sms.

Setup modem

Install modem-manager:

# sudo apt-get install modemmanager

it will detect the modem, do necessary loading of modules and things like that. It is advisable to use it as a service, so when plugin the modem it will be authomatically configured.

I reommend to run it the –debug option enabled in order to see what is happening behind the scenes:

root@raspberrypi:/home/pi# modem-manager  --debug 
modem-manager[16723]: <info>  [1359305305.945270] [main.c:167] main(): ModemManager (version 0.5.2.0) starting...
modem-manager[16723]: <info>  [1359305305.993128] [mm-manager.c:120] load_plugin(): Loaded plugin Option
modem-manager[16723]: <info>  [1359305306.002902] [mm-manager.c:120] load_plugin(): Loaded plugin ZTE
modem-manager[16723]: <info>  [1359305306.013057] [mm-manager.c:120] load_plugin(): Loaded plugin Huawei
modem-manager[16723]: <info>  [1359305306.020689] [mm-manager.c:120] load_plugin(): Loaded plugin X22X
modem-manager[16723]: <info>  [1359305306.028594] [mm-manager.c:120] load_plugin(): Loaded plugin Gobi
modem-manager[16723]: <info>  [1359305306.036247] [mm-manager.c:120] load_plugin(): Loaded plugin Nokia
modem-manager[16723]: <info>  [1359305306.046679] [mm-manager.c:120] load_plugin(): Loaded plugin Samsung
modem-manager[16723]: <info>  [1359305306.054036] [mm-manager.c:120] load_plugin(): Loaded plugin Linktop
modem-manager[16723]: <info>  [1359305306.064143] [mm-manager.c:120] load_plugin(): Loaded plugin Ericsson MBM
modem-manager[16723]: <info>  [1359305306.072771] [mm-manager.c:120] load_plugin(): Loaded plugin Wavecom
modem-manager[16723]: <info>  [1359305306.081609] [mm-manager.c:120] load_plugin(): Loaded plugin Novatel
modem-manager[16723]: <info>  [1359305306.091642] [mm-manager.c:120] load_plugin(): Loaded plugin Option High-Speed
modem-manager[16723]: <info>  [1359305306.101939] [mm-manager.c:120] load_plugin(): Loaded plugin Sierra
modem-manager[16723]: <info>  [1359305306.110765] [mm-manager.c:120] load_plugin(): Loaded plugin Generic
modem-manager[16723]: <info>  [1359305306.118949] [mm-manager.c:120] load_plugin(): Loaded plugin SimTech
modem-manager[16723]: <info>  [1359305306.127009] [mm-manager.c:120] load_plugin(): Loaded plugin MotoC
modem-manager[16723]: <info>  [1359305306.134973] [mm-manager.c:120] load_plugin(): Loaded plugin Longcheer
modem-manager[16723]: <info>  [1359305306.142911] [mm-manager.c:120] load_plugin(): Loaded plugin AnyData
modem-manager[16723]: <debug> [1359305306.203809] [mm-manager.c:491] try_supports_port(): (Huawei): (ttyUSB1) deferring support check

Many lines will evidence where is the modem located:

modem-manager[16723]: <debug> [1359305306.394255] [mm-at-serial-port.c:333] debug_log(): (ttyUSB0): --> 'AT+GCAP<CR>'
modem-manager[16723]: <debug> [1359305307.099166] [mm-at-serial-port.c:333] debug_log(): (ttyUSB0): <-- 'AT+GCAP'
modem-manager[16723]: <debug> [1359305307.102651] [mm-at-serial-port.c:333] debug_log(): (ttyUSB0): <-- '<CR><CR><LF>+CME ERROR: SIM PIN required<CR><LF>'

In my case is /dev/ttyUSB0.

Send and receive SMS

My next step is to send and receive a test sms. First, I will install minicom to do the test directly typing the AT commands to the modem.

# sudo apt-get install minicom
# minicom --device /dev/ttyUSB0

It is advisable to check out these pages in order to know the basic AT commands to do the task:

Enter the pin, check pin status, etc

See pin status:

AT+CPIN?
+CPIN: SIM PIN   # it needs pin of the SIM

OK

Enter pin:

AT+CPIN=9999 # put your pin here
OK

Network registration

Check out network registration and register into network if neccesary:

AT+CREG?
+CREG: 0,5   # 5 means connected

Description of the values:

<n>

  • Disable unsolicited status callback.
  • Enable unsolicited status callback, +CREG: <stat>
  • Enable unsolicited status callback, +CREG: <stat>,[,<lac>,<ci>[,<AcT>]]

<stat>

  • Not registered, not searching
  • Registered to home network
  • Not registered, searching for network
  • Registration denied
  • Registered, roaming

You can change the status with the following command:

AT+CREG=1

Send an sms

There are many ways to send an sms. You can send it directly, write first the message into the memory of the modem, etc…

Direct sending

AT+CMGF=1               # say the modem to operate in sms mode
OK
AT+CMGS="669807321"     # send a message directly
> text your message here, and end the message with ^Z (control+z)
AT+CMGF=1               # say the modem to operate in sms mode
AT+CMGW="669807321"
> A simple demo of SMS text messaging.

+CMSS: 1                # the ID of the message in memory

AT+CMSS=1               # send the message with id = 1 

Read a message

To list all the messages in the memory:



Delete a message

To delete a message:

AT+CMGD=2

Lista de operadores moviles

AT+CGDCONT?

Y usamos uno:

AT+CGDCONT=1

Connect to internet

INSTALAMOS PPP Y WDIAL:

# sudo apt-get install wvdial ppp

~~DISQUS~~

linux/modem3g.1369848383.txt.gz · Last modified: 2022/12/02 22:02 (external edit)