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

Add SMS forwarder example #28

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

alyssadev
Copy link

Love the library, thank you. I added an example of how one might make an SMS forwarder loop to retrieve messages sent to the SIM in the gateway and forward them to another device. Users could adapt it to forward messages to another messaging system if they prefer. I couldn't find any example showing usage of _sms_events and self.listeners, hope this serves as documentation for that. This code is published under the MIT license.

I used f-strings, if you want to support versions of python before 3.6 I can swap the f-string for .format.

@alyssadev
Copy link
Author

Added a feature to allow the recipient of the forwarded SMSs to respond
e.g
sender sends: test
forwarded recipient receives: +xxsender: test
forwarded recipient responds: +xxsender: acknowledged
sender receives: acknowledged

@alyssadev
Copy link
Author

Running this locally, I've been encountering the below error:

Traceback (most recent call last):
  File "/home/alyssa/workspace/eternalegypt/eternalegypt/eternalegypt.py", line 289, in information
    result = self._build_information(data)
  File "/home/alyssa/workspace/eternalegypt/eternalegypt/eternalegypt.py", line 237, in _build_information
    result.serial_number = data['general']['FSN']
KeyError: 'FSN'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/alyssa/workspace/eternalegypt/eternalegypt/eternalegypt.py", line 73, in wrapper
    return await function(self, *args, **kwargs)
  File "/home/alyssa/workspace/eternalegypt/eternalegypt/eternalegypt.py", line 293, in information
    raise Error()
eternalegypt.eternalegypt.Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/alyssa/sms_forward.py", line 29, in wait_for_messages
    await modem.information() # sends new sms objects to listener
  File "/home/alyssa/workspace/eternalegypt/eternalegypt/eternalegypt.py", line 75, in wrapper
    raise Error(str(function))
eternalegypt.eternalegypt.Error: <function LB2120.information at 0x7f5a4313e1f0>

It appears model.json might not always contain the requested data? information() might need to retry the request in the event that an error is raised. For now I've set up my loop to catch that error and retry from outside.

@amelchio
Copy link
Owner

Thank you. I don't have time to look into this right now but will keep this open until I do.

@amelchio
Copy link
Owner

Sorry for the delay, testing this now.

I do not get the traceback, is it frequent for you? Does it happen when idle or only when forwarding a message? I am using Netgear LB2120, do you have the same modem?

@amelchio
Copy link
Owner

Never mind, I did get the error shortly after posting :-). I will look into that.

@amelchio
Copy link
Owner

My findings so far: running with a 5 second interval and keep-alive seems to break the session eventually and reauthentication fails.

Setting the sleep time to 10 seconds seems to resolve this. It can also be avoided by creating the session like this:

    connector = aiohttp.connector.TCPConnector(force_close=True)
    websession = aiohttp.ClientSession(cookie_jar=jar, connector=connector)

The real fix would be to get the autologin to work properly but I am not yet sure how that is best done.

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

Successfully merging this pull request may close these issues.

2 participants