How to send and receive some data via a GSM modem during an active call (Python and AT Command)

4.4k Views Asked by At

I wrote the below Python program to communicate with my D-Link DWM-156 GSM modem. This program wait for incoming calls and as it receive a RING alert, it accepts that call.

Fortunately it works fine ;)

The 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'ATA\r')
            time.sleep(0.5)

finally:
    phone.close()

Output during running:

>>> ================================ RESTART ================================
>>> 
b''
b''
b''
b'\r\n'
b'RING\r\n'   #Here, my friend (named "Jimmy",for example), called me.
b'OK\r\n'
b''
b''
b''
b''
b''

As you see above, immediately after receiving an incoming call, the GSM modem accept it and from that point to the end, we have an active call.

My questions:

1- Is it possible to send/receive some data (SMS for example) during this active call? Or at least can I make a noise on the other side of this channel (i.e on the speaker of Jimmy's phone) during this active call? (I don't want to send recognisable sound, a noise is enough. Although having a methodology to send recognisable voice is really better.)

2- Why this program detect incoming calls, but doesn't detect incoming SMSs? Look below. You can see output of my program when Jimmy sent 3 SMSs to my GSM modem (And he received "delivered" notification in his my mobile phone for all of them).

>>> ================================ RESTART ================================
>>> 
b''
b''
b''
b''
b''
b''
b''

As you see above, I received nothing, while he sent 3 SMSs! Why?

2

There are 2 best solutions below

0
On

Question 1:

I think that what you need are DTMF Tones. DTMF tones are those sounds that you can hear if you're talking with your friend Jimmy and he presses the number buttons. Each button ([0-9],#,*,[A-D],P) has its specific tone.

You can find a good description about how they are composed here.

I just report here that there are two standard commands allowing you to deal with DTMF tones:

  • AT+VTD=<duration> - Setting tones duration
  • AT+VTS=<dtmfSequence> - Sending a sequence of tones

Question 2:

As correctly reported in one comment above, URCs (unsolicited result codes) for incoming Short Messages can be enabled by means of AT+CNMI command, which description can be found here.

0
On

Most GSM modems will need some initialization so that they signal incoming SMSs. I believe that's what Khalil was refering to. These come as a set of AT commands you should send before entering your loop.

I've done this successfully in the past with a few different GSM modem brands and recall that even though there are some device specific details, the general commands you need to send are the same.

A quick search lead me to:

Maybe you can use them as a starting point.