gpt4 book ai didi

python-gsmmodem 读取旧短信

转载 作者:太空宇宙 更新时间:2023-11-03 20:32:52 25 4
gpt4 key购买 nike

我尝试读取 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() 但没有任何附加内容。

谢谢

最佳答案

self 回答:我创建了这个脚本,它可以读取所有长短信和短短信,还可以读取内存中的旧短信。

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

关于python-gsmmodem 读取旧短信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57372174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com