Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Receiving "NO CARRIER" error while tring to make a call using GSM modem in Python

I want to make a call using my GSM modem. So I wrote the below program:

import time
import serial

recipient = "+98xxxxxxxxxx"

phone = serial.Serial("COM10",  115200, timeout=5)
try:
    time.sleep(0.5)
    phone.write(b'ATZ\r')
    time.sleep(1)
    phone.write(b'ATD"'+recipient.encode() +b'"\r')
    while(1):
        print(phone.readline())
    time.sleep(0.5)
finally:
    phone.close()

But when I run it I receive this output:

>>> ================================ RESTART ================================
>>> 
b'ATZ\r\r\n'
b'OK\r\n'
b'ATDxxxxxxxxxx\r\r\n'
b'NO CARRIER\r\n'

What does this "NO CARRIER" error means?

Note that I can send SMS successfully.


This is the program that I use to send SMS:

import time
import serial

recipient = "+98xxxxxxxxxx"
message = "Test"

phone = serial.Serial("COM10",  115200, timeout=5)


try:
    time.sleep(0.5)
    phone.write(b'ATZ\r')
    time.sleep(0.5)
    phone.write(b'AT+CMGF=1\r')
    time.sleep(0.5)
    phone.write(b'AT+CMGS="' + recipient.encode() + b'"\r')
    time.sleep(0.5)
    phone.write(message.encode() + b"\r")
    time.sleep(0.5)
    phone.write(bytes([26]))
    time.sleep(0.5)
finally:
    phone.close()
like image 254
Ebrahim Ghasemi Avatar asked Jun 20 '15 08:06

Ebrahim Ghasemi


People also ask

How do you make a call with GSM?

AT commands used to make call using gsm module : “AT+CMIC = 1” This command is used to select gain of Audio. Its value can be between 0-15. “ATD092341434445” This command is used to make call to required number. Where 092341434445 is a number to which you want to make call.

What are AT commands in GSM?

AT commands are instructions used to control a modem. AT is the abbreviation of ATtention. Every command line starts with "AT" or "at". That's why modem commands are called AT commands.


1 Answers

I found the origin of the error :

The syntax is ATD+98xxxxxxxxxx; followed by terminating string. I was forgotten to put semicolon at the end after the number.

So I replace

phone.write(b'ATD"'+recipient.encode() +b'"\r')

with

phone.write(b'ATD"'+recipient.encode() +b';"\r')

And now it works fine.


Based on the brackets in this documents, I thought that using ";" is optional. But it seems that I was wrong. enter image description here

like image 160
Ebrahim Ghasemi Avatar answered Oct 09 '22 14:10

Ebrahim Ghasemi