Giter VIP home page Giter VIP logo

python-gsmmodem's People

Contributors

alejandroma avatar alex-eri avatar babca avatar bennyslbs avatar boomer74 avatar chakphanu avatar cyril-roques avatar damadmai avatar davidjb avatar epol avatar faucamp avatar ffix avatar havefunworkhard avatar isidroamv avatar jeromez80 avatar lcnittl avatar lucasea777 avatar malanovo avatar nioq avatar ohidurbappy avatar paolo-losi avatar petelawler avatar phreaker0 avatar shaljam avatar tahajahangir avatar tomchy avatar youtux avatar yuriykashin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-gsmmodem's Issues

Missing getter for SIM Own Number

I miss a property phone_number or number or something like that what will represent number of sim in network. I think it would be usefull.

Lot of modems support command AT+CNUM
if it will return just OK the number is missing in own number phonebook
so we will have to write it to own number phonebook and then AT+CNUM it should work

Or we can read it from the phonebook
Select ON in PB -> AT+CPBS="ON"
Then read the first index -> `AT+CPBR=0``


see
http://www.multitech.com/support/resolutionid/5060063
https://developer.gemalto.com/tutorial/how-use-atcnum-query-own-number


def phone_number(self, default_phone_number= None):
    num = None
    if "AT+CNUM" in supported: # supported check
        resp = self.write('AT+CNUM')
        if resp is not "OK": # if is not only ok and number was returned - TODO
            num = resp
    else:
        actual_phonebook = self.write('AT+CPBS?')
        if actual_phonebook is not "ON": 
            self.write('AT+CPBS="ON"')
        try:
            num = self.write("AT+CPBR=0")
        expect Exception: # TODO Change to specific 
            num = None

    if num is None
        if default_phone_number is not None:
            self.set_phone_number(default_phone_number)
            num = default_phone_number
        else:
            raise Exception('Number not found')

    return num

def set_phone_number(self, phone_number):
    actual_phonebook = self.write('AT+CPBS?')
    if actual_phonebook is not "ON": 
        self.write('AT+CPBS="ON"')
    self.write('AT+CPBW=1,"' + phone_number + '"')  # TODO raise exceptions or something like that

pdu.py generates PDU with >160 encoded characters leading to invalid SMS

If you try to send a message under 160 character long, containing some characters which need to be escaped, it is possible that an invalid >160 char single message is generated. It then appears as an empty incoming message on my phone.

12345-010,12345-020,12345-030,12345-040,12345-050,12345-060,12345-070,12345-080,12345-090,12345-100,12345-110,12345-120,12345-130,12345-140,12345-150,[[[[[[[[

This string is 158 char long. It contains 8 brackets which need an escape character, so the real length of the message is 166 septets. It should be split into two SMS, but it isn't.

How to quickly reproduce:

  1. open examples/sms_handler_demo.py
  2. replace sms.reply.... (line 23) with a static string
    sms.reply('12345-010,12345-020,12345-030,12345-040,12345-050,12345-060,12345-070,12345-080,12345-090,12345-100,12345-110,12345-120,12345-130,12345-140,12345-150,[[[[[[[[')
  3. save, start, send sms to modem and wait for the response.
  4. my phone receives an empty message
  5. copy generated PDU message here: http://rednaxela.net/pdu.php and check the contents by decoding it. It shows something like this:
    123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,12345-100,12345-110,12345-120,12345-130,12345-140,12345-150,€<€<€<€<€<€<€<€< Length:166

The example in ussd is not working. Not getting ussd response

This the error am gettings.

/Users/francis/PycharmProjects/python-gsmmodem/.venv/bin/python /Users/francis/PycharmProjects/python-gsmmodem/examples/ussd_demo.py
Initializing modem...
Sending USSD string: 1405*0702729654#
Traceback (most recent call last):
File "/Users/francis/PycharmProjects/python-gsmmodem/examples/ussd_demo.py", line 41, in
main()
File "/Users/francis/PycharmProjects/python-gsmmodem/examples/ussd_demo.py", line 30, in main
response = modem.sendUssd(USSD_STRING) # response type: gsmmodem.modem.Ussd
File "/Users/francis/PycharmProjects/python-gsmmodem/gsmmodem/modem.py", line 946, in sendUssd
raise TimeoutException()
gsmmodem.exceptions.TimeoutException: None

modem.connect() does not work with Python 3

Here is my code:
`
from gsmmodem.modem import GsmModem
import logging

if name == 'main':
port = '/dev/ttyUSB0'
baud_rate = 115200
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
modem = GsmModem(port, baud_rate)

try:
    modem.connect()
    modem.waitForNetworkCoverage(10)
except Exception as e:
    print('Failed to connect the modem: ' + str(e))
    if modem.alive:
        modem.close()
else:
    print('Connected!')
    if modem.alive:
        modem.close()

