eternalegypt icon indicating copy to clipboard operation
eternalegypt copied to clipboard

Add SMS forwarder example

Open alyssadev opened this issue 3 years ago • 6 comments

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 avatar Mar 10 '21 12:03 alyssadev

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 avatar Mar 10 '21 12:03 alyssadev

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.

alyssadev avatar Mar 11 '21 00:03 alyssadev

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

amelchio avatar Mar 13 '21 20:03 amelchio

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 avatar May 22 '21 13:05 amelchio

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

amelchio avatar May 22 '21 13:05 amelchio

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.

amelchio avatar May 26 '21 20:05 amelchio