Maassoft / ColorControl

Easily change NVIDIA display settings and/or control LG TV's
GNU General Public License v3.0
892 stars 41 forks source link

Some bugs and a question #13

Closed JPersson77 closed 3 years ago

JPersson77 commented 3 years ago

Hi there,

I am using your app to mainly start and shutdown my LG CX 48 on system startup/shutdown/suspend, and it works somewhat ok. But for me at least it does not work 100% yet. I will give some feedback here (using latest v.1.5.0.0 but notice the behaviour earlier as well)

1) When the PC starts up from restart or cold boot, and the option to 'wake screen on startup' is enabled I get the below error message.

CC error on starup

I suspect that since the display is not powered on (and there are no other displays to enumerate) this function call fails, which crashes the application basically. If the screen is already powered on when windows launches then this error does not occur.

2) Screen does not always power off reliably when system is suspending or restarting/shutting down. I suspect that the application could benefit from preventing the system from suspending until tasks have been performed properly, maybe check out https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate . Does not matter if I run wireless or cable connection for the screen. PC is always wired.

And I have a question for you. I've been looking into coding a c/c++ command line utility for controlling power on and off for my CX, nothing more and nothing less. But it's just dead ends so far. I have determined I cannot use "IP control" since my screen is a european model, and IP control is US only presumably (could try switching the set to US, but I'm pretty sure that it wont' work). I also established I cannot use RS-232 since there is no RS-232 input (which I figured out after I had already soldered a cable LOL) on the specific model I have (OLED48CX6LB). Which leaves me with figuring out the WebOS control that you are using for ColorControl. But from my reading it seems to be somewhat reverse engineered and not properly documented by LG. bit proprietary.I did check out your c# code but did not follow everything, so can I trouble you for more information? Specifically how to specifically establish connection and start sending commands. Noticed port 3000 is involved, but cannot succeed telnetting into that port with putty to start testing things out. I must be missing something...

Maassoft commented 3 years ago

Thanks for your feedback! I will investigate the bugs you posted. I suspect the first one is actually retrieving the display settings from the Nvidia driver, but it appears no Nvidia device is driving a display at the moment. I have not encountered that issue before personally, but maybe it's fixable by exception handling and letting the rest of the code (sending a signal to the display to wake up) execute. When the display has woken up, enumeration of the displays will probably work again.

I have not heard of "IP control" before, but after reading it seems that it's also used to send a WOL packet to the tv? At least that's what I'm reading here: https://proforums.harman.com/amx/discussion/125095/lg-tvs-ip-control I'm using the Sharppcap package to send a WOL packet to all networks connected to the pc and this packet contains the MAC address of the tv. I don't know if this is easily done in C/C++. At first I was using a NodeJs app, it's pretty easy to turn the tv off at least with this app (see: https://github.com/hobbyquaker/lgtv2). But turning it on via WOL is not possible because it seems that when the tv is in standby mode, you cannot connect to it. But yes, for this connection port 3000 is used.

JPersson77 commented 3 years ago

IP control is another way of sending commands to the TV. It is pretty similar to the serial (RS-232 protocol) where control codes are sent for things like volume setting, options, channel etc. System automation basically. the protocols also include commands for powering on and powering off. Only caveat, like you know already, is that a WOL package is (sometimes) needed to "force" the screen to awake and so the interface is active and the screen can actually listen to commands from the client.

But I can't use any of the above protocols for reasons mentioned unfortunately. Sending a WOL is not a problem though, that I can solve and works correctly. But understanding how to communicate with the webos is a problem so far. I read in your LgTvApi.cs (and in older documentation by msloth, and gr4b4z) that there is a certain handshake which needs to be sent to port 3000. When I try to do this I get absolutely nothing back and the TV just close the connection (using RAW in Putty). This should normally trigger the yes/no prompt on the TV and I assume I should get a session_key back. But I'm kinda stuck here. Do you have the opportunity to help me get a little further I appreciate it. Are there steps to take before sending that handshake request? Am I going about this wrong?

This is the handshake string I send to the TV on port 3000 for reference:

{"type":"register","id":"register_0","payload":{"forcePairing":false,"pairingType":"PROMPT","manifest":{"manifestVersion":1,"appVersion":"1.1","signed":{"created":"20140509","appId":"com.lge.test","vendorId":"com.lge","localizedAppNames":{"":"LG Remote App","ko-KR":"리모컨 앱","zxx-XX":"ЛГ Rэмotэ AПП"},"localizedVendorNames":{"":"LG Electronics"},"permissions":["TEST_SECURE","CONTROL_INPUT_TEXT","CONTROL_MOUSE_AND_KEYBOARD","READ_INSTALLED_APPS","READ_LGE_SDX","READ_NOTIFICATIONS","SEARCH","WRITE_SETTINGS","WRITE_NOTIFICATION_ALERT","CONTROL_POWER","READ_CURRENT_CHANNEL","READ_RUNNING_APPS","READ_UPDATE_INFO","UPDATE_FROM_REMOTE_APP","READ_LGE_TV_INPUT_EVENTS","READ_TV_CURRENT_TIME"],"serial":"2f930e2d2cfe083771f68e4fe7bb07"},"permissions":["LAUNCH","LAUNCH_WEBAPP","APP_TO_APP","CLOSE","TEST_OPEN","TEST_PROTECTED","CONTROL_AUDIO","CONTROL_DISPLAY","CONTROL_INPUT_JOYSTICK","CONTROL_INPUT_MEDIA_RECORDING","CONTROL_INPUT_MEDIA_PLAYBACK","CONTROL_INPUT_TV","CONTROL_POWER","READ_APP_STATUS","READ_CURRENT_CHANNEL","READ_INPUT_DEVICE_LIST","READ_NETWORK_STATE","READ_RUNNING_APPS","READ_TV_CHANNEL_LIST","WRITE_NOTIFICATION_TOAST","READ_POWER_STATE","READ_COUNTRY_INFO"],"signatures":[{"signatureVersion":1,"signature":"eyJhbGdvcml0aG0iOiJSU0EtU0hBMjU2Iiwia2V5SWQiOiJ0ZXN0LXNpZ25pbmctY2VydCIsInNpZ25hdHVyZVZlcnNpb24iOjF9.hrVRgjCwXVvE2OOSpDZ58hR+59aFNwYDyjQgKk3auukd7pcegmE2CzPCa0bJ0ZsRAcKkCTJrWo5iDzNhMBWRyaMOv5zWSrthlf7G128qvIlpMT0YNY+n/FaOHE73uLrS/g7swl3/qH/BGFG2Hu4RlL48eb3lLKqTt2xKHdCs6Cd4RMfJPYnzgvI4BNrFUKsjkcu+WD4OO2A27Pq1n50cMchmcaXadJhGrOqH5YmHdOCj5NSHzJYrsW0HPlpuAx/ECMeIZYDh6RMqaFM2DXzdKX9NmmyqzJ3o/0lkk/N97gfVRLW5hA29yeAwaCViZNCP8iC9aO0q9fQojoa7NQnAtw=="}]}}}

Maassoft commented 3 years ago

Yes, that handshake string is exactly the same my app is using. But it might be that using RAW in Putty is not compatible with the tv. My app is using WebSockets to connect and communicate with the tv (https://docs.microsoft.com/en-us/windows/uwp/networking/websockets) and that protocol uses at least HTTP to set up the connection. Maybe it's an idea to use WireShark to exactly see what my app is sending to/receiving from the tv?

JPersson77 commented 3 years ago

Allright, thanks for the tip. Checked w/ wireshark and indeed there is more to the websockets. Will investigate more... 👍

Maassoft commented 3 years ago

I've created a new release (1.5.1.0) which hopefully fixes the 2 bugs you've encountered.

JPersson77 commented 3 years ago

Hi there,

I had the time to test and unfortunately it still does not work on cold boot and restart.

If I have the option enabled to apply a profile on startup then i get the following error:

CC error on starup2

then followed by this when I open the app:

CC error on starup3

If I disable the auto apply of a profile it still won't work, but I get no error message on the desktop, just the above when I open the application.

Did not encounter any problems with shutting down and powering up on resume/suspend

Thanks for looking into

Maassoft commented 3 years ago

Thanks for testing! I've created a new release, maybe this one will solve the problem.

JPersson77 commented 3 years ago

Thanks, unfortunately no go. I suspect you have multiple displays connected to your dev PC. Try disconnecting other screens than the LG TV when trying to debug potentially?

No error message now though

CC error on starup4

Maassoft commented 3 years ago

I focused on fixing the bugs which had to do with the Nvidia API. Seems they are fixed now, but I didn't realize that on startup the LG-controller code is only looking once if there's a LG tv found. Seems that in your case it can't find the tv if it's powered off/standby. Still weird though, because I only have one display attached to the PC, which is the LG tv, and I never have seen this problem. I will investigate further.

Maassoft commented 3 years ago

I've created a new release which tries to send a WOL-packet to the tv anyway, in case the lookup for devices returns nothing. You must have the option to wake the device after startup enabled for it to work. In case you still get the "Error while initializing the LG-controller"-message, could you please look at the Log-tab if there are any Error-messages logged? There was some logging, but it was redirected to the console, so not visible while not debugging. It should be logged to the Log-tab now.

JPersson77 commented 3 years ago

Hi again,

some quick testing with v1.5.3.0 now shows that the TV power on appropriately from restart and cold boot, no error messages, config window works. Thanks for looking into!

Maassoft commented 3 years ago

Thanks for testing and nice to know it's working as it should on your system! If no other related issues appear the following few days, we can close this issue.

Maassoft commented 3 years ago

Closing, no reports of it not working anymore.