[Custom Component] TP-Link Router Integration

I had a chance to play with the client, easier than I expected :slight_smile:

It appears that the router data doesnā€™t expose the count of IoT devices, unfortunately.

Hereā€™s what I tried:

>>> data = router._get_data('admin/status?form=all')
>>> print({key for key in data.keys() if 'iot' in key})
{'iot_5g_encryption', 'iot_5g_disabled_by', 'iot_2g_hidden', 'iot_2g_ssid', 'iot_5g_hidden', 'iot_5g_ssid', 'iot_2g_psk_cipher', 'iot_5g_psk_cipher', 'iot_2g_encryption', 'iot_2g_disabled', 'iot_2g_enable', 'iot_5g_psk_version', 'iot_2g_disabled_by', 'iot_5g_psk_key', 'iot_5g_disabled', 'iot_2g_psk_version', 'iot_2g_psk_key', 'iot_5g_enable'}
>>> print({key for key in data.keys() if 'access_devices' in key})
{'access_devices_wireless_host', 'access_devices_wired'}

So it might be possible to turn on and off the IoT networks, but canā€™t get a count of the devices :frowning:

  • Could you post the json from admin/status?form=all when the IoT networks enabled on your router. For example if guest wifi is disabled so there is no client list in json for guest wifi (in this json would be the mac address of your router and passwords for wifi and ect. please change the values to *** ) It would be great to see what parameters your model have - maybe I could add some extra sensors
  • Do you have a IoT device? It would be great if you show the json when the device is connected to the router

Yes, the IoT networks are enabled and in use, I have several devices connected to them.

Hereā€™s a redacted view of the full JSON response:

