How to reject or accept an incoming call to my GSM modem using AT commands in Python?

Abraham picture Abraham · Jun 20, 2015 · Viewed 7.5k times · Source

I've wrote the below Python program to wait for incoming calls and accept or reject them. Based on this document and this document, the appropriate AT commands to accept an incoming call is ATA or ATS0 or ATS0<n>. And also the appropriate commands to reject the incoming call is ATH or AT H.

I tried all the above commands, but the incoming call neither answered nor rejected!

My Python program :

import time
import serial

phone = serial.Serial("COM10",  115200, timeout=5)

try:
    time.sleep(1)

    while(1):
        x = phone.readline()
        print(x)
        if (x == b'RING\r\n'):
            phone.write(b'AT H') # I replaced this 'AT H' with all the above
                                 # commands, but nothing changed about the
                                 # incoming call. It always ringing.
            time.sleep(2)

finally:
    phone.close()

Results for AT H:

>>> ================================ RESTART ================================
>>> 
b''
b''
b'\r\n'
b'RING\r\n'
b'AT H\r\n'
b'RING\r\n'
b'AT H\r\n'
b'RING\r\n'
b'AT H\r\n'
b'RING\r\n'
b'AT H\r\n'
b'RING\r\n'

Results for ATH:

>>> ================================ RESTART ================================
>>> 
b''
b''
b''
b'\r\n'
b'RING\r\n'
b'ATH\r\n'
b'RING\r\n'
b'ATH\r\n'
b'RING\r\n'
b'ATH\r\n'
b'RING\r\n'

Results for ATA:

>>> ================================ RESTART ================================
>>> 
b''
b''
b''
b'\r\n'
b'RING\r\n'
b'ATA\r\n'
b'RING\r\n'
b'ATA\r\n'
b'RING\r\n'
b'ATA\r\n'
b'RING\r\n'

Results for ATS0:

>>> ================================ RESTART ================================
>>> 
b''
b''
b''
b'\r\n'
b'RING\r\n'
b'ATS0\r\n'
b'RING\r\n'
b'ATS0\r\n'
b'RING\r\n'

As you see above, the GSM modem regardless of the AT command that I send to it, continue to ringing. What's wrong about my program?

Note that my modem is a D-Link DWM-156 and I can send SMS or make a call successfully using it in Python. Thanks in advance.

Answer

Iron Fist picture Iron Fist · Jun 20, 2015

Add to the end of each AT command a CR to make it a valid AT command