bitfocus / companion-module-android-tv

MIT License
2 stars 2 forks source link

Connection issues with Hisense TV (Running Android TV) #14

Open mrlad opened 5 months ago

mrlad commented 5 months ago

The very first time the module is added it connects to the Hisense Android TV, but the MAC address doesn't auto-populate like the help says it should. I can manually add the MAC but I suspect this is indicative of a bigger issues. Once you disconnect and try to reconnect, the module gets stuck in a permanent "Connecting" state.

mrlad commented 5 months ago

Two initial questions:

  1. Is auto-population of the MAC working in the 3.2.2 Android TV module? If not, is any functionality lost?
  2. Pairing isn't working either. Is pairing required to turn the TV on/off? All I need the module for is to remotely turn the TV on/off.
mrlad commented 5 months ago

I see these statements in the log

Instance/Controller: Adding connection companion-module-android-tv androidtv
Instance/ModuleHost: Starting connection: "androidtv"(ClientID)
Instance/ModuleHost: Connection "androidtv" started
Instance/ModuleHost: Registered module client "ClientID"
Instance/Controller: instance "androidtv" configuration updated
Instance/Wrapper/androidtv: Searching for Devices.
Instance/Controller: instance "androidtv" configuration updated
Instance/Controller: instance "androidtv" configuration updated
Instance/Wrapper/androidtv: Searching for Devices a second time.
Instance/Wrapper/androidtv: Searching for Devices a third time.
zerbzman commented 5 months ago

Hey,

Yeah, I recently tested this with an android tv and the auto-population wasn't working reliably. I'll take a look at this and see if I can get this working and more reliable again.

mrlad commented 5 months ago

Thanks @zerbzman. I just realized that I didn't capture the biggest issue in the bug report.

Turning on the TV is very unreliable (only seems to work once during the initial connection) and turning it off doesn't work at all.

scotttroyer commented 5 months ago

I can verify a similar scenario on TCL tvs running Android TV. They don't respond to power on commands, but do respond to power off and other commands.

zerbzman commented 5 months ago

Ahh, yeah that means the MAC address isn't being used. Those tvs and a lot of tvs use a wake on lan packet to turn on. I'll see if I can fix that here soon.

scotttroyer commented 5 months ago

Thank you, @zerbzman!

mrlad commented 5 months ago

Ahh, yeah that means the MAC address isn't being used. Those tvs and a lot of tvs use a wake on lan packet to turn on. I'll see if I can fix that here soon.

WoL packets work on the HiSense too to turn on the TV. The issue I have with WoL is I need to access the TV from a different subnet so a subnet broadcast wouldn't work for me.

zerbzman commented 5 months ago

Hey! Here is a version to test.

  1. Go to this url. https://github.com/bitfocus/companion-module-android-tv/tree/issue-%2314-fix-mac-address-and-user-flow
  2. Download the Zip
  3. If you haven’t used a custom developer module before, it’s super simple. Here are some instructions. You just have to do step 4 and 5. https://github.com/bitfocus/companion-module-base/wiki#4-clone-the-module
    • In step 4, you just have to make the folder. Don’t worry about cloning anything.
  4. Unzip the downloaded plugin into the created folder.

Please test this out and let me know if you run into any issues or it fails. Thanks

mrlad commented 5 months ago

Hi @zerbzman , took me a second to figure out where the zip file was but I found it.

I tried it but it kept immediately crashing with an unhandled exception.

Unhandled error restarting connection: Error: Restart forced

Never got to the settings screen.

scotttroyer commented 5 months ago

Same here. I couldn’t configure anything. Kept crashing. 

zerbzman commented 5 months ago

Ok, sorry for the confusion. Would you mind clicking on this button >_ next to the trash can icon. That shows the logs for just that module and should show more info. Thanks!

Screenshot 2024-04-03 at 9 16 21 AM
mrlad commented 5 months ago

Here's the exception details

error: node:internal/modules/cjs/loader:1080

  throw err;

  ^

Error: Cannot find module '@companion-module/base'

Require stack:

