klattimer / LGWebOSRemote

Command line webOS remote for LGTVs
MIT License
508 stars 98 forks source link

`lgtv MyTV on ssl` command not working? #110

Closed tonycassara closed 1 year ago

tonycassara commented 1 year ago

Hey I've tried this a few different ways and cannot get it to work. I have wakeonlan installed, I have getmac installed, I have python3 installed and the off command actually does work. So I'm guessing it's something to do with wakeonlan. Anyone else?

DarkCeptor44 commented 1 year ago

wakeonlan doesn't work with every single device (TV, motherboard, etc), I think only the really expensive ones support it.

klattimer commented 1 year ago

is it plugged into ethernet, AFAIK no TV's support WoL over wifi

tonycassara commented 1 year ago

@DarkCeptor44 it worked before I'm on an LG OLED C2. @klattimer It absolutely worked over WiFi until the recent firmware update :(

FYI LGTV Companion still works no problem on Windows.

tonycassara commented 1 year ago

In fact it even says in the TV menu "Turn on via Wi-Fi" it's absolutely supported.

klattimer commented 1 year ago

@tonycassara fancy, mine doesn't do that. :(

tonycassara commented 1 year ago

@klattimer you dont have the LG OLED C2?

t-jonesy commented 1 year ago

@tonycassara can you check ~/.lgtv/config.json and see if there is a mac address? I have the C2 as well and mine was populated with "null".

I took a look at auth.py and saw it is using getmac to pull the address. getmac -v -dddd -4 $tv.ip.address showed me the error:

DEBUG    Not sending UDP packet, using network request method 'ArpingHost' instead
DEBUG    Attempting get() (method='ArpingHost', method_type='ip4', arg='172.17.0.8')
DEBUG    Running: '/usr/bin/arping --ridiculous-garbage-string'
DEBUG    Running: '/usr/bin/arping -f -c 1 172.17.0.8'
DEBUG    Method 'ArpingHost' failed for 'ip4' lookup
DEBUG    Raw MAC found: None
DEBUG    getmac took 0.0021 seconds

so I tried running the same arping command and got the error: arping: socket: Operation not permitted

A bit of googling led me to this https://wiki.archlinux.org/title/capabilities

getcap /usr/bin/arping returned nothing so I added the raw socket capability with: sudo setcap cap_net_raw+ep /usr/bin/arping

Then arping, getmac, and lgtv auth all started working properly.

tonycassara commented 1 year ago

@t-jonesy now we're getting somewhere! It has a MAC address but it's incorrect. I wonder if it's pulling the wrong address because I have two OLED C2 on the same network. The IP address is correct though. I tried deleting config.json and re-authorizing but it's still wrong. I tried running the command getmac -v -dddd -4 $tv.ip.address but don't get an error, just the wrong MAC address which doesn't belong to any device on my network 🤔 .

okay wow I just saw a pattern. imagine the MAC address is 30:7b:45:3b:2:6c but getmac returns 03:07:b4:53:b2:6c as the RAW MAC address. It's the same address with a leading zero added and the rest of the numbers shifted over. I have no idea if this is valid but I'm guessing this is my problem RAW vs actual MAC address?

tonycassara commented 1 year ago

TBH it makes no sense because I can perform off and screenOff just not on or screenOn. Which makes me think wakeonlan is the culprit because maybe it's expecting a different shape of MAC address than the RAW one output by getmac.

t-jonesy commented 1 year ago

TBH it makes no sense because I can perform off and screenOff just not on or screenOn. Which makes me think wakeonlan is the culprit because maybe it's expecting a different shape of MAC address than the RAW one output by getmac.

On uses a magic packet for wake on lan. The other commands are all using the API. Did you try manually correcting the mac on the config file?

tonycassara commented 1 year ago

That's it, it's the format of the mac address. If I run wakeonlan 30:7b:45:3b:02:6c it turns on correctly. So the culprit here is getmac.

tonycassara commented 1 year ago

Let's see what the fine folks at getmac have to say: https://github.com/GhostofGoes/getmac/issues/82 sheesh this is an exhausting trial lol.

tonycassara commented 1 year ago

@t-jonesy what version of getmac are you running? Maybe if I downgrade it will work. I looked at the source code and it all looks right... https://github.com/GhostofGoes/getmac/blob/56412aab460e73304b59c3dc8fb5520ce39f7ef7/getmac/getmac.py#L180

t-jonesy commented 1 year ago

@tonycassara it's a macOS/getmac issue

on arch:

