Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you use this? #362

Open
sybadm opened this issue Nov 11, 2023 · 6 comments
Open

How do you use this? #362

sybadm opened this issue Nov 11, 2023 · 6 comments

Comments

@sybadm
Copy link

sybadm commented Nov 11, 2023

How to use this? there are no examples or README has very limited information

@Vaskivskyi
Copy link
Owner

Hello. Sorry, I have completely missed your issue.

A better documentation will be added soon to cover all the basic usage examples. For now, I can give you a couple of small examples:

import aiohttp
import asyncio
from asusrouter import AsusRouter, AsusData

# Create a new event loop
loop = asyncio.get_event_loop()

# Create aiohttp session
session = aiohttp.ClientSession()

router = AsusRouter(
    hostname="192.168.1.1",
    username="admin",
    password="admin",
    use_ssl=True,
    session=session,
)

# Connect to the router
loop.run_until_complete(router.async_connect())

# Now you can use the router object to call methods
data = loop.run_until_complete(router.async_get_data(AsusData.NETWORK))
print(data)

# Remember to disconnect and close the session when you're done
loop.run_until_complete(router.async_disconnect())
loop.run_until_complete(session.close())

E.g. you can ask for the following AsusData:

AIMESH, BOOTTIME, CLIENTS, CPU, DEVICEMAP, FIRMWARE, GWLAN, LED, NETWORK, NODE_INFO, OPENVPN_CLIENT, OPENVPN_SERVER, PARENTAL_CONTROL, PORT_FORWARDING, PORTS, RAM, SYSINFO, TEMPERATURE, VPNC, VPNC_CLIENTLIST, WAN, WIREGUARD_CLIENT, WIREGUARD_SERVER, WLAN

Availability of data depends on your device model and FW version

You can also set a state of something. E.g. with the base commands:

from asusrouter.modules.led import AsusLED
from asusrouter.modules.parental_control import AsusParentalControl
from asusrouter.modules.port_forwarding import AsusPortForwarding

router.async_set_state(AsusLED.OFF)
router.async_set_state(AsusParentalControl.ON)
router.async_set_state(AsusPortForwarding.ON)

Don't forget, that you need to run async methods properly, e.g. like shown in the example before

@sybadm
Copy link
Author

sybadm commented Nov 25, 2023

thank you so much really appreciate it

@odd86
Copy link

odd86 commented Jan 2, 2024

Hello, I try to disconnect and connect a client (talking about a device), but I struggle to find out how to do it.
I can fetch the info, find the client, and run process_disconnected() but I'm not sure how to set the state on the Router

PS: Very nice work you have done!

@Vaskivskyi
Copy link
Owner

Hello, @odd86,

There is no currently a possibility to disconnect one single client from the router. I would need to check whether this is possible at all. What is your use case for this? Do you want to:

  1. Reconnect a wireless client (because of some issue)
  2. Block a client from internet access
  3. Block a client from local network access

All those would actually be different functions and they are not obligatory overlapping. But we can work on this

@odd86
Copy link

odd86 commented Jan 4, 2024

Hello, I found a way and it is to use ParentControl.
All I wanted was to automate access to the internet.

I made this function inside of a class

  async def toggle_internet_access(self, enable):
        rule_type = PCRuleType.BLOCK if not enable else PCRuleType.DISABLE
        rule = ParentalControlRule(mac=self.mac, type=rule_type)
        success = await self.router.router.async_set_state(state=rule)
        return success

Then I keep track of the time the device is online before it is disconnected by a cronjob (if time is out).

Thanks a lot for taking time to respond, and I hope my reply helps others :)
Your SDK is very nice to use!

@53b4
Copy link

53b4 commented Jun 23, 2024

Hello, Great project and it could be very useful.
I found that there is much more functionality that we have when we installed ASUS mobile application; we can add family members, set bandwidth per devices and so on. Unfortunately application is only for mobile devices, not for PC .

So, here is my question - there additional functions we have are because application or additional part of API, that is not documented yet ?

Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants