Giter VIP home page Giter VIP logo

Comments (12)

menon92 avatar menon92 commented on August 15, 2024

I have same problem. Do you get the solution of this problem

from python-gsmmodem.

mwaaas avatar mwaaas commented on August 15, 2024

Yeah I managed, will find the solution I used then share it with you

from python-gsmmodem.

menon92 avatar menon92 commented on August 15, 2024

could you please help me now. How can I solve this problem ? I am completely stuck with this problem @mwaaas

from python-gsmmodem.

mwaaas avatar mwaaas commented on August 15, 2024

Here is the code that I used

#!/usr/bin/env python

"""
Demo: Simple USSD example

Simple demo app that initiates a USSD session, reads the string response and closes the session
(if it wasn't closed by the network)

Note: for this to work, a valid USSD string for your network must be used.
"""

from future import print_function

import logging

PORT = '/dev/tty.HUAWEIMobile-Pcui'
BAUDRATE = 115200
USSD_STRING = '1405*0703488092#'
PIN = None # SIM card PIN (if any)

from gsmmodem.modem import GsmModem

def main():
print('Initializing modem...')
#logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
modem = GsmModem(PORT, BAUDRATE)
modem.connect(PIN)
modem.waitForNetworkCoverage(10)
print('Sending USSD string: {0}'.format(USSD_STRING))
response = modem.sendUssd(USSD_STRING, 30) # response type:
# gsmmodem.modem.Ussd
print('USSD reply received: {0}'.format(response.message))
if response.sessionActive:
print('Closing USSD session.')
# At this point, you could also reply to the USSD message by using response.reply()
response.cancel()
else:
print('USSD session was ended by network.')
modem.close()

if name == 'main':
main()

from python-gsmmodem.

mwaaas avatar mwaaas commented on August 15, 2024

use this python-gsmmodem-new

pip install python-gsmmodem-new

from python-gsmmodem.

menon92 avatar menon92 commented on August 15, 2024

Thanks for your reply. I try your code. In your code from future import print_function give me Import Error. for this I change your code like this. and this give me the same error. could you please help me.

#!/usr/bin/env python

"""
Demo: Simple USSD example

Simple demo app that initiates a USSD session, reads the string response and closes the session
(if it wasn't closed by the network)

Note: for this to work, a valid USSD string for your network must be used.
"""

#from future import print_function

import logging

#PORT = '/dev/tty.HUAWEIMobile-Pcui'
PORT = '/dev/ttyUSB0'
BAUDRATE = 115200
#USSD_STRING = '1405*0703488092#'
USSD_STRING = 'AA988C3602' # *124# = AA988C3602
PIN = None # SIM card PIN (if any)

from gsmmodem.modem import GsmModem

def main():
	print('Initializing modem...')
	#logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
	modem = GsmModem(PORT, BAUDRATE)
	modem.connect(PIN)
	modem.waitForNetworkCoverage(10)
	print('Sending USSD string: {0}'.format(USSD_STRING))
	response = modem.sendUssd(USSD_STRING, 30) # response type:
	# gsmmodem.modem.Ussd
	print('USSD reply received: {0}'.format(response.message))
	if response.sessionActive:
		print('Closing USSD session.')
		# At this point, you could also reply to the USSD message by using response.reply()
		response.cancel()
	else:
		print('USSD session was ended by network.')
	modem.close()

# if name == 'main':
# 	main()

if __name__ == '__main__':
	main()

Thanks @mwaaas

from python-gsmmodem.

menon92 avatar menon92 commented on August 15, 2024

My modem port:

menon@menon-Inspiron-N4050:~$ ls -l /dev/ttyUSB*
crw-rw---- 1 root dialout 188, 0 May 20 08:50 /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 1 May 20 08:47 /dev/ttyUSB1
crw-rw---- 1 root dialout 188, 2 May 20 10:16 /dev/ttyUSB2
lrwxrwxrwx 1 root root         7 May 20 08:47 /dev/ttyUSB_utps_diag -> ttyUSB1
lrwxrwxrwx 1 root root         7 May 20 08:47 /dev/ttyUSB_utps_modem -> ttyUSB0
lrwxrwxrwx 1 root root         7 May 20 08:47 /dev/ttyUSB_utps_pcui -> ttyUSB2
menon@menon-Inspiron-N4050:~$ 

from python-gsmmodem.

babca avatar babca commented on August 15, 2024

@menon92 set your PORT to dev/ttyUSB2.
The TimeoutException is expected in this case. You can't catch incoming calls, USSDs and SMS messages with dev/ttyUSB0 port on Huawei modems, because this channel doesn't contain modem notifications.

I tested ussd_demo.py with my Huawei modem and it's working as expected:
dev/ttyUSB2 => USSD working fine ✓
dev/ttyUSB0 => TimeoutException ✓

If your code still doesn't work, uncomment logging.basicConfig(... line and post here your console output.

from python-gsmmodem.

menon92 avatar menon92 commented on August 15, 2024

when I set PORT to /dev/ttyUSB2 then output is :

Initializing modem...
INFO: Connecting to modem on port /dev/ttyUSB2 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: ['+CLAC:&C,&D,&E,&F,&S,&V,&W,E,I,L,M,Q,V,X,Z,T,P,\\Q,\\S,\\V,%V,D,A,H,O,S0,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S30,S103,S104,+FCLASS,+ICF,+IFC,+IPR,+GMI,+GMM,+GMR,+GCAP,+GSN,+DR,+DS,+WS46,+CLAC,+CCLK,+CBST,+CRLP,+CV120,+CHSN,+CSSN,+CREG,+CGREG,+CFUN,+GCAP,+CSCS,+CSTA,+CR,+CEER,+CRC,+CMEE,+CGDCONT,+CGDSCONT,+CGTFT,+C', 'ERROR']
DEBUG: write: AT
DEBUG: response: ['OK']
DEBUG: write: AT^CVOICE=?
DEBUG: write: AT+VTS=?
DEBUG: write: AT^DTMF=?
DEBUG: write: AT^USSDMODE=?
DEBUG: write: AT+WIND=?
DEBUG: write: AT+ZPAS=?
DEBUG: write: AT+CSCS=?
DEBUG: write: AT+CNUM=?
DEBUG: write: AT+CGMI
Traceback (most recent call last):
  File "pygsm_modem_send_ussd.py", line 47, in <module>
    main()
  File "pygsm_modem_send_ussd.py", line 29, in main
    modem.connect(PIN)
  File "/usr/local/lib/python2.7/dist-packages/gsmmodem/modem.py", line 282, in connect
    if b'simcom' in self.manufacturer.lower() : #simcom modems support DTMF and don't support AT+CLAC
  File "/usr/local/lib/python2.7/dist-packages/gsmmodem/modem.py", line 524, in manufacturer
    return self.write('AT+CGMI')[0]
  File "/usr/local/lib/python2.7/dist-packages/gsmmodem/modem.py", line 470, in write
    responseLines = super(GsmModem, self).write(data + writeTerm, waitForResponse=waitForResponse, timeout=timeout, expectedResponseTermSeq=expectedResponseTermSeq)
  File "/usr/local/lib/python2.7/dist-packages/gsmmodem/serial_comms.py", line 133, in write
    self.serial.write(data)
  File "/usr/local/lib/python2.7/dist-packages/serial/serialposix.py", line 528, in write
    raise portNotOpenError
serial.serialutil.SerialException: Attempting to use a port that is not open

And when I set PORT to /dev/ttyUSB0 then output is :