{
    "data": {
        "access_devices_wired": [***],
        "access_devices_wireless_host": [***],
        "conn_type": "0",
        "cpu1_usage": 0.15,
        "cpu2_usage": 0.09,
        "cpu_usage": 0.12,
        "guest_2g5g_authentication_timeout": "",
        "guest_2g5g_authentication_type": "",
        "guest_2g5g_encryption": "none",
        "guest_2g5g_passwd_cycle": "",
        "guest_2g5g_portal_password": "",
        "guest_2g5g_psk_cipher": "aes",
        "guest_2g5g_psk_key": "",
        "guest_2g5g_psk_version": "rsn",
        "guest_2g5g_redirect": "off",
        "guest_2g5g_redirect_url": "",
        "guest_2g_authentication_timeout": "",
        "guest_2g_authentication_type": "",
        "guest_2g_disabled": "off",
        "guest_2g_disabled_by": "",
        "guest_2g_enable": "off",
        "guest_2g_encryption": "none",
        "guest_2g_extinfo": {
            "support_band": "both",
            "support_guest_dynpasswd": "no",
            "wds_guest_compatible": "no"
        },
        "guest_2g_hidden": "off",
        "guest_2g_portal_password": "***",
        "guest_2g_psk_cipher": "aes",
        "guest_2g_psk_key": "",
        "guest_2g_psk_version": "rsn",
        "guest_2g_redirect": "off",
        "guest_2g_redirect_url": "",
        "guest_2g_ssid": "***",
        "guest_5g_authentication_timeout": "",
        "guest_5g_authentication_type": "",
        "guest_5g_disabled": "off",
        "guest_5g_disabled_by": "",
        "guest_5g_enable": "off",
        "guest_5g_encryption": "none",
        "guest_5g_extinfo": {
            "support_band": "both",
            "support_guest_dynpasswd": "no",
            "wds_guest_compatible": "no"
        },
        "guest_5g_hidden": "off",
        "guest_5g_portal_password": "",
        "guest_5g_psk_cipher": "aes",
        "guest_5g_psk_key": "",
        "guest_5g_psk_version": "rsn",
        "guest_5g_redirect": "off",
        "guest_5g_redirect_url": "",
        "guest_5g_ssid": "***",
        "guest_access": "off",
        "guest_isolate": "off",
        "iot_2g_disabled": "off",
        "iot_2g_disabled_by": "",
        "iot_2g_enable": "on",
        "iot_2g_encryption": "psk",
        "iot_2g_hidden": "off",
        "iot_2g_psk_cipher": "auto",
        "iot_2g_psk_key": "***",
        "iot_2g_psk_version": "auto",
        "iot_2g_ssid": "***",
        "iot_5g_disabled": "off",
        "iot_5g_disabled_by": "",
        "iot_5g_enable": "on",
        "iot_5g_encryption": "psk_sae",
        "iot_5g_hidden": "off",
        "iot_5g_psk_cipher": "aes",
        "iot_5g_psk_key": "***",
        "iot_5g_psk_version": "sae_transition",
        "iot_5g_ssid": "***",
        "lan_ipv4_dhcp_enable": "On",
        "lan_ipv4_ipaddr": "***",
        "lan_ipv4_netmask": "255.255.255.0",
        "lan_ipv6_assign_type": "slaac",
        "lan_ipv6_ipaddr": "***",
        "lan_ipv6_link_local_addr": "***",
        "lan_macaddr": "***",
        "mem_usage": 0.41,
        "modem_available": 0,
        "modem_connstatus": "0",
        "modem_gateway": "0.0.0.0",
        "modem_ipaddr": "0.0.0.0",
        "modem_ipv4_uptime": "0",
        "modem_netmask": "0.0.0.0",
        "modem_pinlock": "0",
        "modem_pridns": "0.0.0.0",
        "modem_signal": "0%",
        "modem_snddns": "0.0.0.0",
        "modem_status": "0",
        "modem_type": "Modem",
        "printer_count": 0,
        "printer_name": "None",
        "storage_available": 0,
        "storage_available_unit": "B",
        "storage_capacity": 0,
        "storage_capacity_unit": "B",
        "storage_vendor": "",
        "usb_storages": {},
        "wan_ipv4_conntype": "dhcp",
        "wan_ipv4_gateway": "***",
        "wan_ipv4_ipaddr": "***",
        "wan_ipv4_netmask": "***",
        "wan_ipv4_pridns": "***",
        "wan_ipv4_snddns": "***",
        "wan_ipv4_uptime": "***",
        "wan_ipv6_conntype": "dhcp6c",
        "wan_ipv6_enable": "on",
        "wan_ipv6_gateway": "***",
        "wan_ipv6_ip6addr": "***",
        "wan_ipv6_pridns": "***",
        "wan_ipv6_snddns": "***",
        "wan_macaddr": "***",
        "wireless_2g_airtime_fairness": "off",
        "wireless_2g_channel": "auto",
        "wireless_2g_current_channel": "3",
        "wireless_2g_disabled": "off",
        "wireless_2g_disabled_all": "off",
        "wireless_2g_disabled_by": "",
        "wireless_2g_enable": "on",
        "wireless_2g_encryption": "psk_sae",
        "wireless_2g_extinfo": {
            "support_band": "both",
            "support_guest_dynpasswd": "no",
            "wds_guest_compatible": "no"
        },
        "wireless_2g_hidden": "off",
        "wireless_2g_htmode": "auto",
        "wireless_2g_hwmode": "bgnax",
        "wireless_2g_macaddr": "***",
        "wireless_2g_mu_mimo": "off",
        "wireless_2g_port": "***",
        "wireless_2g_psk_cipher": "aes",
        "wireless_2g_psk_key": "***",
        "wireless_2g_psk_version": "sae_only",
        "wireless_2g_server": "",
        "wireless_2g_ssid": "***",
        "wireless_2g_txpower": "high",
        "wireless_2g_wds_status": "disable",
        "wireless_2g_wep_format1": "hex",
        "wireless_2g_wep_format2": "hex",
        "wireless_2g_wep_format3": "hex",
        "wireless_2g_wep_format4": "hex",
        "wireless_2g_wep_key1": "",
        "wireless_2g_wep_key2": "",
        "wireless_2g_wep_key3": "",
        "wireless_2g_wep_key4": "",
        "wireless_2g_wep_mode": "auto",
        "wireless_2g_wep_select": "1",
        "wireless_2g_wep_type1": "64",
        "wireless_2g_wep_type2": "64",
        "wireless_2g_wep_type3": "64",
        "wireless_2g_wep_type4": "64",
        "wireless_2g_wpa_cipher": "auto",
        "wireless_2g_wpa_key": "",
        "wireless_2g_wpa_version": "auto",
        "wireless_2g_wps_state": "configured",
        "wireless_5g_airtime_fairness": "off",
        "wireless_5g_channel": "auto",
        "wireless_5g_current_channel": "***",
        "wireless_5g_disabled": "off",
        "wireless_5g_disabled_all": "off",
        "wireless_5g_disabled_by": "",
        "wireless_5g_enable": "on",
        "wireless_5g_encryption": "psk_sae",
        "wireless_5g_extinfo": {
            "support_band": "both",
            "support_guest_dynpasswd": "no",
            "wds_guest_compatible": "no"
        },
        "wireless_5g_hidden": "off",
        "wireless_5g_htmode": "80",
        "wireless_5g_hwmode": "anacax_5",
        "wireless_5g_macaddr": "***",
        "wireless_5g_mu_mimo": "off",
        "wireless_5g_port": "***",
        "wireless_5g_psk_cipher": "aes",
        "wireless_5g_psk_key": "***",
        "wireless_5g_psk_version": "sae_only",
        "wireless_5g_server": "",
        "wireless_5g_ssid": "***",
        "wireless_5g_txpower": "high",
        "wireless_5g_wds_status": "disable",
        "wireless_5g_wep_format1": "hex",
        "wireless_5g_wep_format2": "hex",
        "wireless_5g_wep_format3": "hex",
        "wireless_5g_wep_format4": "hex",
        "wireless_5g_wep_key1": "",
        "wireless_5g_wep_key2": "",
        "wireless_5g_wep_key3": "",
        "wireless_5g_wep_key4": "",
        "wireless_5g_wep_mode": "auto",
        "wireless_5g_wep_select": "1",
        "wireless_5g_wep_type1": "64",
        "wireless_5g_wep_type2": "64",
        "wireless_5g_wep_type3": "64",
        "wireless_5g_wep_type4": "64",
        "wireless_5g_wpa_cipher": "auto",
        "wireless_5g_wpa_key": "",
        "wireless_5g_wpa_version": "auto",
        "wireless_5g_wps_state": "configured"
    },
    "success": true
}

