Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

individual get_sms gives 'IndexError: list index out of range' Python 3.9 #2

Open
ghost opened this issue Jul 29, 2023 · 1 comment

Comments

@ghost
Copy link

ghost commented Jul 29, 2023

Getting really odd behaviour with the get_sms() function.

[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sim_modem import Modem
>>> modem = Modem('/dev/ttyUSB3')
>>> modem_id = modem.get_model_identification()
>>> print(modem_id)
SIMCOM_SIM7600G-H
>>> sms = modem.get_sms(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/dist-packages/sim_modem.py", line 655, in get_sms
    "slot": read[1].split(":")[1].split(",")[0].strip(),
IndexError: list index out of range
>>> sms = modem.get_sms(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/dist-packages/sim_modem.py", line 655, in get_sms
    "slot": read[1].split(":")[1].split(",")[0].strip(),
IndexError: list index out of range

When I add the debug output (I've obviously redacted the phone number - but that is all I have done):

>>> modem = Modem('/dev/ttyUSB3', baudrate="115200", debug=True)
Modem connected, debug mode enabled
>>> sms = modem.get_sms_list()
Sending: AT+CMGF=1
Sending: AT+CMGL="ALL"
Device responded:  ['AT+CMGF=1', 'OK', 'AT+CMGL="ALL"', '+CMGL: 0,"REC READ","+************ ","","23/07/29,05:01:03+04"', '3rd Test Message Sent', '+CMGL: 1,"REC READ","+************ ","","23/07/29,05:04:04+04"', '4th test sms... this has to work', '+CMGL: 2,"REC READ","+************ ","","23/07/29,05:10:02+04"', "5th test. PLEASE python don't fail me now.", '+CMGL: 3,"REC READ","+************ ","","23/07/29,05:23:57+04"', "6th, this is a tad annoting why the code isn't working properly", '+CMGL: 4,"REC READ","+************ ","","23/07/29,05:30:17+04"', 'possibly final test for today', '', 'OK']
>>> sms = modem.get_sms(1)
Sending: AT+CMGF=1
Sending: AT+CMGR=1
Device responded:  ['AT+CMGF=1', 'OK', 'AT+CMGR=1', '+CMGR: "REC READ","+************ ","","23/07/29,05:04:04+04"', '4th test sms... this has to work', '', 'OK']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/dist-packages/sim_modem.py", line 655, in get_sms
    "slot": read[1].split(":")[1].split(",")[0].strip(),
IndexError: list index out of range

I can't decipher all the splits in the return section:

return {
            "slot": read[1].split(":")[1].split(",")[0].strip(),
            "number": read[1].split('READ","')[1].split('","","')[0],
            "date": read[1].split('","","')[1].split(",")[0],
            "time": read[1].split(",")[5].split("+")[0],
            "message": read[4].replace("\r\n", "").strip(),
        }

The kind of TL;DR is is does read the SMS from the module, but it seems, in python 3.9 at least, the convertion to a dict for the output no longer works as expected...

Firmware of module is: LE20B03SIM7600M22 (not that I can find much by way of reliable info on any newer versions - I'm not daft enough to download files from random website!)

@ghost
Copy link
Author

ghost commented Jul 30, 2023

I'm going to assume this is either difference in SIMCOM module firmware, or a slight variation of module meaning different AT outputs?

When using get_sms() the return of a slot value doesn't make much sense as you entered it into the function so returning it seems redundant.

So unless I'm really hugely missing something if I edit the return filters to be:

## output from modules AT command
read=['AT+CMGF=1', 'OK', 'AT+CMGR=1', '+CMGR: "REC READ","+************ ","","23/07/29,05:04:04+04"', '4th test sms... this has to work', '', 'OK']

return {
    "number": read[3].split(",")[1].strip('"'),
    "date": read[3].split(",")[3].strip('"'),
    "time": read[3].split(",")[4].split("+")[0],
    "message": read[4],
}

It should work with the AT outputs from my SIM7600G-H. I've only tested roughly will do more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants