python-gsmmodem读取旧短信

问题描述 投票:1回答:1

我尝试读取在python-gsmmodem未运行但无法正常工作时收到的SMS ...

==调制解调器信息==

制造商:华为型号: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(),但没有追加。

谢谢

python gsm at-command
1个回答
0
投票

自我回答:我创建了此脚本,该脚本可以读取所有长短短信,还可以读取内存中的旧短信。

自述文件中的更多信息:https://gist.github.com/stevecohenfr/8d3908da4ed39169992e407261f4c0e6

© www.soinside.com 2019 - 2024. All rights reserved.