Giter Club home page Giter Club logo

lgtv-ip-control's Introduction

lgtv-ip-control's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar github-actions[bot] avatar jadoc avatar llamafilm avatar minhtritran avatar tangowithfoxtrot avatar wessouza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

lgtv-ip-control's Issues

Example never exits? Sorry not that familiar with JS?

Example never exits? Sorry not that familiar with JS? The following example works great, once I allow for 'require' versus using a module definition, but why it never exits?

`//import { LGTV } from 'lgtv-ip-control';

const delay = ms => new Promise(res => setTimeout(res, ms));
const { LGTV } = require('lgtv-ip-control');

const tv = new LGTV('192.168.1.87', '7C:64:6C:93:6F:06', 'ZH6WXH9P');

tv.connect()
.then(async () => {

const theVolume = await tv.getCurrentVolume()
console.log('Volume '+theVolume)

//console.log('Mute');
//await tv.setVolumeMute(true);

//delay(5000);

//console.log('Unmute');
//await tv.setVolumeMute(false);

})
.catch(console.error);
`

Something unique about JS that it can't exit the script when complete?

Implement convenience function to wait until the TV turns on

TVs might take time to respond after being turned on, causing timeouts if tried to be connected immediately.

A convenience function such as waitUntilReady() or powerOnAndConnect() must be added, or a change to connect() should be made to allow for retries with a delay.

screenOff not working on LG C2

First of all, thanks for writing this library, it's very helpful!

I think LG probably must have changed the API a bit, but the energy saving option screenOff is not working for me. On my LG C2 this option is not at all in the same dropdown as the other energy saving options, but rather it's a separate button just outside of the energy saving menu.

My question is, how did you figure out all those commands? If I could figure out the command, I could open a PR, if you want.

Matthias

Readme Suggestion

First off, let me say thank you for making this plugin. You saved me a lot of time because I was gonna have to dig into the docs to figure out how to control our new lg displays.

In trying to set up the initial connection to the tv, I was not having any success following your steps in the readme. After searching the internet for a while, I happened to look at previously submitted issues where someone asked for the document you referenced in the readme. That's when I was finally able to make some progress.

Your step #2 states "Using the remote arrows, navigate to "Connection". For some TVs, this may say "Network" instead." which to me meant that I had to go into the Connection/Network settings area. The reference document said to "Keep the Network icon focused" (don't enter into the network area). That was the key for me to be able to proceed. Not sure if it's the same for all models, but if it is, I would suggest updating the Readme to indicate "highlighting, but not entering the network menu".

Thanks again

reference for lg ip control?

your readme mentions "a guide you found on the internet." could you include that in the readme? i've checked lg's website and googled and can't find their ip protocol for recent models. thank you!

Improve TinySocket connection status handling

Calling disconnect on TinySocket wraps the end function call without making sure the Socket has already been disconnected or destroyed.

We should implement checks for these states:

  • Disallow connection on a socket that is connecting or already connected
  • Make disconnecting a disconnected socket a no-op
  • Disallow reading or writing to a socket that is not connected

Additional input for freesat

Thanks for your work on this, I'm using it daily.

My tv is the LG OLED CX type (a UK model with a freesat tuner). I'd like to directly select this input I.e.

setInput('satdtv')

I tried setInput('dtv') but this selects the "Programme Mode" as "Antenna".

Similarly, setInput('cadtv') select the "Programme Mode" as "Cable".

There seems to be no way to select "Programme Mode" as "Satellite".

I've tried adding the following items in constants/TV.d.ts... sdtv, sadtv, satdtv ... no joy.

ReferenceError: LGTV is not defined

lgtv-ip-controlled is installed globally but when trying to execute this simple code it errors out.

const _ = require('lgtv-ip-control')

const tv = new LGTV('192.168.0.13', 'xx:xx:xx:xx:xx:xx', 'xxxxxxx');

error

C:\Program Files\nodejs\node.exe .\index.js
Uncaught ReferenceError: LGTV is not defined
Process exited with code 1

Attached is the entire project.

monitor.zip

Response decryption