- f:\media\documents\Companion\devModules\companion-module-android-tv-issue-14-fix-mac-address-and-user-flow\main.js

    at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)

    at Module._load (node:internal/modules/cjs/loader:922:27)

    at Module.require (node:internal/modules/cjs/loader:1143:19)

    at require (node:internal/modules/cjs/helpers:119:18)

    at Object.<anonymous> (f:\media\documents\Companion\devModules\companion-module-android-tv-issue-14-fix-mac-address-and-user-flow\main.js:1:64)

    at Module._compile (node:internal/modules/cjs/loader:1256:14)

    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)

    at Module.load (node:internal/modules/cjs/loader:1119:32)

    at Module._load (node:internal/modules/cjs/loader:960:12)

    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:86:12) {

  code: 'MODULE_NOT_FOUND',

  requireStack: [

    'f:\\media\\documents\\Companion\\devModules\\companion-module-android-tv-issue-14-fix-mac-address-and-user-flow\\main.js'

  ]

}

Node.js v18.18.1
zerbzman commented 5 months ago

@mrlad my apologies, the way that I told you to set this up won't work. Can you and @scotttroyer shoot me an email at my GitHub username at gmail.com? I'll send you a dropbox link to the module to test.

scotttroyer commented 5 months ago

@zerbzman thank you for sending the files via Dropbox. I've just tested this new module on a clean install of Companion running on an Apple MacBook Air M1. I am able to input the IP address and pair the device. It auto-detects the TV's wireless MAC address. All actions seem to work fine except powering on the device.

I tried the default "androidtv: Set Power State" action as well as the "androidtv: Send Button Command" action with the 4 different available "power" commands.

Screenshot 2024-04-06 at 12 37 59 PM

I'm wondering if there's an issue here with the specific TV I have. In the opening part of your set up guide, my TV's settings don't look exactly the same as your's below. I hit the cog button, click on a cog icon, go to Network & Internet, but don't see the Networked Standby anywhere.

TV Setup For this to turn on the tv you need to turn on Networked Standby.

  1. Hit the Settings Cog Button on your remote.
  2. Go to More Settings
  3. Select Network & Internet
  4. Scroll down to Networked Standby and turn it on.

About the TV

TCL Model Number: 43S350G Software Version: V8-T221T04-LF1V080.000507 Android TV Model: Smart TV ANdroid TV OS Version: 11 Kernel Version: 4.19.116+ # 1 Thu Jun 20 16:08:20 CST 2023 Android TV OS Build: AR2101 Both the System and Service Updates are current. Connected to the network via Wifi with a static IP

Other things I've tried

I found this Reddit post, which maybe implies that some TCL TVs do power the network card when in standby mode.

scotttroyer commented 5 months ago

I've also just confirmed that the TV is not pingable when the power is off. Looks like this particular model may not be able to be powered on from standby via network. Perhaps which is why the "Networked standby" option is not shown as an option on this TV. 😔

zerbzman commented 5 months ago

Thanks @scotttroyer! I've been down that rabbit hole of trying to keep the TV in a "waked" state but nothing worked for me. I did have an issue where I factory reset the TV but then it had a different OS version and that version did not work with this plugin. Eventually it updated but that was frustrating.

What Networked Standby does is turn on the TV when someone casts to it. You could see if there is any option for that. You could also test if you can cast from your phone to it.

Another thing you could test is a wired connection.

Also just thought I would say that Networked Standby on my tv is between IP Settings and Check Internet Connection.

scotttroyer commented 5 months ago

