-
Notifications
You must be signed in to change notification settings - Fork 61
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
Idea: implement input via monkeyrunner for low latency remote control #139
Comments
You know a lot more about this than me! I haven't heard of people complaining about ADB being slow with Nvidia Shield devices. I have no experience with Sony Bravia TVs. You're welcome to submit a pull request, or fork the repo and the HA component and modify them however you'd like. |
Trust me, I don't! I've hacked up a simple proof of concept script with a slightly modified monkeyrunner module to see how fast this method can actually be on real devices. Keeping monkey+adb alive is tricky and I'm doing it by force now because my coding skills are very limited but it works as a demo. Results are promising, although these are only request execution times they reflect a lot of the actual latency difference.
|
I took a look at this. I don't see why a Flask server is necessary. If you want to implement monkeyrunner functionality for this package, you would need to modify https://github.com/nlitsme/PythonMonkey so that it can use an I think the only file that you really need from that repo is |
While I realize this thread is pretty old, I wanted to corroborate that the shield tv commands are pretty slow through the pipeline. My experience is consistent with the above statement. It's fine for single commands. Navigation is one-off ux at best. The coding for the solution above is beyond me at the moment, but I'm more than happy to help, and test if anyone decides to work on this. I would love to help. |
@stainlessray I don't think it's ADB that is the bottleneck. I rewrote the HA component and the backend libraries to be async, thinking maybe that was the issue, but it didn't make much difference, if any. In a terminal, outside of HA, I used this async Python code to send 100 shell commands to a Fire TV stick: EDIT: the If you want to try the async version of the integration, here it is. You have to use the Python ADB implementation; using an ADB server is not supported. https://github.com/JeffLIrion/ha-androidtv/blob/async/custom_components/androidtv |
I looked into this a bit. From https://android.googlesource.com/platform/development/+/master/cmds/monkey/README.NETWORK.txt:
The instructions use port 1080, but I changed it to 12345 to match what's in the linked monkeyrunner Python repo. In terms of implementing this, I think the steps are:
# tell the device to listen to your local port
adb_device._service(b'reverse', b'tcp:12345;tcp:12345')
# forward your local port to the device
# TODO
|
Another idea is to convert Steps:
|
I'm currently searching for a good solution to control both my android devices: a slower Bravia and a Shield TV Pro.
Of course we have adb input but it is slow as heck on both my devices (~2s) because it spawns a new jvm process for each sent command- it's good enough for single commands like pause or volume control but it sucks for d-pad navigation for instance.
I'm disabled and have to use all my devices without any physical control so all my remotes should be exposed in some way in Home Assistant (lovelace cards, services, alexa commands etc).
For Bravia specifically we already have three different API's but even those have it's flaws (ie: actually harder to keep the server alive and responsive than adb mostly due to TVs lack of memory). If you've ever had to power cycle or reboot your TV because sony PSK API refuses to answer because it crashed you know what I mean.
So, after some github searching I've found this neat java app called ADBKeyMonkey that uses the native monkeyrunner API to forward local input (which is a different thing than monkey, usually used to launch intents/app).
It just requires a normal adb connection, and it's very low latency.
I don't wanna mess with java and the official monkeyrunner python module only works with pre-historic Jython 2.5. I played with it a bit and was set on writing a tiny websocket server script as a demo but the Jython requirement still sounded bad. Luckily someone made this compatibility layer and after a bit of fiddling I'm now writing a few sample scripts in Python 3 and figuring out how to properly keep the connection alive based on ideas from the ADBKeyMonkey.
I'm a newbie coder but I hope this gives some ideas for the brighter minds, so drop your thoughts.
The text was updated successfully, but these errors were encountered: