Civlo85 / gsmHat

Using the Waveshare GSM/GPRS/GNSS Hat for Raspberry Pi with Python
MIT License
66 stars 27 forks source link

Thread crash on receiving SMS #11

Open smartroad opened 3 years ago

smartroad commented 3 years ago

I just had the library crash the thread when it received an SMS. here is the log:

2021-10-17 09:03:56,265 - gsmHat.gsmHat - DEBUG - Received Data: +SAPBR: 1,3,"0.0.0.0"
2021-10-17 09:03:56,295 - gsmHat.gsmHat - DEBUG - Received Data: OK
2021-10-17 09:03:56,307 - gsmHat.gsmHat - DEBUG - Lock Off
2021-10-17 09:03:56,313 - gsmHat.gsmHat - ERROR - Timeout during data reception
2021-10-17 09:03:56,318 - gsmHat.gsmHat - INFO - Command sent: AT+SAPBR=2,1
2021-10-17 09:03:56,324 - gsmHat.gsmHat - INFO - Actual state of programme: 61
2021-10-17 09:03:56,326 - gsmHat.gsmHat - CRITICAL - Exception: Unhandled timeout during data reception

looking at the script after sending the critical warning it basically causes the script to end using the raise command. Why does it do that? As soon as that happens the library stops working within my script and I don't get any sms messages being sent out or received. Is there a more graceful way to handle the error? Maybe making it wait a few seconds and then try again later?

flykarlos commented 3 years ago

I can confirm, I have the same issue. My code:

from gsmHat import GSMHat, SMS, GPS

gsm = GSMHat('/dev/ttySC0', 115200)

while True:

    if gsm.SMS_available() > 0:

        newSMS = gsm.SMS_read()
        print('Got new SMS from number %s' % newSMS.Sender)
        print('It was received at %s' % newSMS.Date)
        print('The message is: %s' % newSMS.Message)

Error code:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.9/threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.9/dist-packages/gsmHat/gsmHat.py", line 616, in __workerThread
    if self.__waitForUnlock():
  File "/usr/local/lib/python3.9/dist-packages/gsmHat/gsmHat.py", line 478, in __waitForUnlock
    raise 'Unhandled timeout during data reception'
TypeError: exceptions must derive from BaseException

I noticed that the module is crashing/switching off after this error.

flykarlos commented 3 years ago

I think, that I found solution. When looking on oscilloscope connected to 5v bus on RPI4 I saw large voltage variations. This probably caused thread error, and in my case self shutdown of SIM868 HAT. Looks like the problem is caused by insufficient power provided to the RPi. I resolved my problem by adding electrolytic capacitor across 5V/GND.

KevinBrustolin commented 9 months ago

@flykarlos I faced same issue, can you confirm that the used of electrolytic capacitor prevent this error ?