@zerbzman, I did get this to work (with some caveats) after trying your suggestion to cast to the TV. Here's what worked:

  1. I had never signed into a Google account on the TV. We never needed the TV content features that it and other platforms supply. The TV is just a monitor for our house video feed. But I went ahead and signed into a Google account.
  2. The TV installed some stuff and rebooted. The "Networked standby" feature became visible and I turned it on.
  3. I retried the "Power On" action within Companion. No luck. Same as before.
  4. I couldn't cast to the TV from my MacBook Air even though the name appeared in the list of mirroring option in macOS 14.4.1. Mirroring would time out/fail. (That function still doesn't work.)
  5. I installed the Google TV app on my iPhone. Finally I was able to cast to the TV as well as power on/off from the app. LanScan shows the TV as unpingable/offline when the TV is in standby/powered off mode, but since the app could power on the TV from standby, I knew that it was at least possible somehow to power on this model of TCL from standby.
  6. I retried the actions in the Companion module. The "androidtv: Set Power State" action still does not power on the TV.
  7. However! The "androidtv: Send Button Command" action does turn on the TV with select button set to "KEYCODE_POWER". None of the other "power" buttons (i.e. KEYCODE_TV_POWER, KEYCODE_STB_POWER, KEYCODE_AVR_POWER) will turn on the TV. And this send button command method doesn't always work. Sometimes the command has to be sent more than once before the TV responds. Here is a CSV of the module log while trying the various power on methods. module-log.csv

So, for now this is working, but not super reliably. I really appreciate your help on this module.

scotttroyer commented 5 months ago

Ugh...replied too soon.

When a Google account is signed in, the TV no longer obeys the "Power On Behavior" of "Last used input" and instead defaults to the Google TV home screen every time. Not a big deal, but the "androidtv-lobby: Send Button Command" with Select Button "KEYCODE_TV_INPUT_1" action no longer works either, so there is no way to change the input to our feed.

I've removed the Google account, which factory reset the TV. Going to keep using the TCL in Basic TV mode for now so it will power up with the correct input.

mrlad commented 5 months ago

Tried the dropbox version. Was able to pair two TVs. I am able to power off the TVs, but I can't power them on.

I have a standalone WoL app that I can send the WoL magic packet and wake up the TVs. but no luck from the Android TV module. Interestingly enough, the Companion WoL module doesn't work either to wake up the TVs. Windows, Android and iOS WoL apps do work to turn on the TV.

zerbzman commented 4 months ago

@mrlad Here is another thing you can try. I remember you saying that the TVs are on another subnet and it sounds like you are running companion on a windows computer.

Can you try using the Companion Wake on LAN module and change the Destination IP to the following pattern: "192.168.1.255" where the first three blocks are the first three blocks of the TV ip address. Everything else can stay the default, besides the Mac address of course. Also, you can also try hitting the button twice or separated by 3 seconds.

zerbzman commented 4 months ago

@scotttroyer Aw man, that was a roller coaster. Nice job on troubleshooting that and thinking that through. That's a bummer to hear that it always loads to the home screen. On my TV, the input button command doesn't actually do anything so that was interesting to hear that it actually worked. When I first tested all the buttons I found that on my TV the KEYCODE_F3 button brought up the input screen and then I could use the arrow keys to set the input. You might be able to try that. You could hit the KEYCODE_F3 button, then hit the KEYCODE_DPAD_UP button 3 times, and hit the KEYCODE_DPAD_CENTER button to select it. If you go to the preset tab in companion, I made some presets for navigation that helps. Or, I'm just testing this on my TV right now, if I have the home screen up and then hit the F3 button, I just have to hit the DPAD Center button ("OK" in my preset) and it will go back to the HDMI input. That might work for you. You may just have to play around with the timing of the commands in Companion.

As for powering the TV on, I sent you an email with an updated version of the module to include the regular power on command to the TV when using the power state action. It basically sends both the Wake on Lan command and the power command at the same time. I also found when initially working on this plugin that powering on the TV using Wake on lan was pretty inconsistent. I stumbled on success sending the command multiple times and found that a three second gap between commands was the sweet spot. Hopefully this can remedy the power issue for you.

Let me know how it goes!

mrlad commented 4 months ago

