diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2021-03-23 04:14:34 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2021-03-23 04:14:34 +0300 |
commit | bb955f2546b46e72f7ce30c0aefe88e4a848925b (patch) | |
tree | 4fad7c869c7e24922f1b1981b7d5d7b6aa2c220d /main.py | |
parent | b8c7b0b6ef904d0262b846e914c10b59e159a8fd (diff) |
some improvements while network was down.....
Diffstat (limited to 'main.py')
-rw-r--r-- | main.py | 42 |
1 files changed, 37 insertions, 5 deletions
@@ -2,30 +2,62 @@ import pathlib import os from argparse import ArgumentParser -from pprint import pprint from e3372 import WebAPI, SMSHandler, SMS config_dir = os.path.join(pathlib.Path.home(), '.e3372-sms-handler') +trusted_phone = '' -def sms_handler(sms: SMS): +def sms_handler(sms: SMS, api: WebAPI): + global trusted_phone + print(f'from: {sms.phone}') - print(f'text: {sms.content}') + print(f'text: {sms.text}') + + if sms.phone == trusted_phone: + text = sms.text.lower().strip() + if text == 'you shall reboot': + api.reboot() + + elif text == 'show me some status': + info = api.device_information() + signal = api.device_signal() + buf = [] + + for key, value in info.items(): + if key in ('workmode', 'WanIPAddress'): + buf.append(f'{key}={value}') + + for key, value in signal.items(): + if key in ('cell_id', 'rssi', 'rscp', 'ecio', 'mode'): + buf.append(f'{key}={value}') + + buf = ' '.join(buf) + if buf != '': + api.send_sms(phone=trusted_phone, content=buf) def main(): + global trusted_phone + + # parse arguments parser = ArgumentParser() parser.add_argument('--ip', default='192.168.8.1', help='Modem IP address') - parser.add_argument('--phone') - parser.add_argument('--content') + parser.add_argument('--trusted-phone', + help='Trusted phone number') args = parser.parse_args() + # set global trusted_phone + trusted_phone = args.trusted_phone + + # webapi client client = WebAPI(args.ip) client.auth() + # sms handler smshandler = SMSHandler(api=client, config_dir=config_dir) smshandler.process(sms_handler) |