+ CNMI命令:如何接收通知并将传入的短信保存到SIM卡 [英] +CNMI command: how to receive notification and save to SIM Card incoming SMS

查看:146
本文介绍了+ CNMI命令:如何接收通知并将传入的短信保存到SIM卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获得通知成功发送.我读了很多,然后尝试了.我有GSM调制解调器 ZTE K4510Z .我没有收到任何通知或保存到SIM卡.在我的考验中.尽管我的SIM卡坏了.因此,我尝试 AT + CMGW 将临时消息写入simcard.它成功并存在.所以最后我认为,这是命令而不是Simcard.我尝试了许多来自 AT + CNMI AT + CPMS 的想法.发送邮件后得到的无应答缓冲区.发送邮件后,我也可以通过 AT + CPMS?进行检查.如果有消息,它会在没有通知的情况下写入simcard.但是什么也没有,没有通知,也没有消息写入到SIM卡存储中.

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()

推荐答案

您正在发送AT+CNMI=2,2,0,0,0命令,目标是在SM中包含传入的SMS或SMS传递报告以及针对它们的URC通知.我将尝试说明如何启用这两个功能.

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 [,mt [,bm [,ds [,bfr]]]]]

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

  • 模式:主动提供的结果代码缓冲选项. mode=2表示在调制解调器繁忙时缓冲URC.
  • mt :SMS-DELIVER的结果代码指示报告. mt=2表示直接使用+CMT: ... URC显示传入的消息.没有存储!
  • bm :广播报告选项. 与我们无关.
  • ds :SMS-STATUS-REPORTs报告选项. ds=0表示不报告也不存储状态报告!那不是你想要的!
  • 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.
    • 相反,您可能想要:

      • mt = 2 ,这意味着将存储传入的SMS并显示+CMTI: <mem>,<idx> URC,表明已将其存储在index = idx的memory = mem中.
      • ds = 2 ,这意味着如果存储了状态报告,则显示+CDSI: <mem>,<idx> URC,表明已存储在memory = mem中index = idx.
      • 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. 您必须确保您的调制解调器型号确实支持这些功能(请在其AT用户指南中进行验证),并且它们不是虚拟的.
      2. 您必须确保操作员支持状态传送报告,并且已为您的SIM启用了这些报告.
      3. SMS存储类会影响调制解调器执行的存储操作,尤其对于状态传送报告而言,这是正确的.在这种情况下,您可以使用 ds = 1 设置,至少可以使调制解调器显示带有URC +CDS: ...的报告.
      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: ....

      注意:还应注意+ CNMI设置是易失的,因此,如果重新启动,除非将其保存在默认配置文件中(通过发出AT&W&P),否则它们将丢失.

      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).

      这篇关于+ CNMI命令:如何接收通知并将传入的短信保存到SIM卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