@zerbzman , for the purposes of simplifying testing, the report above was using the WoL functionality on the same subnet (the real use case is in fact on a different subnet, but for now, I'm trying to limit complexity).

Given that I was testing on the same subnet, would the x.y.z.255 broadcast make any difference?

Also, you can also try hitting the button twice or separated by 3 seconds.

I did use the retry option for the Companion WoL module and that didn't help, but I'll try with your module also.

mrlad commented 4 months ago

On the same subnet, I increased the retry window for the Companion WoL module from 100ms to 3000ms and used the x.y.z.255 address. This has worked two of the three times I pressed the button. I'm unsure if its the retry window that made the difference or the broadcast address.

mrlad commented 4 months ago

Went back to the 100ms retry window and the x.y.z.255 address and this continues to work. So it would appear the broadcast address is the key not the duration of the retry window.

zerbzman commented 4 months ago

@mrlad Awesome. Yeah, a manual broadcast address is really what I was looking for. I looked back at the wake on LAN library that this module and companion's module uses and it mentions that on a windows computer the wake on LAN utility works differently than on Unix machines because of limitations on windows and it needs a manual broadcast address. I'll have to do a little bit of work but I'll see if I can fix that relatively soon and send you a version.

Thanks for testing both of those.

mrlad commented 4 months ago

Thanks for the update @zerbzman . Our use case is a Windows box (same subnet/VLAN) and a Mac (different subnet/VLAN). I'm assuming the Mac would be considered *nix from the WoL companion module perspective? I haven't tested the Mac with your new code yet.

zerbzman commented 4 months ago

@mrlad Gotcha, yes sorry the Mac is Unix so it should work but I would be curious if there would be any issues with the different subnet.

mrlad commented 4 months ago

Hi @zerbzman , tried your latest drop. I have two TVs I'm testing w/this module. Both don't turn on with the first power on attempt. They do turn on the second attempt (assuming I wait at least 3-5 seconds).

zerbzman commented 4 months ago

@mrlad Awesome! It should automatically send another wake command at 3 seconds to turn it on. Can you try it again without a second manual command and let me know how it goes? Thanks

mrlad commented 4 months ago

@zerbzman , sorry for not being clearer. I did try with only one power on command and that didn't work. I had to press the button a second time to get it to work.

mrlad commented 4 months ago

So I tried adding four power on commands per button press, didn't help. It wouldn't turn on. I have to press the button twice for the TV to wake up and come out of standby.

mrlad commented 4 months ago

I tried an experiment. I had a assumed the first power on command wasn't working. I may not have been waiting long enough. Seems like the second press turns on the TV after about 10-12 seconds. The first press I waited up to 30 seconds (sometimes it turns on in the 10 second window, sometimes it doesn't).

How many retries are you doing and how frequently are the retries happening?

zerbzman commented 3 months ago

Hey @mrlad, sorry for the delay. This plugin sends a wake command and then again after 3 seconds. That was the sweet spot in my testing. I can try to make a version that sends a third command at 6 seconds. I'll test that and send a version to you.

mrlad commented 3 months ago

Thanks @zerbzman .

mrlad commented 1 month ago

@zerbzman, having quite a few problems with the new drop.

  1. Frequently gets disconnected from the TV after a few standby attempts.
  2. Caused companion to crash the first time I loaded it (with the caveat I just unzipped the directory while Companion was running). Haven't seen the crash except the first time.
  3. When disconnected, I see a "Child is not running, unable to send message" error over and over.
  4. Unfortunately, even when it works, I see no improvement in reliability coming out of standby.
zerbzman commented 1 month ago

Hey @mrlad, so I found that using the WIFI connection on the TV is way more reliable than using the Ethernet connection for turning on and off the TV. I'm doing some testing to see if I can help the ethernet connection but in the meantime I would suggest testing out the Wifi connection and seeing if it resolves your problems.

mrlad commented 3 weeks ago

Tried v5. Here are my findings

Tried the 30 second retry. Didn't notice an appreciable difference (turns on sporadically).

When it did turn on, it was about 6-12 seconds after the original PowerOn request.

mrlad commented 3 weeks ago

Did some more experimenting tonight.

My Windows WoL app works reliably to turn on our two TVs when I have the "Internet" send option activated. If I switch the send option to "local network" is becomes very unreliable. Unsure what the technical difference is between the two but functionally, one is intended for access outside the local subnet so I'm guessing its a broadcast option.

Also, one time the code got stuck in a retry state and I had to kill/restart companion to recover.