/mili

Play With Your GSM Cell Phone

Tonight suddenly I interested in using AT Command on Cell Phone From Python.
It was so fantastic for me, I can connect to my Cell Phone. really Python powered me so much !

All you need are Cell Phone and USB connector, when it connect, you could see device as /dev/ttyACM0 (or /dev/ttyACM[number] )
Don’t forget check your device connected correctly by this command :
$ls -l /dev/ttyACM*
crw-rw---- 1 root dialout 166, 0 2007-10-28 00:40 /dev/ttyACM0
And here is sample code which show Manufacturer, Model and IMEI of your Cell Phone.
import serial
 
def send(ser,command):
if ser.isOpen():
ser.write(command)
while 1:
out=ser.readline()
if out.strip()=='OK\r\n':
break
if out.strip()!='':
print out
 
ser=serial.Serial('/dev/ttyACM0')
ser.open() 
if ser.isOpen():
send(ser,'at+cgmi\r') #Get Manufacturer
send(ser,'at+cgmm\r') #Get Model
send(ser,'at+cgsn\r') #Get IMEI
ser.close()

It’s my output :

at+cgmi
Nokia
at+cgmm
Nokia 3230
at+cgsn
X5X399X06X34X5X (sorry I replace some numbers with X)
It isn’t all you can do! see more AT Commands here also see pyserial manual .