faucamp / python-gsmmodem

Python module to control a GSM modem attached to the system: send/receive SMS messages, handle calls, etc
GNU Lesser General Public License v3.0
384 stars 302 forks source link

The sms_handler_demo not work on my huawei e303 modem, I have no response from the SMS that I send to the modem. #41

Open mariolicona opened 9 years ago

Andati commented 9 years ago

Add the following code after line 34 of sms_handler_demo.py:

modem.processStoredSms(unreadOnly=True)

So that the code reads:

try:    
    modem.processStoredSms(unreadOnly=True)
    modem.rxThread.join(2**31) # Specify a (huge) timeout so that it essentially blocks indefinitely, but still receives CTRL+C interrupt signal
finally:
babca commented 8 years ago

@mariolicona Make sure

@Andati good tip for processing all older messages from the period the python daemon was not running, but it can't resolve the issue that mariolicona describes.

BaronBonet commented 5 years ago

I'm also having this issue.

If I use Port = '/dev/ttyUSB0' I can read my number (using the own_number_demo.py example) and send messages (using the modem.sendSms() function). However, I cannot seem to be able to access /dev/ttyUSB2 so therefor I cannot receive messages.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "own_number_demo.py", line 38, in main() File "own_number_demo.py", line 22, in main modem.connect(PIN) File "/home/eric/.local/lib/python3.6/site-packages/gsmmodem/modem.py", line 199, in connect super(GsmModem, self).connect() File "/home/eric/.local/lib/python3.6/site-packages/gsmmodem/serial_comms.py", line 51, in connect timeout=self.timeout,*self.com_args,**self.com_kwargs) File "/home/eric/.local/lib/python3.6/site-packages/serial/serialutil.py", line 240, in init self.open() File "/home/eric/.local/lib/python3.6/site-packages/serial/serialposix.py", line 268, in open raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg)) serial.serialutil.SerialException: [Errno 16] could not open port /dev/ttyUSB2: [Errno 16] Device or resource busy: '/dev/ttyUSB2'

- if I run the demos and call `sudo` I get this error

-> % sudo python own_number_demo.py Initializing modem... INFO: Connecting to modem on port /dev/ttyUSB2 at 115200bps DEBUG: write: ATZ Traceback (most recent call last): File "own_number_demo.py", line 38, in main() File "own_number_demo.py", line 22, in main modem.connect(PIN) File "/home/eric/.local/lib/python3.6/site-packages/gsmmodem/modem.py", line 211, in connect self.write('ATZ') # reset configuration File "/home/eric/.local/lib/python3.6/site-packages/gsmmodem/modem.py", line 459, in write responseLines = super(GsmModem, self).write(data + writeTerm, waitForResponse=waitForResponse, timeout=timeout, expectedResponseTermSeq=expectedResponseTermSeq) File "/home/eric/.local/lib/python3.6/site-packages/gsmmodem/serial_comms.py", line 144, in write raise TimeoutException() gsmmodem.exceptions.TimeoutException: None



Any advice would be appreciated @babca. 

After some digging i think this might be a lower level problem and have posted a question on [superuser stackExchange](https://superuser.com/questions/1412935/linux-cu-command-returns-line-in-use)
babca commented 5 years ago
  1. Please use a maintained fork: https://github.com/babca/python-gsmmodem faucamp's repo is abandoned.

  2. Have you tried to use '/dev/ttyUSB1' port as well?

  3. The device can be occupied by a another program or another instance of gsmmodem which is still running. Check running processes.

I was never forced to use chmod on /dev/ttyUSBx, defaults should be fine.

BaronBonet commented 5 years ago

Hi @babca, thanks a lot for your reply. I am now using the maintained fork, and i just solved this issue.

I did try using /dev/ttyUSB1 that also did not work

I solved the use by running sudo lsof | grep tty from there i saw there was a process running on /dev/ttyUSB2 once i killed that process sudo kill <PID> I was able to run the examples using PORT = '/dev/ttyUSB2' and now it is functioning as expected.

The first time i didn't run lsof as the super user so i didn't see all the processes running.

If you think it would be helpful I'll happily transfer this information to your fork.

babca commented 5 years ago

I couldn't remember the last time I saw this error. Now I remember, it was a process which occupied the port, as well. The same reason.

I created a simple FAQ section in https://github.com/babca/python-gsmmodem/blob/master/README.rst. Feel free to improve it 👍

BaronBonet commented 5 years ago

Looks great, thanks for maintaining this project and documenting. I'm working on using this package in combination with Django to so i can upload messages to a cloud server, which are then sent to a local computer (in Lesotho) and then sent to local customers phones. The same also will work in reverse (messages from phones -> to local computer -> to cloud server). I'll try to document the process and once it's ready I'll share the project with you in case your interested.

Thanks again!

On Mon, Mar 11, 2019 at 6:22 PM babca notifications@github.com wrote:

I couldn't remember when I saw this error last time. Now I remember, it was a process which occupied the port, as well. The same reason.

I created a simple FAQ section in https://github.com/babca/python-gsmmodem/blob/master/README.rst. Feel free to improve it 👍

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/faucamp/python-gsmmodem/issues/41#issuecomment-471637520, or mute the thread https://github.com/notifications/unsubscribe-auth/Ahs2RjebFD49sTnCwruXuDuP1B39hzGHks5vVpDCgaJpZM4CmZRt .

babca commented 5 years ago

Great news Eric. Share it for everyone! :-)