[tjones@desktop ~]$ getmac --version
getmac 0.9.1
[tjones@desktop ~]$ getmac -v -dddd -4 172.17.0.3
DEBUG    Initializing 'ip4' method cache (platform: 'linux')
DEBUG    27 methods available: CtypesHost, ArpingHost, ArpFile, SysIfaceFile, FcntlIface, UuidArpGetNode, UuidLanscan, GetmacExe, IpconfigExe, WmicExe, ArpExe, DarwinNetworksetupIface, ArpFreebsd, ArpOpenbsd, IfconfigWithIfaceArg, IfconfigEther, IfconfigOther, IpLinkIface, NetstatIface, IpNeighborShow, ArpVariousArgs, DefaultIfaceLinuxRouteFile, DefaultIfaceIpRoute, DefaultIfaceRouteCommand, DefaultIfaceRouteGetCommand, DefaultIfaceOpenBsd, DefaultIfaceFreeBsd
DEBUG    9 type-filtered methods for 'ip4': CtypesHost, ArpingHost, ArpFile, UuidArpGetNode, ArpExe, ArpFreebsd, ArpOpenbsd, IpNeighborShow, ArpVariousArgs
DEBUG    5 platform-filtered methods for 'linux' (method_type='ip4'): ArpingHost, ArpFile, UuidArpGetNode, IpNeighborShow, ArpVariousArgs
DEBUG    5 tested methods for 'ip4': ArpingHost, ArpFile, UuidArpGetNode, IpNeighborShow, ArpVariousArgs
DEBUG    Current method cache: {'ip4': 'ArpingHost', 'ip6': 'None', 'iface': 'None', 'default_iface': 'None'}
DEBUG    Current fallback cache: {'ip4': '[<getmac.getmac.ArpFile object at 0x7f63f805f0d0>, <getmac.getmac.UuidArpGetNode object at 0x7f63f805f250>, <getmac.getmac.IpNeighborShow object at 0x7f63f805f160>, <getmac.getmac.ArpVariousArgs object at 0x7f63f805f1f0>]', 'ip6': '[]', 'iface': '[]', 'default_iface': '[]'}
DEBUG    Finished initializing 'ip4' method cache
DEBUG    Not sending UDP packet, using network request method 'ArpingHost' instead
DEBUG    Attempting get() (method='ArpingHost', method_type='ip4', arg='172.17.0.3')
DEBUG    Running: '/usr/bin/arping --ridiculous-garbage-string'
DEBUG    Running: '/usr/bin/arping -f -c 1 172.17.0.3'
DEBUG    Output from '/usr/bin/arping' command: b'ARPING 172.17.0.3 from 172.17.0.99 enp8s0\nUnicast reply from 172.17.0.3 [E4:5F:01:67:22:2A]  0.630ms\nSent 1 probes (1 broadcast(s))\nReceived 1 response(s)\n'
DEBUG    Raw MAC found: E4:5F:01:67:22:2A
DEBUG    getmac took 0.0379 seconds
e4:5f:01:67:22:2a

on ventura:


(lgtv-venv) tjones@Taylors-MBP lgtv-venv % getmac --version             
getmac 0.9.1
(lgtv-venv) tjones@Taylors-MBP lgtv-venv % getmac -v -dddd -4 172.17.0.3
DEBUG    Initializing 'ip4' method cache (platform: 'darwin')
DEBUG    27 methods available: CtypesHost, ArpingHost, ArpFile, SysIfaceFile, FcntlIface, UuidArpGetNode, UuidLanscan, GetmacExe, IpconfigExe, WmicExe, ArpExe, DarwinNetworksetupIface, ArpFreebsd, ArpOpenbsd, IfconfigWithIfaceArg, IfconfigEther, IfconfigOther, IpLinkIface, NetstatIface, IpNeighborShow, ArpVariousArgs, DefaultIfaceLinuxRouteFile, DefaultIfaceIpRoute, DefaultIfaceRouteCommand, DefaultIfaceRouteGetCommand, DefaultIfaceOpenBsd, DefaultIfaceFreeBsd
DEBUG    9 type-filtered methods for 'ip4': CtypesHost, ArpingHost, ArpFile, UuidArpGetNode, ArpExe, ArpFreebsd, ArpOpenbsd, IpNeighborShow, ArpVariousArgs
DEBUG    3 platform-filtered methods for 'darwin' (method_type='ip4'): ArpingHost, UuidArpGetNode, ArpVariousArgs
DEBUG    Test failed for method 'ArpingHost'
DEBUG    2 tested methods for 'ip4': UuidArpGetNode, ArpVariousArgs
DEBUG    Current method cache: {'ip4': 'UuidArpGetNode', 'ip6': 'None', 'iface': 'None', 'default_iface': 'None'}
DEBUG    Current fallback cache: {'ip4': '[<getmac.getmac.ArpVariousArgs object at 0x102da8610>]', 'ip6': '[]', 'iface': '[]', 'default_iface': '[]'}
DEBUG    Finished initializing 'ip4' method cache
DEBUG    Attempting to populate ARP table with UDP packet to 172.17.0.3:55555
DEBUG    Attempting get() (method='UuidArpGetNode', method_type='ip4', arg='172.17.0.3')
DEBUG    Raw MAC found: 0E:45:F1:67:22:2A
DEBUG    getmac took 0.0147 seconds
0e:45:f1:67:22:2a
tonycassara commented 1 year ago

I just want to use my TV like a monitor is that so much to ask?

t-jonesy commented 1 year ago

@tonycassara if you edit ~/.lgtv/config.json and correct the mac address it should work until the upstream issues get resolved

tonycassara commented 1 year ago

@t-jonesy oh of course I did that yesterday haha, but in the future at some point I'll have to auth again for whatever reason and will probably forget.

klattimer commented 1 year ago

so this looks very much to be an upstream issue with getmac - thanks for your time and effort on this.

tonycassara commented 1 year ago

@klattimer I'll notify you when there's some progress, hopefully it's just a quick version upgrade once it's plugged.

tonycassara commented 1 year ago

OK! Special thanks to @t-jonesy for helping move this forward. Here's a PR updating the version of getmac to prevent the incorrect parsing of MAC addresses: https://github.com/klattimer/LGWebOSRemote/pull/111