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

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

问题描述

我需要收到通知成功发送.我读了很多并尝试过.我有 GSM 调制解调器 ZTE K4510Z.我没有收到任何通知或保存到 SIM 卡.在我的测试中.我虽然我的sim卡坏了.所以我尝试AT+CMGW 将临时消息写入simcard.它成功并存在.所以最后我认为,它是命令而不是 SIM 卡.我尝试了很多来自AT+CNMIAT+CPMS的想法.发送消息后我得到的无回复缓冲区.发送消息后,我也用 AT+CPMS? 进行检查.如果一条消息会在没有通知的情况下写入 simcard.但是什么都没有,没有通知,没有消息写入 simcard 存储.

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

while True:
    buffer = modem.readline()

    if buffer == b'OK
':
        print('OK')
        break

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

while True:
    buffer = modem.readline()

    if buffer == b'OK
':
        print('OK')
        break

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

while True:
    buffer = modem.readline()

    if buffer == b'OK
':
        print('OK')
        break

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

while True:
    buffer = modem.readline()

    if buffer == b'OK
':
        print('OK')
        break

recipient = "Phone_number"
message = 'Message'

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

while True:
    buffer = modem.read(1)

    if buffer == b'>':
        break

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

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

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

  • mode:主动提供的结果代码缓冲选项.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天全站免登陆