---
title: Caller ID with Linux and Huawei e220
canonical: https://0110.be/posts/Caller_ID_with_Linux_and_Huawei_e220
markdown_url: https://0110.be/posts/Caller_ID_with_Linux_and_Huawei_e220.md
id: 49
published_at: '2010-04-11T00:00:00Z'
updated_at: '2013-12-05T18:19:15Z'
author: Joren
tags:
- name: 0110.be
  markdown_url: https://0110.be/tags/0110.be.md
- name: Code
  markdown_url: https://0110.be/tags/Code.md
- name: Hackerspace Ghent
  markdown_url: https://0110.be/tags/Hackerspace%20Ghent.md
- name: Projecten
  markdown_url: https://0110.be/tags/Projecten.md
---

# Caller ID with Linux and Huawei e220

<img src="https://0110.be/files/attachments/49/huawei_e220.jpg" title="huawei e220" style="float:right">This is the scenario: you have a Huawei e220, a linux computer and you want to react to a call from a set of predefined numbers. E.g. [ordering a pizza](https://0110.be/artikels/lees/Order_Pizza_with_USB_Pizza_Button) when you receive a call from a certain number.

The Huawei e220 supports a subset of the [AT commands](http://en.wikipedia.org/wiki/AT_commands), which subset is [an enterprise secret](http://forum.huawei.com/jive4/thread.jspa?threadID=324487) of te Huawei company. So there is no documentation available for the device I bought, thanks Huawei. Anyhow when you attach the e220 to a Linux machine you should get two serial ports:

\`\`\`ruby\
/dev/ttyUSB0\
/dev/ttyUSB1\
\`\`\`

To connect to the devices you can use a serial client. [GNU Screen](http://www.gnu.org/software/screen/) can be used as a serial client like this: `screen /dev/ttyUSB0 115200`. The first device, `ttyUSB0` is used to control `ttyUSB1`, so to enable caller ID on te Huawei e220 you need to send this message to `ttyUSB0`:

\`\`\`ruby\
AT+CLIP=1\
\`\`\`

To check for calls you should listen to `ttyUSB1`. A serial session for `ttyUSB1` looks like:

\`\`\`ruby\
\^BOOT:44594282,0,0,0,6\
\^RSSI:18\
RING\
+CLIP: "+33499311152",145,,,,0\
\^BOOT:44594282,0,0,0,6\
\`\`\`

The `RING` and `CLIP` messages are the most interesting. The `RING` signifies an incoming call, the `CLIP` is the caller ID. The `BOOT` and `RSSI` are some kind of ping messages. The following Python script demonstrates a complete session that enables caller ID, waits for a phone call and prints the number of the caller.

\`\`\`python\
#!/usr/bin/env python\
import serial, re

command_channel = serial.Serial(\
port='/dev/ttyUSB0',\
baudrate=115200,\
parity=serial.PARITY_NONE,\
stopbits=serial.STOPBITS_ONE,\
bytesize=serial.EIGHTBITS\
)\
command_channel.open()\
#enable caller id\
command_channel.write("AT+CLIP=1" + "\\r\\n")\
command_channel.close()

ser = serial.Serial(\
port='/dev/ttyUSB1',\
baudrate=9600,\
parity=serial.PARITY_NONE,\
stopbits=serial.STOPBITS_ONE,\
bytesize=serial.EIGHTBITS\
)

ser.open()

pattern = re.compile('.**CLIP.**"\\+(\[0-9\]+)",.\*')

while 1:\
buffer = ser.read(ser.inWaiting()).strip()\
buffer = buffer.replace("\\n","")\
match = pattern.match(buffer)\
if match:\
number = match.group(1)\
print number\
\`\`\`

