Package: tplinkrouter
TP-Link Archer C50 APIHTTP based python package for API access and router management of the TP-Link Archer C50Version 1.0.0DependenciesrequestsUsageInitializeEnter your hostname/IP & credentials used to log in to your router management pageimporttplinkrouterrouter=tplinkrouter.C50('hostname','username','password')OPTIONAL:You may also pass a logger asrouter = tplinkrouter.C50('hostname','username','password',_LOGGER)to log errors instead of printing themBuilt-in Functions (v0.3.0+)router.about()# Return{'modelName':'Archer C50','description':'TP-Link Archer C50 AC1200 Dual-Band'}router.get_clients()# Return['johns-iphone','macbook-pro','android-c78df7av3c5d4ba43cad65c6']router.get_password('MYSSID1')# Return'mypassword24ghz'router.set_password('MYSSID1','bobsyouruncle')# Disable SSID broadcast of MYSSID2router.set_ssid_state('MYSSID2',False)# Disable 5GHz Bandrouter.set_band('5GHz',False)FunctionArgsDescriptionReturnaboutGets basic info about the router{ 'modelName', 'description' }get_versionGets hardware and software version of the router{ 'hardwareVersion', 'softwareVersion' }get_clientsGets list of connected clients (host name) including DHCP & permanent leases, across both wifi and LANList of stringsget_clients_by_macGets list of connected clients (MAC Address) including DHCP & permanent leases, across both wifi and LANList of stringsget_wlansGets details of wlans (by internal wlan name) including guest network wlans on both bandsDict of Dictsget_ssidsGets list of ssids including guest network wlans on both bandsList of stringsget_passwordssid ->str: requiredGets WPA2 PSK of specified SSIDstringset_passwordssid ->str: requiredpassword ->str: requiredSets new WPA2 PSK of specified SSIDbooleanset_ssid_statessid ->str: requiredstate ->boolean: requiredEnables/disables SSID broadcast of the specified SSIDbooleanset_bandband ->2.4GHzor5GHzstate ->boolean: requiredEnables/disables specified bandbooleanis_onReturns whether or not the device is powered onbooleanrestartDoes what it says on the canbooleanlogoutDoes what it says on the canbooleanInternal Function: _get()Internal function used to access different named commands. You may use this if you want direct access to the router's return data without the cleanup done by built-in functionsrouter._get('wlan')Supported Parameters:aboutversioninfobandswanwlanwlan_infoguest_24ghzguest_5ghzdhcp_settingsdhcp_clientsrestartlogoutReturn Format: DictionaryInternal Function: _set()Internal function used to run differentsetprocesses. You may use this if you want to directly set the router's parameters without the processing done by built-in functionsChange Password of 2.4Ghz Network:router._set('24ghz',[{'[LAN_WLAN#1,1,0,0,0,0#0,0,0,0,0,0]0,5':{'X_TP_PreSharedKey':'new_password'}}])Enable/Disable WAN PPPoE:# Enablerouter._set('wan',[{},{'[WAN_PPP_CONN#1,1,1,0,0,0#0,0,0,0,0,0]1,19':{'enable':'1'}},{}])# Disablerouter._set('wan',[{},{'[WAN_PPP_CONN#1,1,1,0,0,0#0,0,0,0,0,0]1,19':{'enable':'0'}}])Return Format: BooleanSupported Parameters:wan24ghz5ghz24ghz_band5ghz_band_set()only updates the keys passed in argument 2. All other values are either fetched from the router wherever available.Note 1: Value FormatAll key/values passed in Argument 2 of_set()must be strings.Argument 2 passed to_set()mustbe a List of Dictionaries.Note 2: Positional ArgumentsEach list item in Argument 2 of_set()directly corresponds to each subtask in the process.Omitting an item in the list will ignore that subtask. (See Example: Disable WAN PPPoE, index[2] omitted)To run a subtask without updating any of its values, pass an empty dictionary in its position.Note 3: Status CodeInternal functions return an additional keystatus_codewith the HTTP status code of the request. Remember to ignore this key before iterating through returned Lists or Dicts.ModelsThis has only been tested on the TP-Link Archer C50 V1 running firmware 160411.Supported Models (known):TP-Link Archer C50 V1TP-Link N600
You're free to test on other models and report them in the Issues tab.Error 500 & Login LimitThe TP-Link Web Interface only supports upto 1 user logged in at a time (for security reasons, apparently) which is the most common reason to recieveHTTP ERROR 500. As a workaround, you must log out from all other devices/browsers and try again. Additionally, you may also runrouter._get('logout')Troubleshooting/Error Reporting/ContributingIf you face an error, you may debug using a HTTP Requests tool/monitor on your router's configuration webpage. Additionally, you may open a new issue on this repo prefixed by [Bug]If you would like to help improve the package, request features or add support for more models, open an issue prefixed by [Feature Request] or [Improvement]PRs and Commit TemplatePRs and commits that you make to this repo must include the following:Type: bug-fix or enhancementDescription: Brief description about what the commit achievesNotes: (heads ups/pointers to other developers if necessary)Changelogv1.0.0First major release!Cleanupv0.3.0Logging supportNew return format that addsstatus_codePerformance Optimization: Logout session after commands to minimize Error 500 instancesRemove unnecessary I/Ov0.2.1Add band control togglesv0.2.0Introducing built in functions! Predefined commands for the most commonly used tasks, so you don't have to manually figure out the payloads.v0.1.3Fix pip deploy bugv0.1.2Fix pip import bugv0.1.1Remove AIOHTTP Dependencyv0.1.0Python Package