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 when you receive a call from a certain number.
The Huawei e220 supports a subset of the AT commands, which subset is an enterprise secret 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:
To connect to the devices you can use a serial client. GNU 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
To check for calls you should listen to
ttyUSB1. A serial session for
ttyUSB1 looks like:
^BOOT:44594282,0,0,0,6 ^RSSI:18 RING +CLIP: "+33499311152",145,,,,0 ^BOOT:44594282,0,0,0,6
CLIP messages are the most interesting. The
RING signifies an incoming call, the
CLIP is the caller ID. The
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.
#!/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