Hey, i just hacked a demo to control my TV and was able to decrypt responses. It's in C# but i hope the idea will be clear.

  1. first 16 bytes are IV which is encrypted the same way as in request (IV as data, ECB, key is obtained from hashing, IV is 16 zeroes). Decrypting is straightforward, but my .net crypto library required "padding" property to be set to "none".
  2. other received bytes are the message, encrypted with given IV and the same way as in request (CBC). Decrypting is similar too, set "padding" to "none", don't know why.
            // buf is TCP response bytes
            var iv = DecryptEcb(buf.Take(16).ToArray(), key);
            var response = Decrypt(buf.Skip(16).Take(16).ToArray(), iv, key);
            Console.WriteLine(Encoding.ASCII.GetString(response));

        public byte[] DecryptEcb(byte[] value, byte[] key)
        {
            using (var aes = Aes.Create())
            {
                aes.BlockSize = 8 * 16;
                aes.Key = key;
                aes.IV = new byte[16];
                aes.Mode = CipherMode.ECB;
                aes.Padding = PaddingMode.None;
                var decryptor = aes.CreateDecryptor();
                var result = decryptor.TransformFinalBlock(value, 0, value.Length);
                PrintHex("decrypt iv with ecb", result);
                return result;
            }
        }

        public byte[] Decrypt(byte[] value, byte[]iv, byte[] key)
        {
            using (var aes = Aes.Create())
            {
                aes.BlockSize = 128;
                aes.Key = key;
                aes.IV = iv;
                aes.Mode = CipherMode.CBC;
                aes.Padding = PaddingMode.None;
                var decryptor = aes.CreateDecryptor();
                var result = decryptor.TransformFinalBlock(value, 0, value.Length);
                PrintHex("decrypt cbc", result);
                return result;
            }
        }

Output from PrintHex():

buf:
    BA C4 BE 9C CE 68 D1 26 C4 0E D7 07 E1 FB 97 EC
    8C 1D 1D 8E D9 C9 D1 14 34 D0 07 D2 E9 BD 26 8B
decrypt iv with ecb
    EB 75 18 DB 91 27 72 9A 1F C6 13 D3 C4 44 9C 52
decrypt cbc
    4F 4B 0A 0D 0D 0D 0D 0D 0D 0D 0D 0D 0D 0D 0D 0D
OK

the last line is the TV response text! ๐ŸŽ‰

Calling your library/class object from Node Red, I ultimately get a timeout?

Calling your library/class object from Node Red, I ultimately get a timeout?

TimeoutError
at Socket.handleTimeout (/root/node_modules/lgtv-ip-control/dist/classes/TinySocket.cjs:38:16)
at Object.onceWrapper (node:events:631:28)
at Socket.emit (node:events:517:28)
at Socket._onTimeout (node:net:598:8)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7)

Since Node Red is based on Node (v18 in my case), this should be consistent to say calling Node directly. But your code never seems to reset or recover from the time out once it occurs?

Installation failure

The "npm install lgtv-ip-control" command fails:

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\Development (x86)\nodejs\node.exe',
1 verbose cli 'D:\Users\njc\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js',
1 verbose cli 'install',
1 verbose cli 'lgtv-ip-control'
1 verbose cli ]
2 info using [email protected]
3 info using [email protected]
4 verbose config Skipping project config: C:\Users\njc/.npmrc. (matches userconfig)
5 silly loadCurrentTree Starting
6 silly install loadCurrentTree
7 silly install readLocalPackageData
8 verbose stack TypeError: cb.apply is not a function
8 verbose stack at D:\Users\njc\AppData\Roaming\npm\node_modules\npm\node_modules\graceful-fs\polyfills.js:287:18
8 verbose stack at FSReqCallback.oncomplete (fs.js:193:5)
9 verbose cwd C:\Users\njc
10 verbose Windows_NT 10.0.19043
11 verbose argv "C:\Development (x86)\nodejs\node.exe" "D:\Users\njc\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js" "install" "lgtv-ip-control"
12 verbose node v14.17.0
13 verbose npm v4.5.0
14 error cb.apply is not a function
15 verbose exit [ 1, true ]

Connection refused for about 40 seconds after TV powers on

I don't think this is an issue with this project but I thought I'd reach out there before contacting LG. I first tried this library when I bought my LG CX in early May. I was able to use Wake On LAN to power the TV on and immediately switch to a certain input. This worked for a couple of weeks but after that, I started getting ECONNREFUSED (Connection refused) messages until about 40 seconds after the TV powers on. I've also tried connecting with netcat and found the same. I suspect a firmware update has broken it. Have you seen this? If not, could you please test it?

