+CNMI command: how to receive notification and save to SIM Card incoming SMS

点点圈 提交于 2020-03-06 09:23:45

问题


I need to get notification success delivery. I read so many and tried. I have GSM modem ZTE K4510Z. I don't get any notification or save to sim card. In my tested. I though my sim card is broken. So I try AT+CMGW to write temporary message to simcard. It success and exist. So in the end I think, it's command not the simcard. I try so many think from AT+CNMI, AT+CPMS. None reply buffer I get after send a message. I check it too with AT+CPMS? after send message. If a message it write to simcard without notification. But nothing, no notification, no message written into simcard storage.

import serial
import time

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

modem.write(b'AT\r')

while True:
    buffer = modem.readline()

    if buffer == b'OK\r\n':
        print('OK')
        break

# Set SMS MODE
modem.write(b'AT+CMGF=1\r')

while True:
    buffer = modem.readline()

    if buffer == b'OK\r\n':
        print('OK')
        break

# Set Preferred Storage
modem.write(b'AT+CPMS="SM","SM","SM"\r')

while True:
    buffer = modem.readline()

    if buffer == b'OK\r\n':
        print('OK')
        break

# Set how a notification    
modem.write(b'AT+CNMI=2,2,0,0,0\r')

while True:
    buffer = modem.readline()

    if buffer == b'OK\r\n':
        print('OK')
        break

recipient = "Phone_number"
message = 'Message'

# Set Recipient
modem.write(b'AT+CMGS="' + recipient.encode('UTF-8') + b'"\r')

while True:
    buffer = modem.read(1)

    if buffer == b'>':
        break

# Set Message
modem.write(message.encode('UTF-8') + b'\r')

# Input CTRL+Z  
modem.write(bytes([26]))

# Waiting any buffer
while True:
    buffer = modem.readline()

    print(buffer)

    time.sleep(1)

modem.close()

回答1:


You are sending AT+CNMI=2,2,0,0,0 command, with the goal to have in SM either incoming SMS or the SMS delivery report, along with URCs notifications for them. I'll try to explain how to enable both of these features.

According to the spec, syntax the syntax of that command is:

AT+CNMI=[mode[,mt[,bm[,ds[,bfr]]]]]

  • mode: unsolicited result codes buffering option. mode=2 means that URCs are buffered in case of busy modem.
  • mt: result code indication reporting for SMS-DELIVER. mt=2 means that incoming messages are shown directly with a +CMT: ... URC. No storing!!!
  • bm: broadcast reporting option. Unrelevant for us.
  • ds: SMS-STATUS-REPORTs reporting option. ds=0 means that status report receiving is not reported and is not stored! That's not what you want!
  • bfr: buffered result codes handling method. Unrelevant for us.

Instead, you probably want:

  • mt=2, meaning that incoming SMS is stored and a +CMTI: <mem>,<idx> URC is shown, stating that is has been stored in memory=mem at index=idx.
  • ds=2, meaning that if a status report is stored, then a +CDSI: <mem>,<idx> URC is shown, stating that is has been stored in memory=mem at index=idx.

This might help you, but be aware that

  1. You have to make sure that your modem model do supports these features (verify it in its AT user guide) and they are not dummy.
  2. You have to make sure that your operator supports status delivery reports, and that they have been enabled for your SIM.
  3. The SMS storage class affects the storing action performed by the modem, and this is true expecially for status delivery reports. In this case you can use ds=1 setting, which at least makes the modem show a report with the URC +CDS: ....

Note: be also aware that +CNMI settings are volatile, so if you reboot you lose them unless you save them in the default profile (by issuing AT&W&P).



来源:https://stackoverflow.com/questions/58908575/cnmi-command-how-to-receive-notification-and-save-to-sim-card-incoming-sms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!