yui amanda
yui amanda

Reputation: 47

How to know if an SMS sending is failed or successful?

I' creating a SMS gateway from GSM Modem port. I need to verify if an SMS sending is failed or successful. So I think the ways to check failed or success is to check the message storage called outbox if success and failed to draft.
But, if I try to issue AT commands to check storage by index or to print the messages contained in all indexes, it returns nothing.

Response after sending a message:

+CMGS: 170

as I read we can read the message with AT+CMGR command

modem = serial.Serial('COM5', 9600, timeout=0)

modem.write(b'AT+CMGR=170\r')

while True:
    print(modem.read(100))
    input('Type to see response')

I tried also with the command AT+CMGR="ALL" to print out anything in storage, but, no messages are printed out.

Upvotes: 0

Views: 1190

Answers (1)

Roberto Caboni
Roberto Caboni

Reputation: 7490

Command AT+CMGS directly sends SMSs without storing them. In its command response

+CMGS: 170

number 170 is just a progressive number counting successful sends (it is incremented up to 255 and the restarts from 0) and it is completely unrelated to SMS memory location in which it is stored.

But fortunately that response is sent by the modem only when the SMS is successfully transmitted, otherwise an ERROR response is returned. What does "sent" mean? Just that is has been successfully delivered to SMS service center. Actual delivery to SMS recipient is usually immediate, but it might also be delayed by network congestion or by recipient unavailability.

Just for completeness, AT+CMGR=<index> and AT+CMGL=ALL can actually show also sent messages, but only for those stored with AT+CMGW before sending them. For example with +CMGL you may have N rows, each one reporting:

+CMGL: <index>,<stat>,...

in which can have the following values:

  • "REC UNREAD" - new incoming message
  • "REC READ" - already read incoming message
  • "STO UNSENT" - stored message not yet sent
  • "STO SENT" - stored message already sent <-- this one is relevant for you

Upvotes: 1

Related Questions