Power on max retries reached 10.

Power on doesn't work all the time the tv won't respond. I have to manually open the tv then it will start to respond to commands.

here is the command im using that gives the error when the tv is off.

lgtv-ip-control-cli-win.exe -o 192.168.1.200 -m macaddress -k MGTEKEY power on

Home key does not work but live tv does?

This works...

TV.connect()
.then(async () => {
await TV.sendKey('livetv')

            process.exit()
    })

.catch(console.error);

But this does not work...

TV.connect()
.then(async () => {
await TV.sendKey('home')

            process.exit()
    })

.catch(console.error);

AssertionError [ERR_ASSERTION]: key must be valid
at LGTV.sendKey (/root/node_modules/lgtv-ip-control/dist/classes/LGTV.cjs:77:5)
at /root/LGTV-Screen-Off.js:6:12 {
generatedMessage: false,
code: 'ERR_ASSERTION',
actual: false,
expected: true,
operator: '=='
}

The home key is defined in the keys enumeration, so not sure why it is not a valid key.

Handle getCurrentApp empty response when the TV is off

The TV might allow connections briefly after being turned off. The getCurrentApp command will error out because the response will be an empty string.

We should handle this case properly.

Example code:

const { LGTV } = require("lgtv-ip-control");

const tv = new LGTV("IP", "MAC", "CODE");

tv.powerOn();
tv.connect()
  .then(async () => {
    console.log(await tv.getCurrentApp());
    tv.disconnect();
  })
  .catch((e) => {
    console.error(e);
    tv.disconnect();
  });

Output:

โžœ node test.js
ResponseParseError: failed to parse response: 
    at LGTV.getCurrentApp (/Users/wes/Developer/lgtv-ip-control-test/node_modules/lgtv-ip-control/dist/classes/LGTV.cjs:35:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /Users/wes/Developer/lgtv-ip-control-test/test.js:25:17

Design issue or not? Select input, if sceen mute on, previous input presented?

Not sure if this an issue with LG IP Control module, or WebOS quirk? The following via lgtv-ip-control commands:

  1. Set TV to HDMI1
  2. Set screenmuteon
  3. Set TV to HDMI2
  4. HDMI1 is displayed... this does make sense?

IMHO. expected result is allmuteoff state, and TV displays HDMI2, however, TV displays HDMI1, as set in step 1. So although allmuteoff is the new screen mute state, the HDMI2 set input never seems to happen. Either the WebOS is not honoring HDMI2 or lgtv-ip-control is not?

The issue is masked, if you do the following...

  1. Set TV to HDMI1
  2. Set screenmuteon
  3. Set TV to HDMI1
  4. HDMI1 displayed

Never see the changed input being dishonored, because original input and new input is same.

The issue never happens if you do...

  1. Set TV to HDMI1
  2. Set screenmuteon
  3. Set allmuteoff
  4. HDMI1 displayed

The issue is also masked depending on the actual TV remote, some models of TV remotes have direct input for HDMI1, HDMI2, etc. In my case, not having direct input buttons, my remote seems to send allmuteoff when I hit the input button. And I have to hit input again to select a different input. So maybe the above behavior is WebOS design?

Package has type "module", but `main` refers to a CommonJS file

If package.json has the property type set to "module", then Node interprets files with the ".js" extension as ESM. Currently, the main property refers to "dist/index.js", which contains CommonJS, but is erroneously interpreted as ESM due to type being set to "module". If the goal is to create a hybrid package, then I believe conditional exports should be used and the type property shouldn't be set at all. This conditional export worked for me:

  "exports": {
    "import": "./dist/index.mjs",
    "require": "./dist/index.js"
  },

This appears to have been broken at or near 633e2f6.

initial constructor

What am I doing wrong here? I'm getting "LGTV is not a constructor". Here is my code

var LGTV = require('lgtv-ip-control'); const tv = new LGTV('192.168.X.XX', 'XXXXXXXXXX', 'XXXXXXX'); tv.connect() .then(async () => { console.log('powering on'); tv.powerOn() }) .catch(console.error);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.