Huawei E220 on Linux for SMS
Posted by Diarmuid on April 29, 2008
The E220 as sold by many mobile phone operators has transformed business use of the web. No more is the sales force tied to poor wifi coverage, dial up connections or 56k GPRS speeds. The E200 gives 3G speeds of 7.2 Mbit in a very nice tidy package.
I develop mini computers for use in remote locations. These are used for a number of purposes, but particularily Bluetooth Marketing (www.bluekulu.com). The use of the E200 has allowed me to quickly add in both internet access for the device and now I have SMS working. This will be used to both trigger an action on the computer or indeed let it SMS out reports.
In this short article I explain how to set up the E200 for use as an SMS transmitter and receiver on Linux.
Setting up the E220 for use as a modem to allow 3G on Linux is well documented on the web, but there are a few articles that really made a difference in getting it going for me.
NSLU2-Linux – HowTo / AddUsb3gModem browse
However, the SMS side is poorly documented.
I have put together a simple script that can be used to put the modem in the right state and that then launches minicom.
#!/bin/bash
rmmod usb-storage
rmmod usb-serial
mknod /dev/ttyUSB0 c 188 0
mknod /dev/ttyUSB1 c 188 1
mknod /dev/ttyUSB2 c 188 2
modprobe usbserial vendor=0×12d1 product=0×1003
sleep 10
sudo /home/broadcast/bin/huaweiAktBbo-i386.out
sleep 3 # wait for the USB host to settle down…
sudo minicom
In minicom I used the following settings
Minicom settings
Serial Device : /dev/ttyUSB0
Bps/Par/Bits : 115200 8N1
Hardware No
Software Flow Control : Yes
Once you set these settings as the default, restart minicom. (CTRLA z x)
You are now in a position to send commands to the modem. The general format is AT+Some_Command. Some that will work straigh away are.
AT+COPS=? #get network names
AT+CIMI #Get IMSI Number
AT+CGMI #Get manufacturer name
To send SMS’s you need to put the device in “Text” mode. This is done by sending the following command:
AT+CMGF=1 # Puts the mode in text mode
To send an SMS do the following:
AT+CMGS=”+35386827XXXX”
> 3G Rocks!!!!
CTRL-Z
When you type in the line with the phone number the “>” will come up automatically. Type in your message and when you are finished type in CTRLZ (as in ctrl key and z at the same time).
Good so far? But how about incoming messages. Have no fear, DBTR is here!!!
AT+CMGL=”all” #To get a list of SMS’s type in :
AT+CMGR=0 #get an individual message
AT+CMGD=n #Delete a message where n is the number returned by the list above.
There are quite a few other commands that the Huawei understands. I’ll post them later.
To hangup just do CTRLA x.
I hope this makes using the Huawei a bit easier. Now if anyone can tell me why incoming HTPP requests don’t work on Vodafone Ireland, I’d be happy to hear from them.
Hannes said
Wheee!!! finally
now I only need to script some stuff for my apache server
Rainer said
Works with HUAWEI E226??
Diarmuid said
Hi Rainer,
Probably. The same code worked via a bluetooth link to my Nokia 6230i. The protocol is well supported. All you need is a serial link.
Regards
Diarmuid
Rainer said
Thanks Diarmuid.
I will test and post the results soon.
Regards
Rainer.
Alex said
Thanks for writing this fantastic post. Just as I was about to resort to finding a Windows PC to read a text message as well!
One question – is there a way to get the modem to notify you of incoming messages as they arrive, or do you just have to poll for them?
Thanks again,
Alex
Diarmuid said
Thanks for the feedback Alex. I think you have to poll. I have a python script lurking around that I used for testing. It uses pyserial and basically just opens the port, sets text mode and then writes out the commands. Pretty straightforward.
I have used a 3G/GSM board from telit that had python on board. That could trigger code based on incoming SMS and could then write that data to a serial link (in my case to a microprocessor to trigger relays). Have a look at the boards from http://www.acmesystems.it
Regards
Diarmuid
Jorge said
For me it’s working almost completely.
But just at the end when entering the command
AT+CMGS=”+417777777777” #for example
It returns me:
+CMS ERROR: 330
I read in internet that this error is when the SMSC (service message send center) it’s not defined.
In windows the send of SMS works perfectly
Any help?
Jorge said
Ok I solved it just with the command:
AT+CSCA=”+41888888888″ #it would be the number of the SMSC
Cheers! Thanks a lot for the tutorial!
Hendra said
Hi, may I know the AT command for set huawei to use GPRS Only, GPRS Preffered, 3G Only, 3G Preffered ? Like in Mobile Connect for Windows. Please reply…
perl + huawei modem e220 + sms « Netcrash said
[...] Um tutorial à maneira e um script de perl não muito perfeito para testar a coisa… [...]
Huawei e169, ubuntu e debian… e TIM « Yupa’s Weblog said
[...] e il volume scambiato, mentre per leggere e inviare gli sms ho configurato minicom come trovato su questo sito e ho impostato delle comode macro per non dover digitare sempre tutta quella roba che non oso [...]
Me2resh said
thanks for the article, really saved a lot for me and worked smoothly
but i have a question
how can i send commands to be executed from minicom
for example i want to make a shell script that opens minicom and sends the AT command of sending the sms along with the number and sms text itself
any idea how can i get this done ??
thanks in advance.
Diarmuid said
Hi Me2resh!!,
Check out my post on using Python for this. It’s not bash and I bet you could use Ruby or even PHP for this.
http://designbuildtestrepeat.wordpress.com/2008/06/26/sms-over-3g-and-bluetooth-from-python/
basically
import serial
def SendVia3G():
ser = serial.Serial(’/dev/ttyUSB1′, 115200, timeout=1)
ser.write(’ATZ\r’)
ser.write(’AT+CMGF=1\r’)
ser.write(’AT+CMGS=”+353868276XXX”\r’)
ser.write(’SMS over 3G but from Python\n’)
ser.write(chr(26))
line = ser.readline() #read a ‘\n’ terminated line
print line
ser.close()
Happy texting. Text me on 353 86 8276237 from your modem and I’ll reply. I should have thought of that earlier to get an idea of how many people have used my code!!!
D.
Diarmuid said
@Hendra,
I’m not sure how to set it to 3g only, etc but lurking around the vodafone code I found this
HUAWEI_DICT = {
‘GPRSONLY’ : ‘AT^SYSCFG=13,1,3FFFFFFF,2,4′,
‘3GONLY’ : ‘AT^SYSCFG=14,2,3FFFFFFF,2,4′,
‘GPRSPREF’ : ‘AT^SYSCFG=2,1,3FFFFFFF,2,4′,
‘3GPREF’ : ‘AT^SYSCFG=2,2,3FFFFFFF,2,4′,
}
Could you try to figure it out from that and post the results.
Regards
D
Me2resh said
Hi Diarmud,
your code worked pretty well with me, thanks a lot
but i dunno why when i put it into loop, the first message only gets send
here is a link to my code : http://paste2.org/p/69065
i think that there is something i shouldn’t send except in the 1st loop, or something to be closed each time.
also i am wondering what is the return value i can depend on from the sendSMS function so i can make sure the message sent ?
by the way, u got my sms
?
Simon said
Very helpful site, thanks !
FYI you can write to serial port from bash, so you can set things easily at boot time by putting entries in /etc/rc.local
The command below sets 3g prefered, (I haven’t fully confirmed this working)
#define port settings
sudo stty 115200 cs8 -parenb -parodd -F /dev/ttyUSB0
#send command
echo “AT^SYSCFG=2,2,3FFFFFFF,2,4″ > /dev/ttyUSB0
Damian said
THANK YOU VERY MUCH!!!!!!!!!!!!!!!!!!!!!!
Diarmuid Wrenne said
@Me2resh
The code looks good. Try printing out more data on the messages to see if there is something about the database code that is messing up the sending.
Try adding in a few more read lines in the send sms to make sure all data has been cleared.
@simon
That could be handy. Some of my boards have very limited ram and a straight bash script to send an sms may be a better option
ionut_d said
I have this error when sending. Help!
AT+CMGS=”+07*********”
> test
>
+CMS ERROR: 500
chenull said
Beware of copy pasting!
this morning, i always got error like this:
minicom: cannot open /dev/ttyUSB0: No such device
dealing with that error for hours, I finally figured it out that maybe your website has differenct character encoding than mine. so it cannot be directly “copy paste”d
your command:
modprobe usbserial vendor=0×12d1 product=0×1003
is not work for me
but, after i retyped all the command by hand (not copy paste):
modprobe usbserial vendor=0x12d1 product=0x1003
it work ! the different is in “x” character… see that ? fyuhhh
Nuno Dantas » SMS’s na Huawei E220 em Mac OS X said
[...] era as “placas” aceitarem comandos AT. Uma pesquisa no Google levou-me ao blog “design build test repeat ”, onde encontrei instruções para Linux. Como o Mac OS X não é muito diferente do Linux, [...]
Guilherme Lopes said
only 3g mode AT command is a sucess
‘3GONLY’ : ‘AT^SYSCFG=14,2,3FFFFFFF,2,4′,
just used minicom and now only 3g awesome
hungmac said
Wow!! Great..
SMS and Wireless Setting (3G Only etc) works perfectly..
i’ll test your python program, i’ll text you if it’s success
Thx
Best, Regards
hungmac said
oh, btw, i test this on Mac OS X 10.5.6..
it works just fine like in linux.,
just change the /dev/ttyUSB0 to /dev/cu.HUAWEIMobile-Modem
Diarmuid said
Hi,
It’s great to see that my little bit of code was so useful to people. I think there really is scope to make a decent linux client for this that is not so bloated as the Vodafone one.
Has anyone tried to send an MMS using this?
Cheers
Diarmuid
http://www.bluekulu.com
boerl said
super! sms send and receive works well on my Huawei Technologies Co., Ltd. E620 USB Modem, in österreich, with provider with the most diffuse name of drei.
Choms said
Need help! How can I receive sms via huawei modem @ ubuntu?
k4ngucup said
cool….
thanks…………!!!!!!!!
sina_split said
Thanks Diarmuid, your post has been really helpful.
But I have a little problem, and I tried to find a solution through many forums, but none seemed to fully help.
I have a E160 modem, and everything seems to work just fine until the part of sending an SMS.
I use CuteCom, not minicom, and it seems that CuteCom can’t understand the CTRL-Z command. It just reads it as text input, so I can’t end the SMS.
Any ideas?
Thanks again,
sina_split
Bimbo said
Is it possible to have a string like RING “+39xxxxxxxxxx” when you call the sim in the modem.
When i make a call to the modem sim number i get an off line message.
It’s possible to get the sim registered for voice call?
Thank You
Cristano
Pat said
Below is what I got when I tried to set the serial port by issuing the following:
ser = serial.Serial(’/dev/ttyS0′, 115200, timeout=1)
Any ideas?
Traceback (most recent call last):
File “”, line 1, in ?
File “/usr/lib/python2.4/site-packages/serial/serialutil.py”, line 171, in __init__
self.open()
File “/usr/lib/python2.4/site-packages/serial/serialposix.py”, line 179, in open
raise SerialException(“could not open port %s: %s” % (self._port, msg))
serial.serialutil.SerialException: could not open port dev/ttyS0: [Errno 2] No such file or directory: ‘dev/ttyS0′
Thanks
Ender said
SMS works with an Orange’ Huawei E270 USB 3G modem on openSUSE 11
Great work, thank you very much!
Dieter Ziehe said
Hello,
many thanks for your work.
Now I can send SMS and get SMS on my linux PC with huawei220
I forgot these commands from the 90-eth (modem and so on).
But now these commands are again important.
Bye
Dieter
nuffer said
Hey, any word on if this is possible with the Hauwei EC226?
In da jungle said
Probably PyHumod will support it.
badr said
hi all
PLZ i need help for my e220 modem, the e220 is connected and the light is blue but internet dont work the browser firefox can not fine any thing.
im using ubuntu 9.04
e220 modem operator Meditel
Drew said
badr,
Maybe you already solved your issue:
But you should be using KPPP to make your internet connection with the Huawei Modem.
Just set the Modem to /dev/ttyUSB0 and the conumber to *99# (or similar depending on provider).
Of course you may not have kppp on ur system (not sure) and may have to download it or install it from CD.
HUAWEI G5730 said
nice post keep going
Pavelas said
I have HUAWEI E156G modem. Everything works perfectly, same us with E220, but ~ for 15 minutes. Then modem just disconnects (hangs), and gets up on another USB address after several seconds.
Tried different hardware, different kernels and distros – same result. E220, E176 works perfectly.
Maybe anyone found solution?
Dmesg example:
Aug 1 16:17:51 x10 kernel: usb 2-6: USB disconnect, address 6
Aug 1 16:17:51 x10 kernel: option 2-6:1.0: device disconnected
Aug 1 16:17:51 x10 kernel: option1 ttyUSB1: GSM modem (1-port) converter now disconnected from ttyUSB1
Aug 1 16:17:51 x10 kernel: option 2-6:1.1: device disconnected
Aug 1 16:17:51 x10 kernel: usb 2-6: new high speed USB device using ehci_hcd and address 7
Aug 1 16:17:51 x10 kernel: usb 2-6: configuration #1 chosen from 1 choice
Aug 1 16:17:52 x10 kernel: usb 2-6: USB disconnect, address 7
Aug 1 16:17:56 x10 kernel: usb 2-6: new high speed USB device using ehci_hcd and address 8
Aug 1 16:17:56 x10 kernel: usb 2-6: configuration #1 chosen from 1 choice
Aug 1 16:17:56 x10 kernel: option 2-6:1.0: GSM modem (1-port) converter detected
Aug 1 16:17:56 x10 kernel: usb 2-6: GSM modem (1-port) converter now attached to ttyUSB1
Aug 1 16:17:56 x10 kernel: option 2-6:1.1: GSM modem (1-port) converter detected
Aug 1 16:17:56 x10 kernel: usb 2-6: GSM modem (1-port) converter now attached to ttyUSB2
Aug 1 16:17:57 x10 kernel: scsi25 : SCSI emulation for USB Mass Storage devices
Aug 1 16:17:58 x10 kernel: scsi26 : SCSI emulation for USB Mass Storage devices
Aug 1 16:18:02 x10 kernel: scsi 25:0:0:0: CD-ROM HUAWEI Mass Storage 2.31 PQ: 0 ANSI: 2
Aug 1 16:18:02 x10 kernel: scsi 25:0:0:0: Attached scsi generic sg3 type 5
Aug 1 16:18:03 x10 kernel: scsi 26:0:0:0: Direct-Access HUAWEI MMC Storage 2.31 PQ: 0 ANSI: 2
Aug 1 16:18:03 x10 kernel: sd 26:0:0:0: [sdc] Attached SCSI removable disk
Aug 1 16:18:03 x10 kernel: sd 26:0:0:0: Attached scsi generic sg4 type 0
Harris said
Is it the same with the Sony Ericson K550i AT commands? I am thinking of using it for our thesis. thanks for the post.
-harristgp
Harris said
Is it the same with the Sony Ericson K550i AT commands? I am thinking of using it for our thesis. thanks for the post..
-harristgp
inckie said
nagios:~# chat TIMEOUT 1 “” “AT+CPIN=****” “OK” > /dev/ttyUSB0 /dev/ttyUSB0 /dev/ttyUSB0 /dev/ttyUSB0 /dev/ttyUSB0 /dev/ttyUSB0 <– Terminate Line
inckie said
nagios:~# chat TIMEOUT 1 "" "AT+CPIN=****" "OK" > /dev/ttyUSB0 /dev/ttyUSB0 /dev/ttyUSB0 /dev/ttyUSB0 /dev/ttyUSB0 /dev/ttyUSB0 <-- Terminale Line
inckie said