No sign of information about the IoT network devices.

Thanks for the json! I can add IoT networks On/Off switches
Is there a routerā€™s UI page where is a IoT devices list?
If yes, could you check what url it requests with browser developer tools What are browser developer tools? - Learn web development | MDN
And put it like this

data = router._get_data('admin/status?form=all')

And get the json

Yes, I believe this is the correct URL:

/admin/wireless?form=iot_2g&form=iot_5g

And it returns this JSON:

{
    "success": true,
    "data": {
        "iot_2g_psk_version": "auto",
        "iot_2g_disabled_by": "",
        "iot_2g_encryption": "psk",
        "iot_5g_encryption": "psk_sae",
        "iot_5g_hidden": "off",
        "iot_2g_psk_key": "***",
        "iot_2g_enable": "on",
        "iot_5g_psk_key": "***",
        "iot_5g_disabled": "off",
        "iot_2g_psk_cipher": "auto",
        "iot_5g_disabled_by": "",
        "iot_5g_psk_version": "sae_transition",
        "iot_5g_ssid": "***",
        "iot_5g_psk_cipher": "aes",
        "iot_2g_ssid": "***",
        "iot_5g_enable": "on",
        "iot_2g_hidden": "off",
        "iot_2g_disabled": "off"
    }
}

Iā€™m currently trying to test with a new enum value WIFI_IOT_5G and router.set_wifi(Wifi.WIFI_IOT_5G, False) but I canā€™t get that working yet. I also took out form=guest at this line: https://github.com/AlexandrErohin/TP-Link-Archer-C6U/blob/daeed495d1452a63c88ae1308f84a4713514fe95/tplinkrouterc6u/client.py#L57

Iā€™ll try to put up a pull request if I figure it out.

I think my issue was single_request_mode - I have a few pull requests coming.

Thank you! I have made some comments on PRs
So there is no routerā€™s UI page where is IoT devices list shown? Like the wifi clients list shown

Ah, there is a web UI, at http://<ip_address>/webpages/index.html?t=***#networkMap.

Looks like this:

The relevant endpoints appear to be admin/smart_network?form=game_accelerator and admin/access_control?form=black_devices - based on the JS call stack, Iā€™m pretty sure the first one is the right endpoint. I tried passing them into _get_data() but am getting back Exception: An unknown response - {"errorcode":"no such callback","success":false}, so something else is missing.

I believe _prepare_data() needs to be used somehow, based on what I see in the browser debugger - the body/payload has sign and data included.

Hi! Iā€™m testing the integration with Archer AX10 and itā€™s working fine, but I noticed that the app Tether warn about ā€œother administratorā€ and Iā€™ve to log in again.
Does anyone know what could be?
Thx

Hi @Ljleonardo , as far as I know the TPlink Archer, only allows 1 administrator to be active.

1 Like

confirmed it works with TP-Link AX10

1 Like

Testing, but seems to work fine with Archer C6 V3.0

1 Like

Question:
Is it possible to do log in with TP link ID, not local password? I forgot mine and using TP link ID to log in to my router. Thank you

1 Like

Hi.
It is a local integration - so only local password works

1 Like

v1.2.5 Released

Changelog

I have 3 Archer A7 V5 routers.
All are configured as access point.
All have the same firmware. (1.2.1 Build 20220714 rel.75573)
The ip addresses end on xxx.xxx.xxx.3, xxx.xxx.xxx.4 and xxx.xxx.xxx.5 for the different Access Points.

3 is fully visible in HA
4 is showing message ā€œfailed to set upā€
5 is showing 2 home wizard devices that have complete different ip addresses

image

Deleting all 3 devices and adding only xxx.xxx.xxx.4 succeeds.
The same also happens with only xxx.xxx.xxx.5
Looks like the integration only works with 1 device at a time

Hey everyone how does the device tracking works, here it only found like 5 devices (counting with router), thanks yā€™all

Is there any logs from the integration in Settings->System->Logs ?

The integration tracks devices which are connected to the router via WIFI. In the router UI you can see a list of Wireless Clients. These clients are tracked by the integration