Initializing modem...
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: ['+CLAC:&C,&D,&E,&F,&S,&V,&W,E,I,L,M,Q,V,X,Z,T,P,\\Q,\\S,\\V,%V,D,A,H,O,S0,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S30,S103,S104,+FCLASS,+ICF,+IFC,+IPR,+GMI,+GMM,+GMR,+GCAP,+GSN,+DR,+DS,+WS46,+CLAC,+CCLK,+CBST,+CRLP,+CV120,+CHSN,+CSSN,+CREG,+CGREG,+CFUN,+GCAP,+CSCS,+CSTA,+CR,+CEER,+CRC,+CMEE,+CGDCONT,+CGDSCONT,+CGTFT,+CGEQREQ,+CGEQMIN,+CGQREQ,+CGQMIN,+CGEQNEG,+CGEREP,+CGPADDR,+CGCLASS,+CGSMS,+CSMS,+CMGF,+CSAS,+CRES,+CSCA,+CSMP,+CSDH,+CSCB,+FDD,+FAR,+FCL,+FIT,+ES,+ESA,+CMOD,+CVHU,+CGDATA,+CSQ,+CBC,+CPAS,+CPIN,+CMEC,+CKPD,+CIND,+CMER,+C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['OK']
INFO: Loading Huawei 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: "+880150159999",145', 'OK']
DEBUG: write: AT+CSMP=49,167,0,0
DEBUG: response: ['OK']
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CSCA: "+880150159999",145', 'OK']
DEBUG: write: AT+CPMS=?
DEBUG: response: ['+CPMS: ("ME","MT","SM","SR"),("ME","MT","SM","SR"),("ME","MT","SM","SR")', 'OK']
DEBUG: write: AT+CPMS="ME","ME","ME"
DEBUG: response: ['+CPMS: 0,23,0,23,0,23', 'OK']
DEBUG: write: AT+CNMI=2,1,0,2
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']
DEBUG: write: AT+CREG?
DEBUG: response: ['+CREG: 0,1', 'OK']
DEBUG: write: AT+CSQ
DEBUG: response: ['+CSQ: 6,99', 'OK']
Sending USSD string: AA584D3602
DEBUG: write: AT+CUSD=1,"AA584D3602",15
DEBUG: response: ['OK']
Traceback (most recent call last):
  File "pygsm_modem_send_ussd.py", line 47, in <module>
    main()
  File "pygsm_modem_send_ussd.py", line 32, in main
    response = modem.sendUssd(USSD_STRING, 30) # response type:
  File "/usr/local/lib/python2.7/dist-packages/gsmmodem/modem.py", line 958, in sendUssd
    raise TimeoutException()
gsmmodem.exceptions.TimeoutException: None

Thanks.

from python-gsmmodem.

babca avatar babca commented on August 15, 2024

serial.serialutil.SerialException: Attempting to use a port that is not open
It seems your modem unexpectedly restarts itself? (Maybe a bug in the modem firmware?)
It fails at simple CLAC command, the response is cut after ~300 characters.

Could you start gsmterm from tools/ folder?
python gsmterm.py -r /dev/ttyUSB2
type AT+CLAC, Enter
is the command working properly?
(Press CTRL+] to exit.)

from python-gsmmodem.

menon92 avatar menon92 commented on August 15, 2024

I run python gsmterm.py -r /dev/ttyUSB2 and it give me output:

Raw terminal connected to /dev/ttyUSB2 at 115200bps.
Press CTRL+] to exit.

ERROR
AT+CLAC
ERROR
AT+CLAC
+CLAC:&C,&D,&E,&F,&S,&V,&W,E,I,L,M,Q,V,X,Z,T,P,\Q,\S,\V,%V,D,A,H,O,S0,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S30,S103,S104,+FCLASS,+ICF,+IFC,+IPR,+GMI,+GMM,+GMR,+GCAP,+GSN,+DR,+DS,+WS46,+CLAC,+CCLK,+CBST,+CRLP,+CV120,+CHSN,+CS
+CPMS: 0,50,0,50,0,50
OK
AT+CLAC
Done.

I think AT+CLAC command sometimes works and sometimes not working.

If there is problem with modem firmware or modem unexpectedly restarts In that case what can i do ? should i try a new modem with the same code ? or anything else i can do .

Thanks @babca

from python-gsmmodem.

babca avatar babca commented on August 15, 2024

This seems to be related to the modem not to python-gsmmodem library.
Please try it again and type ATZ command before AT+CLAC command.
Both should output OK on the last line, every time.
I don't think it will help, but you can also try to lower baudrate:
python gsmterm.py -r /dev/ttyUSB2 -b 9600

Which modem do you use?

Try a different modem if you can. Huawei E372 and E160 are working fine with ussd_demo.py.

from python-gsmmodem.

Related Issues (20)

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.