Table des matières

Modem Huawei E220

picocom /dev/ttyUSB0 -b 115200 -l

Configure the modem

AT^U2DIAG=0

The U2DIAG command is very versatile. It can be used to activate different operating modes of the modem:

AT^U2DIAG=0 – the device is only modem
AT^U2DIAG=1 – device is in modem mode + CD ROM
AT^U2DIAG=255 – the device in modem mode + CD ROM + card reader
AT^U2DIAG=256 – the device in modem mode + card reader

Set the pin code

AT+CPIN=1234

Next, we configure the modem to NOT ask for the SIM PIN any more. Replace xxxx with your PIN! Of course this step needs a SIM card inserted in the modem.

AT+CLCK="SC",0,"xxxx"

You can re-enable the PIN constraint with

AT+CLCK=”SC”,1,”xxxx"

Modes of operation

Now exit picocom, unplug the modem and replug it to let the changes take effect. If you do a “dmesg | grep usb” now, it should not display an additional CD-rom drive.

I encountered frequent disconnects/connects with my modem at first. A little bit of poking around and (luckily) looking at the modem at the exact moment it got disconnected brought the solution: whenever the modem changes the network type, that is going from GPRS to UMTS (3G) and vice versa, it did disconnect (and that was visible by the LED changing its color). As I only wanted to send and receive text messages I decided to configure the modem to use GPRS only. I do not need UMTS (3G) functionality with that modem ever. So lets get this done.

Connect to the modem with picocom (as above) and type:

AT^SYSCFG?

You should get something like

AT^SYSCFG=2,2,3FFFFFFF,2,4

There are 4 modes that can be selected for operation:

All we need to do is activate the mode we need: “Only GPRS/EGDE” in this case. In picocom type:

AT^SYSCFG=13,1,3FFFFFFF,2,4

Pay attention that there are no spaces after the commas and type in the correct number of “F”s.

AT^SYSCFG Huawei command reference

To see the supported values, you can query your own modem sending the AT^SYSCFG=? command.

AT^SYSCFG=$mode,$acqOrder,$band,$roam,$srvDomain

$mode

$acqOrder

$band

$roam

$srvDomain

Sending and receiving SMS

I did quite a lot of research on this and found numerous valuable resources online. One of the most complete frameworks for controlling a phone/modem from Unix/Linux is Gammu. It seems a little complicated at first, but once one has read most of the excellent documentation things get clear. Again, I wanted to do things by myself to get e deeper understanding of things, so I did not use Gammu. Another great source of information is the SMS Tutorial at developershome.com.

Let’s have a look at the basics by interfacing with the modem directly with picocom. Modems support two types of SMS handling: text mode and PDU mode. Text mode is easier and I will use it throughout this post. In PDU-mode the SMS is binary encoded which adds some complexity. Again, I wanted a “proof of concept” and decided to go with textmode.

One word about AT-commands before we begin:

The command for SMS mode is “CMGF”:

So set the modem to text mode first. It should respond with “OK”. Next we use the command “CMGL” to read all messages. This command takes one parameter that is used to configure if we want to get all messages, only new messages etc. Here is a list:

So to read all messages from the card you would type

AT+CMGL="ALL"

and get an output like this:

+CMGL: 0,"REC READ","+4911234567890",,"13/07/11,19:03:45+08"
this is message number one
+CMGL: 1,"REC READ","+4911234567890",,"13/07/11,19:48:31+08"
Second message, 45 minutes later

OK

The format of this output is straightforward. The command (CMGL) is repeated, followed by the index of the SMS. Then follows the status and the phone number from the sender and a timestamp. The following lines (until the next line starts with +CMGL) are the message.

Messages can be deleted using the “CMGD” command. It takes the index and an (optional) flag as parameters:

AT+CMGD=index[,flag]

The flag value can be one of the following:

Lastly, we are going to send an SMS. This is done with the command “CMGS”. The syntax is:

AT+CMGS="phonenumber"<CR>the message to send<Ctrl+z>

If you are doing this in picocom you need to press the return-key after the number, type the message and finalize it by pressing CTRL+z. If you encounter the message “+CMS ERROR: 330” the message center service number is not set. You can check the configured service center number with the command “AT+CSCA?”. It should return something like +CSCA: “xxxxxxxxxxxx”,145.

Beware: I just spent one hour debugging, because I did get the “ERROR: 330” message despite the fact that “CSCA” did return the correct number. In the end I decided to just write the number again to the modem and give it a try. And it worked. I just have no idea why…

^BOOT

In AT Command Interface Specification, Huawei mention that ^BOOT unsolicited command only for the Huawei specified client, nothing specific.

You can disable all unsolicited result by the following AT command:

AT^CURC=0

To enable it back just change 0 to 1:

AT^CURC=1