python-gsmmodem 读取旧短信
python-gsmmodem read old sms
我尝试读取收到的短信,而 python-gsmmodem 不是 运行 但无法使其工作...
==调制解调器信息==
厂商:华为
型号:E3531
修订:22.521.31.00.400
这是我的 python 代码:
#!/usr/bin/env python
from __future__ import print_function
from datetime import datetime
from gsmmodem.modem import GsmModem, Sms
import logging
PORT = '/dev/ttyUSB0'
BAUDRATE = 115200
PIN = None # SIM card PIN (if any)
def handleSms(sms):
print(u'== SMS message received ==\nFrom: {0}\nTime: {1}\nMessage:\n{2}\n'.format(sms.number, sms.time, sms.text))
def main():
print('Initializing modem...')
# Uncomment the following line to see what the modem is doing:
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
modem = GsmModem(PORT, BAUDRATE, smsReceivedCallbackFunc=handleSms)
modem.smsTextMode = False
modem.connect(PIN)
#modem.processStoredSms(False)
smss = modem.listStoredSms(status=Sms.STATUS_ALL, delete=True);
print(str(len(smss)) + ' messages found')
for i in range(len(smss)):
sms = smss[i]
handleSms(sms)
print('Waiting for new SMS message...')
try:
modem.rxThread.join(2**31) # Specify a (huge) timeout so that it essentially blocks indefinitely, but still receives CTRL+C interrupt signal
finally:
modem.close();
if __name__ == '__main__':
main()
这是日志:
Initializing modem...
INFO: Connecting to modem on port /dev/ttyUSB0 at 115200bps
DEBUG: write: ATZ
DEBUG: response: [u'OK']
DEBUG: write: ATE0
DEBUG: response: [u'OK']
DEBUG: write: AT+CFUN?
DEBUG: response: [u'+CFUN: 1', u'OK']
DEBUG: write: AT+CMEE=1
DEBUG: response: [u'OK']
DEBUG: write: AT+CPIN?
DEBUG: response: [u'+CPIN: READY', u'OK']
DEBUG: write: AT+CLAC
DEBUG: write: AT
DEBUG: response: [u'OK']
DEBUG: write: AT^CVOICE=?
DEBUG: response: [u'^CVOICE: (0)', u'OK']
DEBUG: write: AT+VTS=?
DEBUG: response: [u'+VTS: (0-9,A-D,*,#)', u'OK']
DEBUG: write: AT^DTMF=?
DEBUG: response: [u'ERROR']
DEBUG: write: AT^USSDMODE=?
DEBUG: response: [u'^USSDMODE: (0-1)', u'OK']
DEBUG: write: AT+WIND=?
DEBUG: response: [u'ERROR']
DEBUG: write: AT+ZPAS=?
DEBUG: response: [u'ERROR']
DEBUG: write: AT+CSCS=?
DEBUG: response: [u'+CSCS: ("IRA","UCS2","GSM")', u'OK']
DEBUG: write: AT+CNUM=?
DEBUG: response: [u'OK']
DEBUG: write: AT^CVOICE=0
DEBUG: response: [u'ERROR']
DEBUG: write: AT^USSDMODE=0
DEBUG: response: [u'OK']
DEBUG: write: AT+CGMI
DEBUG: response: [u'huawei', u'OK']
DEBUG: write: AT+CGMI
DEBUG: response: [u'huawei', u'OK']
INFO: Loading Huawei call state update table
DEBUG: write: AT+COPS=3,0
DEBUG: response: [u'OK']
DEBUG: write: AT+CMGF=0
DEBUG: response: [u'OK']
DEBUG: write: AT+CSCA?
DEBUG: response: [u'+CSCA: "002B00330033003600390035003000300030003600390035",145', u'OK']
DEBUG: write: AT+CSMP=49,167,0,0
DEBUG: response: [u'OK']
DEBUG: write: AT+CSCA?
DEBUG: response: [u'+CSCA: "002B00330033003600390035003000300030003600390035",145', u'OK']
DEBUG: write: AT+CPMS=?
DEBUG: response: [u'+CPMS: ("SM","ME"),("SM","ME"),("SM","ME")', u'OK']
DEBUG: write: AT+CPMS="ME","ME","ME"
DEBUG: response: [u'+CPMS: 0,20,0,20,0,20', u'OK']
DEBUG: write: AT+CNMI=2,1,0,2
DEBUG: response: [u'OK']
DEBUG: write: AT+CLIP=1
DEBUG: response: [u'OK']
DEBUG: write: AT+CRC=1
DEBUG: response: [u'OK']
DEBUG: write: AT+CVHU=0
DEBUG: response: [u'ERROR']
DEBUG: write: AT+CMGL=4
DEBUG: response: [u'OK']
0 messages found
Waiting for new SMS message...
我只在 python-gsmmodem 为 运行 时收到消息,我无法阅读之前收到的消息...
我也试过 processStoredSms() 但没有附加内容。
谢谢
自我回答:我创建了这个脚本,它可以读取所有长短信和短短信,也可以读取内存中的旧短信。
README 中的更多信息:https://gist.github.com/stevecohenfr/8d3908da4ed39169992e407261f4c0e6
我尝试读取收到的短信,而 python-gsmmodem 不是 运行 但无法使其工作...
==调制解调器信息==
厂商:华为 型号:E3531 修订:22.521.31.00.400
这是我的 python 代码:
#!/usr/bin/env python
from __future__ import print_function
from datetime import datetime
from gsmmodem.modem import GsmModem, Sms
import logging
PORT = '/dev/ttyUSB0'
BAUDRATE = 115200
PIN = None # SIM card PIN (if any)
def handleSms(sms):
print(u'== SMS message received ==\nFrom: {0}\nTime: {1}\nMessage:\n{2}\n'.format(sms.number, sms.time, sms.text))
def main():
print('Initializing modem...')
# Uncomment the following line to see what the modem is doing:
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
modem = GsmModem(PORT, BAUDRATE, smsReceivedCallbackFunc=handleSms)
modem.smsTextMode = False
modem.connect(PIN)
#modem.processStoredSms(False)
smss = modem.listStoredSms(status=Sms.STATUS_ALL, delete=True);
print(str(len(smss)) + ' messages found')
for i in range(len(smss)):
sms = smss[i]
handleSms(sms)
print('Waiting for new SMS message...')
try:
modem.rxThread.join(2**31) # Specify a (huge) timeout so that it essentially blocks indefinitely, but still receives CTRL+C interrupt signal
finally:
modem.close();
if __name__ == '__main__':
main()
这是日志:
Initializing modem...
INFO: Connecting to modem on port /dev/ttyUSB0 at 115200bps
DEBUG: write: ATZ
DEBUG: response: [u'OK']
DEBUG: write: ATE0
DEBUG: response: [u'OK']
DEBUG: write: AT+CFUN?
DEBUG: response: [u'+CFUN: 1', u'OK']
DEBUG: write: AT+CMEE=1
DEBUG: response: [u'OK']
DEBUG: write: AT+CPIN?
DEBUG: response: [u'+CPIN: READY', u'OK']
DEBUG: write: AT+CLAC
DEBUG: write: AT
DEBUG: response: [u'OK']
DEBUG: write: AT^CVOICE=?
DEBUG: response: [u'^CVOICE: (0)', u'OK']
DEBUG: write: AT+VTS=?
DEBUG: response: [u'+VTS: (0-9,A-D,*,#)', u'OK']
DEBUG: write: AT^DTMF=?
DEBUG: response: [u'ERROR']
DEBUG: write: AT^USSDMODE=?
DEBUG: response: [u'^USSDMODE: (0-1)', u'OK']
DEBUG: write: AT+WIND=?
DEBUG: response: [u'ERROR']
DEBUG: write: AT+ZPAS=?
DEBUG: response: [u'ERROR']
DEBUG: write: AT+CSCS=?
DEBUG: response: [u'+CSCS: ("IRA","UCS2","GSM")', u'OK']
DEBUG: write: AT+CNUM=?
DEBUG: response: [u'OK']
DEBUG: write: AT^CVOICE=0
DEBUG: response: [u'ERROR']
DEBUG: write: AT^USSDMODE=0
DEBUG: response: [u'OK']
DEBUG: write: AT+CGMI
DEBUG: response: [u'huawei', u'OK']
DEBUG: write: AT+CGMI
DEBUG: response: [u'huawei', u'OK']
INFO: Loading Huawei call state update table
DEBUG: write: AT+COPS=3,0
DEBUG: response: [u'OK']
DEBUG: write: AT+CMGF=0
DEBUG: response: [u'OK']
DEBUG: write: AT+CSCA?
DEBUG: response: [u'+CSCA: "002B00330033003600390035003000300030003600390035",145', u'OK']
DEBUG: write: AT+CSMP=49,167,0,0
DEBUG: response: [u'OK']
DEBUG: write: AT+CSCA?
DEBUG: response: [u'+CSCA: "002B00330033003600390035003000300030003600390035",145', u'OK']
DEBUG: write: AT+CPMS=?
DEBUG: response: [u'+CPMS: ("SM","ME"),("SM","ME"),("SM","ME")', u'OK']
DEBUG: write: AT+CPMS="ME","ME","ME"
DEBUG: response: [u'+CPMS: 0,20,0,20,0,20', u'OK']
DEBUG: write: AT+CNMI=2,1,0,2
DEBUG: response: [u'OK']
DEBUG: write: AT+CLIP=1
DEBUG: response: [u'OK']
DEBUG: write: AT+CRC=1
DEBUG: response: [u'OK']
DEBUG: write: AT+CVHU=0
DEBUG: response: [u'ERROR']
DEBUG: write: AT+CMGL=4
DEBUG: response: [u'OK']
0 messages found
Waiting for new SMS message...
我只在 python-gsmmodem 为 运行 时收到消息,我无法阅读之前收到的消息... 我也试过 processStoredSms() 但没有附加内容。
谢谢
自我回答:我创建了这个脚本,它可以读取所有长短信和短短信,也可以读取内存中的旧短信。
README 中的更多信息:https://gist.github.com/stevecohenfr/8d3908da4ed39169992e407261f4c0e6