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()
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=2
means that URCs are buffered in case of busy modem. mt=2
means that incoming messages are shown directly with a +CMT: ...
URC. No storing!!!ds=0
means that status report receiving is not reported and is not stored! That's not what you want!Instead, you probably want:
+CMTI: <mem>,<idx>
URC is shown, stating that is has been stored in memory=mem at index=idx. +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
+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
).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.