Search code examples
pythonpyserialat-command

AT+CIMI command using pyserial results in empty string


Connecting to Android Phone via Putty and sending at+cimi command shows my IMSI number. (XX[..]XX are numeric values)

at+cimi
XXXXXXXXXXXXXXX

OK

With below python code (at command g+cgpaddr):

def open_serial(com_port):
    my_serial = serial.Serial(com_port, baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=1, xonxoff=1, rtscts=0)
    return my_serial

s = open_serial('COM35')
s.write(b'at+cgpaddr\r')
temp = s.readlines()
print(temp)

The output is:

[b'at+cgpaddr\r\r\n', b'+CGPADDR: 1,"XXX.XXXX.XXX.XXX"\r\n', b'\r\n', b'OK\r\n']

If I only change at+cgpaddr to at+cimi:

s = open_serial('COM35')
s.write(b'at+cimi\r')
temp = s.readlines()
print(temp)

The output is empty string:

[]

Is there a solution for that problem?


Solution

  • If anyone meets this problem, I solved it by adding spaces between "at" and "cimi".

    Before: s.write(b'at+cimi\r')

    After: s.write(b'at + cimi\r')

    I don't know why, but it works. Checked on another phone, PC it works with both versions.