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

I wrote the following Python program to wait for incoming calls and accept or reject them. Based on this document and this document, the appropriate AT commands for receiving an incoming call are ATA

either ATS0

or ATS0<n>

. As well as the corresponding commands for rejecting an incoming call: ATH

or AT H

.

I tried all of the above commands, but the incoming call didn't answer or reject!

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 can see above, the GSM modem, regardless of the AT command I send to it, continues to ring. What's wrong with my program?

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

+3


source to share


3 answers


Add AT

a CR to the end of each command to make it a valid commandAT



+3


source


We cannot reject an incoming call directly. To reject incoming calls, we have to set up a voice hang-up control command,

AT + CVHU (command to hang up voice).



ATH command depends on AT + CVHU.

0


source


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()

      

0


source







All Articles