iMicknl / python-sagemcom-api

(Unofficial) Python wrapper to interact with SagemCom F@st routers via internal API's.
MIT License
95 stars 39 forks source link

Sagemcom FAST3896 Telekom Login issue #176

Closed takdan01 closed 3 months ago

takdan01 commented 2 years ago

Model information

Key Value
Model name FAST3896
Hardware Version V4
Software Version FAST3896_MAGYAR_sw18.83.11.14y-6

Describe the bug

I tried to login to router with example code. It couldn't because returned this: {'code': 16777224, 'description': 'XMO_LOGIN_RETRY_ERR'} I tried both encryption method.

Additional context

I have got Fast3890V3 Telekom and it doesn't do this. I only collect Docsis data.

sthevenp commented 9 months ago

Any chance for Home Assistant integration like for Speedport modem? https://github.com/Andre0512/speedport

bakonyiferenc commented 8 months ago

FTR I had the same issue with FAST3896_MAGYAR_sw18.83.17.20e, it was caused by me doing a lot of failed authentication attempts while messing around with the configuration and code. Accessing the web UI of the router from a browser told me the admin account was locked out. Rebooting the router helped.

takdan01 commented 8 months ago

I use small python code, which I manage with crontab. I wrote the password and user in the code and try to authenticate with these credentials into HGW, but a few times I get this message back. I have noticed that if you are already logged in and try to log in again, it locks out HGW. The xmo has a loggedin function ($.xmo.loggedin()), but for some reason the browser doesn't catch this and so I can't see the request. You can use it to check if you are already logged in.

takdan01 commented 8 months ago

This is my code. It collects the Docsis, modem data and it visualises.

import asyncio
import time
import datetime
import influx_data_sender

from sagemcom_api.enums import EncryptionMethod
from sagemcom_api.client import SagemcomClient

HOST = "192.168.0.1"
USERNAME = "admin"
PASSWORD = "password"
ENCRYPTION_METHOD = EncryptionMethod.SHA512  # EncryptionMethod.MD5 # or EncryptionMethod.SHA512

async def main() -> None:
    async with SagemcomClient(HOST, USERNAME, PASSWORD, ENCRYPTION_METHOD) as client:
        print('Try logout')
        try:
            await client.logout()
            time.sleep(5)
        except Exception as exeception:
            print(f'Logout error: {exeception}')
        print('Try login')
        try:
            await client.login()
        except Exception as exception:  # pylint: disable=broad-except
            print(f'Login error: {exception}')
            return
        x = 1
        ds = True
        date_time = datetime.datetime.now()
        influxtime = int(time.mktime(date_time.timetuple())) * 1000000000

        print('uptime data download')
        try:
            uptime = await client.get_value_by_xpath('Device/DeviceInfo/UpTime')
            influx_data_sender.modem_uptime(influxtime, 'up', uptime)
        except Exception as exception:
            print(f'Get uptime error: {exception}')
            influx_data_sender.modem_uptime(influxtime, 'down', '-1')
        print('downstream data download and send to database')
        while ds == True:
            try:
                downstreams = await client.get_value_by_xpath(
                    "Device/Docsis/CableModem/Downstreams/Downstream[@uid='" + str(x) + "']")
                freq = downstreams['downstream']['frequency'] / 1000000
                ##Down SNR
                influx_data_sender.docsis_down_snr(influxtime, downstreams['downstream']['channel_id'],
                                                   freq,
                                                   downstreams['downstream']['SNR'])
                ##Down Power Level
                influx_data_sender.docsis_down_power(influxtime, downstreams['downstream']['channel_id'],
                                                     freq,
                                                     downstreams['downstream']['power_level'])
                ##Down Correctabel Codewords
                influx_data_sender.docsis_down_correct(influxtime, downstreams['downstream']['channel_id'],
                                                       freq,
                                                       downstreams['downstream']['correctable_codewords'])

                # uncorrectable codewords difference
                influx_data_sender.docsis_down_uncorrect_diff(influxtime, downstreams['downstream']['channel_id'],
                                                              freq,
                                                              downstreams['downstream']['uncorrectable_codewords'])
                ## Down Uncorrectable Codewords
                influx_data_sender.docsis_down_uncorrect(influxtime, downstreams['downstream']['channel_id'],
                                                         freq,
                                                         downstreams['downstream']['uncorrectable_codewords'])
                print(downstreams)
            except Exception as exception:
                ds = False
            x += 1
        print('Upstream data download and send to database')
        us = True
        y = 1
        while us == True:
            try:
                upstreams = await client.get_value_by_xpath(
                    "Device/Docsis/CableModem/Upstreams/Upstream[@uid='" + str(y) + "']")
                influx_data_sender.docsis_up_power(influxtime, upstreams['upstream']['channel_id'],
                                                   (upstreams['upstream']['frequency'] / 1000000),
                                                   upstreams['upstream']['power_level'])
                print(upstreams)
            except Exception as exception:
                us = False
            y += 1

if __name__ == '__main__':
    asyncio.run(main())