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

9.2k views Asked by At

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.

3

There are 3 answers

0
Iron Fist On BEST ANSWER

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

0
Dinesh Pulidindi On

We can't reject the incoming call directly. To reject incoming Calls, We should configure the Voice hang up control command,

AT+CVHU (command for voice hang up).

ATH command is depends on AT+CVHU.

0
YasserDaniyal On
phone = serial.Serial("/dev/ttyAMA0", baudrate=9600, timeout=1)

try:
    time.sleep(1)

    while(1):
        x = phone.readline()
        print(x)
        if (x == b'RING\r\n'):
            phone.write('ATH'+'\r\n') 
            time.sleep(2)

finally:
    phone.close()