`
Run it with python 3.6:
INFO: Connecting to modem on port /dev/ttyUSB0 at 115200bps
DEBUG: write: ATZ
Failed to connect the modem: None

Run it with python 2.7:
INFO: Connecting to modem on port /dev/ttyUSB0 at 115200bps
DEBUG: write: ATZ
DEBUG: response: ['ATZ\r', 'OK']
DEBUG: write: ATE0
DEBUG: response: ['ATE0\r', 'OK']
DEBUG: write: AT+CFUN?
DEBUG: response: ['+CFUN: 1', 'OK']
DEBUG: write: AT+CMEE=1
DEBUG: response: ['OK']
DEBUG: write: AT+CPIN?
DEBUG: response: ['+CPIN: READY', 'OK']
DEBUG: write: AT+CLAC
DEBUG: response: ['+CME ERROR: 100']
DEBUG: write: AT+WIND?
DEBUG: response: ['+CME ERROR: 100']
DEBUG: write: AT+CGMI
DEBUG: response: ['+CGMI: COMWAY', 'OK']
DEBUG: write: AT+ZPAS?
DEBUG: response: ['+CME ERROR: 100']
INFO: Unknown/generic modem type - will use polling for call state updates
DEBUG: write: AT+COPS=3,0
DEBUG: response: ['OK']
DEBUG: write: AT+CMGF=0
DEBUG: response: ['OK']
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CSCA: "8613800100500", 145', 'OK']
DEBUG: write: AT+CSMP=49,167,0,0
DEBUG: response: ['OK']
DEBUG: write: AT+CPMS=?
DEBUG: response: ['+CPMS: ("SM", "ME", "SM_P", "ME_P", "MT"), ("SM", "ME", "SM_P", "ME_P", "MT"), ("SM", "ME", "SM_P", "ME_P", "MT")', 'OK']
DEBUG: write: AT+CPMS="ME"
DEBUG: response: ['+CPMS: 0, 100, 3, 50, 3, 50', 'OK']
DEBUG: write: AT+CNMI=2,1,0,2
DEBUG: response: ['ERROR']
WARNING: Incoming SMS notifications not supported by modem. SMS receiving unavailable.
DEBUG: write: AT+CLIP=1
DEBUG: response: ['OK']
DEBUG: write: AT+CRC=1
DEBUG: response: ['OK']
DEBUG: write: AT+CVHU=0
DEBUG: response: ['OK']
DEBUG: write: AT+CREG?
DEBUG: response: ['+CREG: 0, 1', 'OK']
INFO: +CREG check disabled due to invalid response or unsupported command
DEBUG: write: AT+CSQ
DEBUG: response: ['+CSQ: 8, 99', 'OK']
Connected!

test_connect.txt

Use Unicode instead of Bytes in modem.py and only use Bytes inside SerialComms.write()

Find a better solution for d7ac128

lucasea777 wrote:

As far as I know, there is no way to properly use .format() with Bytes without using .decode().
Maybe it is possible to use Unicode instead of Bytes in modem.py and only use Bytes inside SerialComms.write(), which in my opinion would lead to a much cleaner solution, but it might require more changes.
Also it might be better to carefully use .decode() before .format() only when necessary.
I can keep this changes in my fork until a better solution is found.

Source: #8

Failed to send SMS with the sample code

May I know what is going wrong?
The SIM card can get a network and send a SMS with a phone.
Ths GSM modem is using SIMCOM SIM800C chip.
Thanks.

$ sudo python3 tools/sendsms.py -i /dev/ttyUSB0 85212345678 test --debug
Connecting to GSM modem on /dev/ttyUSB0...
INFO: Connecting to modem on port /dev/ttyUSB0 at 115200bps
DEBUG: write: ATZ
DEBUG: response: ['OK']
DEBUG: write: ATE0
DEBUG: response: ['ATE0\r', 'OK']
DEBUG: write: AT+CFUN?
DEBUG: response: ['+CFUN: 1', 'OK']
DEBUG: write: AT+CMEE=1
DEBUG: response: ['OK']
DEBUG: write: AT+CPIN?
DEBUG: response: ['+CPIN: READY', 'OK']
DEBUG: write: AT+CLAC
DEBUG: response: ['+CME ERROR: 100']
DEBUG: write: AT
DEBUG: response: ['OK']
DEBUG: write: AT^CVOICE=?
DEBUG: response: ['+CME ERROR: 100']
DEBUG: write: AT+VTS=?
DEBUG: response: ['+VTS: (0-9,*,#,A,B,C,D),(1-255)', 'OK']
DEBUG: write: AT^DTMF=?
DEBUG: response: ['+CME ERROR: 100']
DEBUG: write: AT^USSDMODE=?
DEBUG: response: ['+CME ERROR: 100']
DEBUG: write: AT+WIND=?
DEBUG: response: ['+CME ERROR: 100']
DEBUG: write: AT+ZPAS=?
DEBUG: response: ['+CME ERROR: 100']
DEBUG: write: AT+CSCS=?
DEBUG: response: ['+CSCS: ("IRA","GSM","UCS2","HEX","PCCP","PCDN","8859-1")', 'OK']
DEBUG: write: AT+CNUM=?
DEBUG: response: ['OK']
DEBUG: write: AT+CGMI
DEBUG: response: ['SIMCOM_Ltd', 'OK']
DEBUG: write: AT+DDET=1
DEBUG: response: ['OK']
DEBUG: write: AT+CGMI
DEBUG: response: ['SIMCOM_Ltd', 'OK']
DEBUG: write: AT+ZPAS?
DEBUG: response: ['+CME ERROR: 100']
INFO: Unknown/generic modem type - will use polling for call state updates
DEBUG: write: AT+COPS=3,0
DEBUG: response: ['OK']
DEBUG: write: AT+CMGF=0
DEBUG: response: ['OK']
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CSCA: "+85290100000",145', 'OK']
DEBUG: write: AT+CSMP=49,167,0,0
DEBUG: response: ['OK']
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CSCA: "+85290100000",145', 'OK']
DEBUG: write: AT+CPMS=?
DEBUG: response: ['+CPMS: ("SM","ME","SM_P","ME_P","MT"),("SM","ME","SM_P","ME_P","MT"),("SM","ME","SM_P","ME_P","MT")', 'OK']
DEBUG: write: AT+CPMS="ME","ME","ME"
DEBUG: response: ['+CPMS: 0,20,0,20,0,20', 'OK']
DEBUG: write: AT+CNMI=2,1,0,2
DEBUG: response: ['+CMS ERROR: 325']
DEBUG: write: AT+CNMI=2,1,0,1,0
DEBUG: response: ['OK']
DEBUG: write: AT+CLIP=1
DEBUG: response: ['OK']
DEBUG: write: AT+CRC=1
DEBUG: response: ['OK']
DEBUG: write: AT+CVHU=0
DEBUG: response: ['OK']
Checking for network coverage...
DEBUG: write: AT+CREG?
DEBUG: response: ['+CREG: 0,1', 'OK']
DEBUG: write: AT+CSQ
DEBUG: response: ['+CSQ: 25,0', 'OK']

Sending SMS message...
DEBUG: write: AT+CSCS=?
DEBUG: response: ['+CSCS: ("IRA","GSM","UCS2","HEX","PCCP","PCDN","8859-1")', 'OK']
DEBUG: write: AT+CSCS="GSM"
DEBUG: response: ['OK']
DEBUG: write: AT+CMGS=17
DEBUG: response: ['> ']
DEBUG: write: 0021000BA15862030969F0000004F4F29C0E
DEBUG: response: ['+CMS ERROR: 38']
Traceback (most recent call last):
File "tools/sendsms.py", line 116, in
main()
File "tools/sendsms.py", line 58, in main
send_sms(args)
File "tools/sendsms.py", line 103, in send_sms
sms = modem.sendSms(args.destination, text, waitForDeliveryReport=args.deliver)
File "/home/y2kbug/.local/lib/python3.6/site-packages/gsmmodem/modem.py", line 924, in sendSms
result = lineStartingWith('+CMGS:', self.write(str(pdu), timeout=35, writeTerm=CTRLZ)) # example: +CMGS: xx
File "/home/y2kbug/.local/lib/python3.6/site-packages/gsmmodem/modem.py", line 486, in write
raise CmsError(data, int(errorCode))
gsmmodem.exceptions.CmsError: CMS 38

Potential Race in listStoredSms with delete=True

In the normal course of listStoredSms getting the messages, then deleting them, there is a window when a message that has arrived could be deleted before it is read:

DEBUG:gsmmodem.modem.GsmModem:write: AT+CMGL=4
DEBUG:gsmmodem.modem.GsmModem:response: [u'OK']
<No Messages were read, but a Message arrives here>
DEBUG:gsmmodem.modem.GsmModem:write: AT+CMGD=1,4
<Message that arrived was deleted before it was read>

Iridium satellite phone issues

Attempting to use gsmmodem with Iridium units (9505(A), 9522, 9555) leaves the connect() method hanging in _unlockPin() and various other places; it looks like the Iridium responses are non-standard enough to cause problems.

Fixing this inline in the existing connect() method looks complicated and might cause problems for existing users, and it seems like it might be better to create an iridiummodem subclass to override connect() and also provide other Iridium-specific functionality; I have a working prototype that could be added into this project if you think it worthwhile?

Obviously I don't mind doing the work and testing the end result with various Iridium handsets and other equipment, but thought it worthwhile asking first :)

Intermittent problems while communicating with pi 3

Hello All,

Apologies in advance. This is most likely not an issue with this python module, but I am hoping to some help here. Also if such problems are regular with hardware, I wonder if we can somehow make the software more robust.

I am interfacing a SIM800 GSM module with Pi 3 over serial ports (pins 6, 8, 10). While things work OK most of the time, every now and then I get spurious characters in the response. For example, I get:

['+CLCC: 1,0,2,0,0,"+919812x\x9c\xd3\x13\x93\x93\x12)\xa25,""', 'OK']

whereas the expected response is:

['+CLCC: 1,0,2,0,0,"+919812012321,""', 'OK']

As I said, this happens once in a while (may be 1 in 10) and happens with other commands too. Also, this is not the only GSM module or Pi having the problem. So very unlikely hardware issue, unless the GSM module is buggy. The GSM module in question is this http://www.rhydolabz.com/wiki/?p=10450

The baudrate is set to 9600.

What could be going wrong? Could it be bad connections? I usually crimp dupont connectors to the open ends of the cable supplied with the modem. As far as I can tell, the crimps are decently done. How do I fix this?

Thanks,
Pavan

Asyncio version

Hi. Is there a plan to add asyncio features to the library ? or is there a way to use pyserial async version for fast asynchronous work

openwrt

Hi,
do you think that python-gsmmodem work fine on a device with openwrt?
BR

About handling several consecutive texts/sms?

I'm currently testing by sending several texts to the gsm modem (at most 7 at a time), and I think it ruins the threads resulting in TimeoutExceptions. Anyone also experiencing this/tried this?

Sample error:
File "C:\Users\User\Anaconda3\lib\site-packages\gsmmodem\modem.py", line 1354, in _handleSmsReceived
self.smsReceivedCallback(sms)
File "main.py", line 24, in handleSms
sms.reply("Reply: "+sms.text)
File "C:\Users\User\Anaconda3\lib\site-packages\gsmmodem\modem.py", line 66, in reply
...return self._gsmModem.sendSms(self.number, message)
File "C:\Users\User\Anaconda3\lib\site-packages\gsmmodem\modem.py", line 902, in sendSms
...result = lineStartingWith('+CMGS:', self.write(text, timeout=35, writeTerm=CTRLZ))
File "C:\Users\User\Anaconda3\lib\site-packages\gsmmodem\modem.py", line 458, in write
...responseLines = super(GsmModem, self).write(data + writeTerm, waitForResponse=waitForResponse, timeout=timeout, expectedResponseTermSeq=expectedResponseTermSeq)
File "C:\Users\User\Anaconda3\lib\site-packages\gsmmodem\serial_comms.py", line 144, in write
...raise TimeoutException()

P.S.:
Unless, several text messages at once is too much for a gsm modem to handle?

Getting an SMS index/SMS deletion

Greetings.

I would like to know if there is any possible way to get the SMS's index, preferably by using ReceivedSms object. I want to do it mainly for SMS deletion (the idea is that I read an SMS, process it and, afterwards, delete it). Indexes are dynamic and I can't surely predict which index corresponds to which message. If there is another convenient way to delete an SMS by using ReceivedSms object - that would suffice, too.

Thank you!

Timeout exception thrown when a long message with non-English chars included

Hi, nice to see the project live again.

I found that when i send the message to the modem with a long message with different language, English + Non-English,

Exception in thread Thread-3:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/var/www/gsmmodem/modem.py", line 1093, in __threadedHandleModemNotification
    self._handleSmsReceived(line)
  File "/var/www/gsmmodem/modem.py", line 1254, in _handleSmsReceived
    sms = self.readStoredSms(msgIndex, msgMemory)
  File "/var/www/gsmmodem/modem.py", line 1324, in readStoredSms
    msgData = self.write('AT+CMGR={0}'.format(index))
  File "/var/www/gsmmodem/modem.py", line 465, in write
    responseLines = super(GsmModem, self).write(data + writeTerm, waitForResponse=waitForResponse, timeout=timeout, expectedResponseTermSeq=expectedResponseTermSeq)
  File "/var/www/gsmmodem/serial_comms.py", line 144, in write
    raise TimeoutException()
TimeoutException: None

It seems that nth can be read in the _readLoop and thus the timeout. Any ideas?

Updates:
It works when I set the textmode to True, however, I need to decode the PDU manually.

ValueError: invalid literal for int() with base 10: '250,0'

Hello,

Unfortunately, I can’t tell the modem yet.
One thing I know is chinese on 16 ports.

def main():
    d=0
    p=24
    max_ports=30
    imsin = ''
    path = Path(__file__).parent.absolute()
    while d < max_try:
        while p < max_ports:
            print('try ',p, ' :port; ')
            PORT = 'COM'+str(p)
            logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
            modem = GsmModem(PORT, BAUDRATE, smsReceivedCallbackFunc=handleSms)
            modem.connect(PIN)
            modem.rxThread.join(2**8)
            modem.close();
            p += 1
        d += 1
try  24  :port;
INFO: Connecting to modem on port COM24 at 115200bps
DEBUG: write: ATZ
DEBUG: response: ['OK']
DEBUG: write: ATE0
DEBUG: response: ['ATE0\r', 'OK']
DEBUG: write: AT+CFUN?
DEBUG: response: ['+CFUN: 1', 'OK']
DEBUG: write: AT+CMEE=1
DEBUG: response: ['OK']
DEBUG: write: AT+CPIN?
DEBUG: response: ['+CPIN: READY', 'OK']
DEBUG: write: AT+CLAC
DEBUG: response: ['+CME ERROR: 100']
DEBUG: write: AT
DEBUG: response: ['OK']
DEBUG: write: AT^CVOICE=?
DEBUG: response: ['+CME ERROR: 100']
DEBUG: write: AT+VTS=?
DEBUG: response: ['+VTS: (0-9,*,#,A,B,C,D),,(1-255)', 'OK']
DEBUG: write: AT^DTMF=?
DEBUG: response: ['+CME ERROR: 100']
DEBUG: write: AT^USSDMODE=?
DEBUG: response: ['+CME ERROR: 100']
DEBUG: write: AT+WIND=?
DEBUG: response: ['+WIND: (250,257)[,(0,1)]', 'OK']
DEBUG: write: AT+ZPAS=?
DEBUG: response: ['+CME ERROR: 100']
DEBUG: write: AT+CSCS=?
DEBUG: response: ['+CSCS: ("GSM","HEX","IRA","PCCP437","UCS2","8859-1")', 'OK']
DEBUG: write: AT+CNUM=?
DEBUG: response: ['OK']
DEBUG: write: AT+WIND?
DEBUG: response: ['+WIND: 250,0', 'OK']
Traceback (most recent call last):
  File "D:\yandex/sms_receive.py", line 75, in <module>
    main()
  File "D:\yandex/sms_receive.py", line 56, in main
    modem.connect(PIN)
  File "D:\yandex\Python38\lib\site-packages\gsmmodem\modem.py", line 268, in connect
    if int(wind[7:]) != 50:
ValueError: invalid literal for int() with base 10: '250,0'

Thanks

dsrdtr and rtscts usage are hardlocked

Would it better to pipe this settings to modem declaration (similar to baudrate and port)? Like so:
modem = GsmModem(PORT, BAUDRATE, dsrdtr=False, rtscts=False, smsReceivedCallbackFunc=handleSms)
My board has wire issue with dsrdtr and rtscts. So dsrdtr=False, rtscts=False help me. But I have to edit serial_comms.py file.

SMS-DELIVER `from` number decoding error

Hey, I've encountered strange bug while decoding some pdu's. I got EncodingError exception on some messages while the others are decoding normally. It seems that a problem is in a function nibble2octet:

def nibble2octet(o):
    if o % 2:
        return o / 2 + 1
    else:
        return o / 2

In Python 3 this function can produce float values. The value is used later in unpackSeptets and comparison with int breaks desired behavior. If it is simple python2->python3 migration issue, it can be fixed simply by return int(o / 2) + 1. Can somebody confirm that fix doesn't break anything else?

Optimze CLIP procedure

Concerning #20.

Previous and current CLIP-RegEx

CLIP_REGEX = re.compile('^\+CLIP:\s*"\+{0,1}(\d+)",(\d+).*$')

does not give a match if unknown number "" or any string (If possible?) is in caller ID. Furthermore, without match, ton cannot be parsed.

     if self._callingLineIdentification and len(lines) > 0:
        clipLine = lines.pop(0)
        clipMatch = self.CLIP_REGEX.match(clipLine)
        if clipMatch:
            callerNumber = '+' + clipMatch.group(1)
            ton = clipMatch.group(2)
            #TODO: re-add support for this
            callerName = None
            #callerName = clipMatch.group(3)
            #if callerName != None and len(callerName) == 0:
            #    callerName = None
        else:
            callerNumber = ton = callerName = None
    else:
            callerNumber = ton = callerName = None

Nevertheless, ton is not empty if the number string is (f.e. if an unknown number is calling). My SIM800 module gives this response

+CLIP: "",128,"",0,"",1

when an unknown number is calling. So at least in this case tonis not at all None, as set currently.

Would it be better to change the RegEx to '^\+CLIP:\s*".*)",(\d+).*$' (Can handle strings as well) so that it always matches, and ton can then be used to distinguish between different types of numbers.

The SIM800 series command manual (v1.01) states:
129 Unknown Type
161 National Number Type
145 International Number Type
177 Network Specific Number

This information might be used for either prepanding the plus sign (for Intl Numbers) or not (Maybe National Number Type does no have the plus sign, unfortunately I can't find any info about this). If the response is 128, 'unknown Number' might be returned instead of the current None

Sender ID in sms

This is not exactly an issue. I would like to know if I can play around the "OADC" or "sender ID" in order to display some name instead of the phone number. Related link.

Is there something already implemented or at least, are there some hints to do it?

Exception in _setSmsMemory

In _setSmsMemory (modem.py:715) self.write() with no argument cause TypeError exception:
TypeError: write() missing 1 required positional argument: 'data'

I think it's safe to remove empty self.write(), correct me if I'm wrong.

[new feature]web server

Hi,do you have a plan to make a simple gsmmodem web server?
I think it's a very good idea .Think about it ,you can send sms from you brower or make phone calls.

Invalid check if command is supported

Actual check

if "+CSCS" in self._commands

value in self._commands

[b'H', b'A', b'D', b'S0', b'S3', b'S4', b'S5', b'S6', b'S7', b'E', b'V', b'I', b'T', b'P', b'X', b'Z', b'Q', b'&C', b'&D', b'&F', b'+CMGS', b'+CMGW', b'+CMGR', b'+CMGL', b'+CMGC', b'+CMSS', b'+CNMA', b'+CSCS', b'+CMEE', b'+CREG', b'+CSDH', b'+CNMI', b'+CGREG', b'+CMMS', b'+CMGF', b'+CGSMS', b'+CSCA', b'+CSMS', b'+CSMP', b'+CPMS', b'+CMGD', b'+CSCB', b'^RSTRIGGER', b'+CLIP', b'+CLIR', b'+COLP', b'+CLCC', b'+CPAS', b'+CSTA', b'+CCUG', b'+CSSN', b'+CHLD', b'+CHUP', b'+VTS', b'^DTMF', b'+CRC', b'+CBST', b'+CMOD', b'^ALS', b'+CUUS1', b'^CDUR', b'+CGDCONT', b'+CGEQNEG', b'+CGDSCONT', b'+CGEQREQ', b'+CGEQMIN', b'+CGPADDR', b'+CGCMOD', b'+CGACT', b'+CGANS', b'+CGTFT', b'^CGDNS', b'+CGAUTO', b'+CGDATA', b'^TRIG', b'^GCFIND', b'+CGATT', b'^CGCATT', b'+COPS', b'+CGCLASS', b'+CFUN', b'+CGMI', b'+CGMM', b'+GMM', b'+CGMR', b'+CGSN', b'+GSN', b'+CIMI', b'+CSQ', b'^CBND', b'^CPDW', b'^HWVER', b'^HVER', b'^FHVER', b'^PFVER', b'+CLAC', b'^SN', b'+GCAP', b'^SRVST', b'^MODE', b'^SIMST', b'^HS', b'+CPLS', b'+CPOL', b'+CPBS', b'^CPBR', b'+CPBR', b'^CPBW', b'+CPBW', b'^SCPBW', b'^SCPBR', b'+CNUM', b'+CPBF', b'+CSIM', b'+CPIN', b'^ICCID', b'^CPIN', b'+CRSM', b'^PNN', b'^CPNN', b'^OPL', b'^CARDLOCK', b'+CCWA', b'+CCFC', b'+CUSD', b'^CMLCK', b'+CLCK', b'+CPWD', b'^CDSF', b'^CDCF', b'^CDQF', b'^DSFLOWCLR', b'^DSFLOWQRY', b'^DSFLOWRPT', b'^CPAM', b'^TIME', b'+CTZR', b'^STSF', b'^STGI', b'^STGR', b'^IMSICHG', b'^PDPSTUB', b'^CWAS', b'^CGAS', b'^MFREELOCKSIZE', b'^CPULOAD', b'^CELLINFO', b'^MEANRPT', b'^CCC', b'^SPN', b'^CARDMODE', b'^CURC', b'^CMSR', b'^CMGI', b'^CMMT', b'^AUTHDATA', b'^DHCP', b'^CRPN', b'^GLASTERR', b'^NDISDUP', b'^NDISCONN', b'^NDISSTATQRY', b'^NDISADD', b'^DNSP', b'^DNSS', b'^DLOADVER', b'^DLOADINFO', b'^NVBACKUP', b'^NVRESTORE', b'^AUTHORITYVER', b'^AUTHORITYID', b'^GODLOAD', b'^RESET', b'^NVRSTSTTS', b'^FLASHINFO', b'^COMM', b'^HSPA', b'^CSNR', b'^FREQLOCK', b'^CFPLMN', b'^CQST', b'^CAATT', b'^SYSINFO', b'^SYSCFG', b'^RXDIV', b'^PCSCINFO', b'^CELLSRCH', b'+CLVL', b'^VMSET', b'^CDTMFS', b'^CDTMFE', b'+GMI', b'+GMR', b'^SETPORT', b'^VERTIME', b'^APHPLMN', b'^ANQUERY', b'^APPWRONREG', b'^APTHROUGHPUT', b'^APCONNST', b'^WIFIGLOBALMAC', b'^SCID', b'+CSQLVL', b'^CSQLVLEXT', b'^APPDMVER', b'^AUTHVER', b'^IPV6CAP', b'^DHCPV6', b'^APRAINFO', b'^APLANADDR']

As you can see +CSCS is supported

but in array is as bytes
but checking is strig
so return is its not supported

Also with CNUM

so controls should be

if b'+CSCS' in self._commands
if b'+CNUM' in self._commands

Unable to read old messages

Hi,

I try to read SMS received while python-gsmmodem was not running but not able to make it work...

#!/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()

Here are the logs :

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...

I only receive message when python-gsmmodem is running and I'm unable to read messages that I received before...
I also tried processStoredSms() but nothing append.

Thanks

How to send in HEX format?

My GSM Modem doesn't support UCS-2 but HEX. I have been using a C# app, converted it to PDU and then sent used AT commands to send SMS through serial port.

This library seems more reliable but I can't seem to get this working with HEX. When I try to send like emojis the application dies.

I guess I was close but this library always tries to encode the messages as UCS-2

Am I missing something here?

encoding error on handling status report

DEBUG: write: AT+CMGS=28
DEBUG: response: ['> ']
DEBUG: write: 0021000E91269835751694980000105479D83D0FAFE769D0BCBE9E97E7
DEBUG: response: ['+CMGS: 35', 'OK']
DEBUG: notification: ['+CDSI: "SR",19']
DEBUG: SMS status report received
DEBUG: write: AT+CPMS="SR"
DEBUG: response: ['+CPMS: 19,50,50,50', 'OK']
DEBUG: write: AT+CMGR=19
DEBUG: response: ['+CMGR: 1,,26', '0006230E9126983575169498610103409544C26101034095448200', 'OK']
Exception in thread Thread-3:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "build/bdist.linux-armv7l/egg/gsmmodem/modem.py", line 1106, in __threadedHandleModemNotification
    self._handleSmsStatusReport(line)
  File "build/bdist.linux-armv7l/egg/gsmmodem/modem.py", line 1274, in _handleSmsStatusReport
    report = self.readStoredSms(msgIndex, msgMemory)
  File "build/bdist.linux-armv7l/egg/gsmmodem/modem.py", line 1360, in readStoredSms
    smsDict = decodeSmsPdu(pdu)
  File "build/bdist.linux-armv7l/egg/gsmmodem/pdu.py", line 412, in decodeSmsPdu
    result['time'] = _decodeTimestamp(pduIter)
  File "build/bdist.linux-armv7l/egg/gsmmodem/pdu.py", line 498, in _decodeTimestamp
    return datetime.strptime(dateStr[:-2], '%y%m%d%H%M%S').replace(tzinfo=SmsPduTzInfo(timeZoneStr))
  File "build/bdist.linux-armv7l/egg/gsmmodem/pdu.py", line 60, in __init__
    self._setPduOffsetStr(pduOffsetStr)
  File "build/bdist.linux-armv7l/egg/gsmmodem/pdu.py", line 66, in _setPduOffsetStr
    self._offset = timedelta(minutes=(int(pduOffsetStr) * 15))
ValueError: invalid literal for int() with base 10: '2c'

USSD responce dont convert

i get my number use USSD response, and get in Cyrillic char-set, but don't decode

i resolve this problem use this hack:

        try:
            msg = binascii.unhexlify(original_message).decode('utf-16-be')
            out('Use decode utf-16-be')
        except:
            msg = original_message
            out('Use decode plain')

are this hack correct?

Timeout for CPIN command may be too short?

Increase timeout when checking the PIN.
cpinResponse = lineStartingWith('+CPIN', self.write('AT+CPIN?', timeout=0.25))
original issue: faucamp#50

currently: 0.25 sec
new value: 15 sec

Ubuntu networkmanager uses 15 sec timeout:

After looking in the bowls of modem-manager, I found the line which creates this request. Adjusting the timeout (I chose 15 seconds) fixes the problem. Very simple patch attached.

This probably needs investigating as to whether the timeout for all pin checks or sets needs to be increased. I suspect that this delay is a security feature to prevent brute forcing the pin.

source:
https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/607517
https://launchpadlibrarian.net/52187509/CPIN-timeout.patch

MMS Support

Hi, I saw your application and I was wondering if you could also implement a way to send MMSs as well. Thank you!

sms encoding error when trying to send sms

DEBUG: write: ATZ
DEBUG: response: ['ATZ\r', 'OK']
DEBUG: write: ATE0
DEBUG: response: ['ATE0\r', 'OK']
DEBUG: write: AT+CFUN?
DEBUG: response: ['+CFUN: 1', 'OK']
DEBUG: write: AT+CMEE=1
DEBUG: response: ['OK']
DEBUG: write: AT+CPIN?
DEBUG: write: AT+CLAC
DEBUG: response: ['ERROR']
DEBUG: write: AT+WIND?
DEBUG: response: ['+WIND: 50', 'OK']
INFO: Loading Wavecom call state update table
DEBUG: write: AT+COPS=3,0
DEBUG: response: ['OK']
DEBUG: write: AT+CMGF=0
DEBUG: response: ['OK']
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CSCA: "+6289644000001",145', 'OK']
DEBUG: write: AT+CSMP=49,167,0,0
DEBUG: response: ['OK']
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CSCA: "+6289644000001",145', 'OK']
DEBUG: write: AT+CPMS=?
DEBUG: response: ['+CPMS: (("SM","BM","SR"),("SM"))', 'OK']
DEBUG: write: AT+CPMS="SM","SM"
DEBUG: response: ['+CPMS: 36,50,36,50', 'OK']
DEBUG: write: AT+CLIP=1
DEBUG: response: ['OK']
DEBUG: write: AT+CRC=1
DEBUG: response: ['OK']
DEBUG: write: AT+CVHU=0
DEBUG: response: ['ERROR']
DEBUG: write: AT+CLAC
DEBUG: response: ['ERROR']
Process Process-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(_self._args, *_self._kwargs)
File "sendsms.py", line 32, in modemp
sms = modem.sendSms("0895357614989", "test aja", waitForDeliveryReport=True, deliveryTimeout=60)
File "build/bdist.linux-armv7l/egg/gsmmodem/modem.py", line 829, in sendSms
self.smsEncoding = 'GSM'
File "build/bdist.linux-armv7l/egg/gsmmodem/modem.py", line 677, in smsEncoding
if not '+CSCS' in self._commands:
TypeError: argument of type 'NoneType' is not iterable

tried AT+CSCS=? on gsmterm the return is

+CSCS: ("GSM","PCCP437","CUSTOM","HEX")
OK

i'm using raspberry pi 3
ubuntu mate
python 2.7.11
wavecom fastrack m1306b

Exception on last commit (6e69c26)

Getting exception on sendSms. The attribute _encoding must be _smsEncoding.

Traceback (most recent call last):
  File "/home/ali/test2.py", line 42, in <module>
    sms = modem.sendSms(destination, text, waitForDeliveryReport=deliver)
  File "/home/ali/.pyenv/versions/3.6.1/lib/python3.6/site-packages/python_gsmmodem_new-0.12-py3.6.egg/gsmmodem/modem.py", line 917, in sendSms
  File "/home/ali/.pyenv/versions/3.6.1/lib/python3.6/site-packages/python_gsmmodem_new-0.12-py3.6.egg/gsmmodem/modem.py", line 688, in smsEncoding
AttributeError: 'GsmModem' object has no attribute '_encoding'

Fix unit tests after rapid merging

Some unit tests are now broken.

I suggest to revert a locally cloned repo to the last v0.9 commit 29ca5f5, add one commit after the other and reveal which commits break the tests and why.

Anyone able to help?

Add native support for remote modems connected over the network (connect to IP address)

I'm currently have to use the remote modem with socat command which maps the remote port to virtual local port socat pty,link=/dev/vmodem0,raw tcp:192.168.5.1:12121 but it is uncomfortable to use. A native support would be much better and more reliable.

According to pySerial docs, it should be easy to add a support for remote modems.
We only have to replace the serial.Serial() construction
self.serial = serial.Serial(port=self.port, baudrate=self.baudrate, timeout=self.timeout,*self.com_args,**self.com_kwargs)
in serial_comms.py connect() method with the alternative serial_for_url() function, which takes a lot more types of connections.

Before editing the rest of the code like adding params to modem() init functions and propagation of the needed settings to connect() method, let's resolve this:

I've successfully replaced the serial.Serial() with something like this
self.serial = serial.serial_for_url(self.port, baudrate = self.baudrate, bytesize = serial.EIGHTBITS, parity = serial.PARITY_NONE, stopbits = serial.STOPBITS_ONE, rtscts = False, xonxoff = False)
and it connects to locally connected modem as usual.

But I have trouble when I fill in an URL pointing to a remote modem
self.serial = serial.serial_for_url("socket://192.168.5.1:12121", baudrate = self.baudrate, bytesize = serial.EIGHTBITS, parity = serial.PARITY_NONE, stopbits = serial.STOPBITS_ONE, rtscts = False, xonxoff = False)

The connection timeouts because of modem not responding. The same code is working fine outside of the python-gsmmodem project. It seems it is a buffer issue or something like that. When I add printing of all the connection output, it does not output anything until I hit Ctrl+C. Then it outputs the last X lines of serial communication. Strange.

Any ideas how to debug?

Make a better fix for TypeError – don't suppress exception, find a cause

Find a cause of the exception and make a better fix.

Traceback (most recent call last):
      File "main.py", line 47, in <module>
        main()
      File "main.py", line 35, in main
        hub = Hub(config)
      File "/home/yuriykashin/sms/hub/__init__.py", line 36, in __init__
        m.processStoredSms()    # handle received messages if any
      File "build/bdist.linux-x86_64/egg/gsmmodem/modem.py", line 761, in processStoredSms
      File "build/bdist.linux-x86_64/egg/gsmmodem/modem.py", line 826, in listStoredSms
      File "build/bdist.linux-x86_64/egg/gsmmodem/pdu.py", line 391, in decodeSmsPdu
      File "build/bdist.linux-x86_64/egg/gsmmodem/pdu.py", line 445, in _decodeUserData
      File "build/bdist.linux-x86_64/egg/gsmmodem/pdu.py", line 789, in unpackSeptets
    TypeError: unsupported operand type(s) for >>: 'NoneType' and 'int'

original issue:
yuriykashin#1

When no smsReceivedCallback function is specified, SMS messages are auto-deleted

When the GsmModem object is not instantiated with an smsReceivedCallback function, it's assigned the internal "_placeholderCallback" function.

The _handleSmsReceived method checks to see if the smsReceivedCallback function is None, and if so, ignores the processing. smsReceivedCallback is NEVER null, so processing occurs, one aspect of which is that the message is deleted after the _placeholderCallback function is called.

Suggest the if statement read:
if not "_placeholderCallback" in self.smsReceivedCallback.im_func.name:
instead of
if self.smsReceivedCallback is not None:

sendussd AttributeError: 'NoneType' object has no attribute 'group'

i was testing the ussd_demo.py and get this error

Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(_self.__args, *_self.__kwargs)
File "build/bdist.linux-armv7l/egg/gsmmodem/modem.py", line 1097, in __threadedHandleModemNotification
self._handleUssd(lines)
File "build/bdist.linux-armv7l/egg/gsmmodem/modem.py", line 1408, in _handleUssd
self._ussdResponse = self._parseCusdResponse(lines)
File "build/bdist.linux-armv7l/egg/gsmmodem/modem.py", line 1441, in _parseCusdResponse
sessionActive = cusdMatches[0].group(1) == '1'
AttributeError: 'NoneType' object has no attribute 'group'

the Exception just return "None"
sometimes it gives me this error but sometimes it just work perfectly
i'm using raspberry pi 3
ubuntu mate
python 2.7.11
wavecom fastrack m1306b

ussd not working

Is there anyone here who is successful sending and receiving ussd?

$ python ussd_demo.py 
Initializing modem...
Sending USSD string: *123#
Traceback (most recent call last):
  File "ussd_demo.py", line 41, in <module>
    main()
  File "ussd_demo.py", line 30, in main
    response = modem.sendUssd("*123") # response type: gsmmodem.modem.Ussd
  File "/home/sav/.local/lib/python2.7/site-packages/gsmmodem/modem.py", line 963, in sendUssd
    cusdResponse = self.write('AT+CUSD=1,"{0}",15'.format(ussdString), timeout=responseTimeout) # Should respond with "OK"
  File "/home/sav/.local/lib/python2.7/site-packages/gsmmodem/modem.py", line 488, in write
    raise CommandError(data)
gsmmodem.exceptions.CommandError: AT+CUSD=1,"*123",15

call.number return None

When using the built in incomingCall example, receivers call number comes um None.
Is this a known issue? Don't find anything here about it

modem disconnecting at AT+CLAC

when trying to connect to modem i got this error

DEBUG: write: AT
DEBUG: response: ['AT\r', 'OK']
DEBUG: write: ATZ
DEBUG: response: ['ATZ\r', 'OK']
DEBUG: write: ATE0
DEBUG: response: ['ATE0\r', 'OK']
DEBUG: write: AT+CFUN?
DEBUG: response: ['+CFUN: 1', 'OK']
DEBUG: write: AT+CMEE=1
DEBUG: response: ['OK']
DEBUG: write: AT+CPIN?
DEBUG: response: ['+CPIN: READY', 'OK']
DEBUG: write: AT+CLAC
DEBUG: write: AT
Traceback (most recent call last):
File "scanmodem.py", line 95, in
modem.connect("1234", waitingForModemToStartInSeconds=10)
File "build/bdist.linux-armv7l/egg/gsmmodem/modem.py", line 237, in connect
File "build/bdist.linux-armv7l/egg/gsmmodem/modem.py", line 577, in supportedCommands
gsmmodem.exceptions.TimeoutException: None

tried to connect the modem manually from terminal and run AT+CLAC
it return the supported command but instantly disconnected from computer and then automatically connecting again
i'm using ZTE Vodafone K3806-Z
i just bought this modem because my previous modem Wavecom Fastrack M1306B doesn't support AT+CLAC either

i know this is the problem with the modems but is there any way to bypass this AT+CLAC
i can't afford another modem :(
i mean all the use of this is just checking if AT+CSCS is supported
and some device specific settings

        if self._commands == None:
            self._commands = self.supportedCommands

        if '+CSCS' in self._commands:
            response = self.write('AT+CSCS?')

Long SMS Concatenation

Working with the sample code here: http://blog.wathmal.me/create-your-own-sms-gateway/ which uses this package, the message concatenation doesn't seem to be working.

Specifically when I use

pdu = sms.to_pdu()[0]
I get part one of the message, but if I use
pdu = sms.to_pdu()[1]
I get part 2, but if I use:
pdu = sms.to_pdu()

It doesn't concatenate. Any tips / working examples?

+CFUN 1,0

It is not true that every modem responds with single int value in CFUN command.

modem.py +223
cfun = int(lineStartingWith('+CFUN:', self.write('AT+CFUN?'))[7:]) # example response: +CFUN: 1

The line could be replaced with following one if you don't need to use the command.
cfun = lineStartingWith('+CFUN:', self.write('AT+CFUN?'))[7:] # example response: +CFUN: 1

I don't see that as a real issue to make pull request, though mentioning it seemed responsible.

Failed to receive sms. (from example)

I am trying to receive sms, using code from example.
Program connected to gsmmodem.
I receive my sms once, when I plug in new gsm modem the first time.
What could be the problem?

Concatenated SMS problem when using UCS2 coding

Hello! I trying to send long SMSs. When I send long SMS (eg. consisting of 7 PDUs) using GSM-7 coding it works fine. But when I send long SMS using UCS2 coding (even consisting of 2 PDUs) - on receiving side text is corrupted. It seems like an encoding problem, isn't it?

Source text (I trying to send this):

File		:	beacon.py - Location reporter service
# Version	:	0.8.2
# Date		:	2018-03-12
# Author	:	TishSerg (Ukraine)
# Email		:	[email protected]
# ==============================================================================

import sys
import time
import threading
import socket
import urllib.request
import subprocess
import re
import beacon
if __name__ == "__main__":
    from location_provider import LocationProvider
    from modem_comm import Modem
else:
    from .location_provider import LocationProvider
    from .modem_comm import Modem

#GPS_PORT = 'COM15'  # DEBUG
#GSM_PORT = 'COM17'  # DEBUG
GPS_PORT = '/dev/ttyS1'  # NanoPi's UART1
GSM_PORT = '/dev/ttyS2'  # NanoPi's UART2
GSM_RTS_PIN = 13  # NanoPi's PA2 pin
GSM_CTS_PIN = 15  # NanoPi's PA3 pin
GSM_STATUS_PIN = 21  # NanoPi's PC1 pin
GSM_PWRKEY_PIN = 23  # NanoPi's PC2 pin (Active High)

This text will be encoded using UCS2 due to "\t" symbols near the beginning. I programmatically limit this text to fit it into 1 then 2 PDUs. Results on the picture:

First (correctly coded) message - source text was limited to 1 PDU (UCS2).
Second (incorrectly coded) message - same source text was limited to 2 PDUs (UCS2).

The Modem I use is SIM800C.

Failed to parse text-mode SMS message +CMGR response

In case of ^RSSI and +CMGR are both in the response list handled by _handleSmsStatusReport it raises CommandError.

Example response list that raises error:

['^RSSI:3', '+CMGR: "REC UNREAD",6,203,"1320",129,"17/06/13,19:00:58+28","17/06/13,19:00:58+28",0', 'OK']

The way to reproduce:

  1. run modem into idle, unhandled modem notifications ^RSSI will flow
  2. do any actions to make handled notifications come
  3. wait until ^RSSI and handled notifications are received at one time

Device: Huawei E171

Full log:

2017-06-13 19:00:51,589 - DEBUG - response: ['^RSSI:3', '+CMGR: "REC UNREAD",6,203,"1320",129,"17/06/13,19:00:58+28","17/06/13,19:00:58+28",0', 'OK']
Exception in thread Thread-54:
Traceback (most recent call last):
File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner
self.run()
File "C:\Python27\lib\threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "C:\Python27\lib\site-packages\gsmmodem\modem.py", line 1177, in __threadedHandleModemNotification
self._handleSmsStatusReport(line)
File "C:\Python27\lib\site-packages\gsmmodem\modem.py", line 1345, in _handleSmsStatusReport
report = self.readStoredSms(msgIndex, msgMemory)
File "C:\Python27\lib\site-packages\gsmmodem\modem.py", line 1419, in readStoredSms
raise CommandError('Failed to parse text-mode SMS message +CMGR response: {0}'.format(msgData))
CommandError: Failed to parse text-mode SMS message +CMGR response: ['^RSSI:3', '+CMGR: "REC UNREAD",6,203,"1320",129,"17/06/13,19:00:58+28","17/06/13,19:00:58+28",0', 'OK']

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.