Pradeep Singh | 27th Jun 2018
In this article, you would learn how to detect Modem events like Ring, Busy Tone, Silence or the DTMF tones. Depending on the modem type and model and the country you live in there could be a difference in the events reported by the analog modem from the phone line.
For this article, I am going to use USRobotics USR5637 USB Dial-up Modem and as per its documentation, it can report the following events to the computer it is connected to –
1. Hardware Setup:
For this article, I am going to connect the USRobotics USR5637 USB Dial-up Modem with a Raspberry Pi as shown in the following picture –
2. Download the Python Script:
You can download a sample Python script from my Github Repository using the following command –
git clone https://github.com/pradeesi/dtmf_tone_detection
Following terminal output shows the git clone output on raspberry pi –
pi@raspberrypi:~ $ git clone https://github.com/pradeesi/dtmf_tone_detection Cloning into 'dtmf_tone_detection'... remote: Counting objects: 6, done. remote: Compressing objects: 100% (5/5), done. remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (6/6), done. pi@raspberrypi:~ $
On successful code download, you should see “dtmf_tone_detection” directory under your present working directory. CD into the “dtmf_tone_detection” directory and make sure you have “detect_modem_events.py” file under it, as shown in the following terminal output –
pi@raspberrypi:~ $ cd dtmf_tone_detection/ pi@raspberrypi:~/dtmf_tone_detection $ ls README.md detect_modem_events.py pi@raspberrypi:~/dtmf_tone_detection $
3. Execute Python Script to Detect Modem Events:
To run the python script, execute the following command (make sure you are inside“dtmf_tone_detection” directory) –
python detect_modem_events.py
On python script execution you should see following input on your Raspberry Pi terminal. At this stage, the modem is waiting for the incoming call.
4. Modem Events:
The python script will keep monitoring the phone line for the events using the modem and report them back on to the console as shown in the following examples –
4.1 Ring and Caller ID Details:
On receiving an incoming call the modem would report the phone ring with “RING” message. Apart from this, if the Caller ID is enabled, it will also report the caller’s phone number with “NMBR=xxxxxxxx” message, Date and Time with “DATE=DDMM” and “TIME=HHmm” messages as shown in the following screenshot –
4.2 DTMF Digits:
After 2 rings the python script will put the modem into the voice mode and go off-hook. Now it will detect the DTMF tones sent by the caller by pressing the button of his/her phone. The DTMF digits are shielded between “/” and “~” special characters (For ex: /1111111~ or /5555555~ etc.). The python script will parse the digits and display them on the Raspberry Pi terminal console as shown in the following screenshot –
4.3 Silence:
If the modem detects silence on the call after going off-hook, it (modem) would report back to Raspberry Pi using char “s“. The silence character (“s”) will be shielded by ASCII char 16 which is used as DLE character. Python script will report the silence as shown in the following terminal screenshot (the call will be disconnected by the script on silence detection using the ATH command) –
4.4 Busy Tone:
If the caller disconnects the call, the modem will report Busy Tone back to raspberry pi using the “b” char. Busy tone signal (“b“) will be shielded by ASCII char 16 which is used as DLE character. Python script will report the busy tone as shown in the following terminal screenshot (the call will be disconnected by the script on busy tone detection using the ATH command) –
Related Articles:
USB Analog Modem with Raspberry Pi
Python Script to Reset USB Modem COM Port on Raspberry Pi
Python Script to Autodetect Modem COM Port on Raspberry Pi
Incoming Call Details Logger with Raspberry Pi
Play Audio File on Phone Line with Raspberry Pi
Record Audio from Phone Line with Raspberry Pi
References:
Wikipedia – Voice modem command set
USRobotics 56K USB Modem Voice Commands
USRobotics 56K USB Modem – Data and General Commands
Voice +V Commands – Developer’s Guide