Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 361
Ebrahim Ghasemi Avatar asked Jun 20 '15 12:06

Ebrahim Ghasemi


People also ask

How to send and receive SMS using GSM modem in Python?

To send the SMS, first set the messaging to the text mode using “AT+CMGF=1″ command. Then, select a number to send the SMS using the AT+CMGS=”XXXXXXXXXX” command, where XXXXXXXXXX is a mobile number. The message to be sent is stored in a variable.

Which command instructions are used to control a GSM modem?

Many of the commands that are used to control wired dial-up modems, such as ATD (Dial), ATA (Answer), ATH (Hook control) and ATO (Return to online data state), are also supported by GSM/GPRS modems and mobile phones.

What are the commands used in GSM?

There are some commands which support GSM. These commands which are used for GSM mainly include SMS based commands like AT+CMGS, AT+CMSS, AT+CMGL & AT+CMGR. Here the prefix AT in these commands informs the modem regarding the begin of a command line.

What is GSM in Python?

python-gsmmodem is a module that allows easy control of a GSM modem attached to the system. It also includes a couple of useful commandline utilities for interacting with a GSM modem. Its features include: simple methods for sending SMS messages, checking signal level, etc.


1 Answers

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.

like image 69
Roberto Caboni Avatar answered Sep 21 '22 15:09

Roberto Caboni