18

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()
Ebrahim Ghasemi
  • 5,850
  • 10
  • 52
  • 113

1 Answers1

38

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

Ebrahim Ghasemi
  • 5,850
  • 10
  • 52
  • 113
  • 2
    Personally I would use: `phone.write(b'ATD"%s";\r' % recipient.encode())` as being clearer what is going on and a little more compact. – Steve Barnes Jun 21 '15 at 12:38
  • 1
    For completeness regarding the semicolon: The `ATD` command has a `L` modifier that makes the modem dial the last dialed number. So if you first start a data call with `ATD1234` then you can after that call ends give `ATDL` to set up a new data call to the same number. The not so obvious issue here is for voice calls. If you first set up a **voice call** with `ATD1234;` then just giving `ATDL` will set up a **data call** to number 1234, so the modem only reuses the number and not the type of the call. If you want to repeat a voice call you have to give `ATDL;` with a semicolon at the end. – hlovdal Jun 30 '15 at 21:40
  • @hlovdal thank you dear friend. May I ask you to say me what's the difference between a voice call and a data call? Can I initiate a data call using a dial up modem also, or it is for GSM modems only? – Ebrahim Ghasemi Jul 01 '15 at 03:48
  • 3
    Hi nlovdal, I have "NO CARRIER" error with command ATD+39**********; . SIM is unlocked (AT+CPIN? returns READY), the signal quality is OK (AT+CSQ returns 9,3) and It's registered properly to a network (AT+COPS? returns 0,0,"vodafone IT",2). Any suggestion to fix the issue? – aldo85ita Feb 08 '17 at 14:21
  • @aldo85ita me too getting the same error. did u found the answer ? – Anto sujesh Jun 15 '17 at 11:18
  • 1
    I have found that getting NO CARRIER could also mean that you don't have any airtime left to dial. – Danie Nov 07 '19 at 10:52