hobbyquaker / node-red-contrib-lgtv

Node-RED Nodes to control LG webOS Smart TVs :tv:
http://flows.nodered.org/node/node-red-contrib-lgtv
MIT License
59 stars 21 forks source link

LGTV refuses to connect with ws after webOS Update #56

Open sam-mancarella opened 1 year ago

sam-mancarella commented 1 year ago

Recent update of webOS no longer accepts connection attempts via ws://:3000 and instead expects SSL to be used wss://:3001

This issue has impacted other similar lgtv automation projects, take a look at: https://github.com/merdok/homebridge-webos-tv/commit/9912258f242f2da31683232ae64b149c2d919057

It'd be great to support wss connections on the lgtv-config node.

jb-nobody commented 1 year ago

Thanks for pointing out why the lgtv-config node won't connect anymore. The homebridge plugin you mentioned was fixed, so I was able to get lgtv working again. I don't really know how GitHub, forking, npm and node.js in general works, so I'll just post what changes I made to the files on my system (RasPi 4) to get it working.

There are 2 lines to change for node-red-contrib-lgtv and 4 lines for lgtv2 (dependency of node-red-contrib-lgtv, which also does not seems to ne maintained anymore).

/home/pi/.node-red/node_modules/node-red-contrib-lgtv/nodes/lgtv-config.js [15] url: 'wss://' + node.host + ':3001', [157] url: 'wss://' + req.query.host + ':3001',

/home/pi/.node-red/node_modules/lgtv2/index.js [12] var WebSocketClient = require('websocket'); [46] config.wsconfig = config.wsconfig || {keepalive: true, keepaliveInterval: 10000, dropConnectionOnKeepaliveTimeout: true, keepaliveGracePeriod: 5000, tlsOptions: { rejectUnauthorized: false } }; [62] var client = new WebSocketClient.client(config.wsconfig); [257] var special = new WebSocketClient.client({ tlsOptions: { rejectUnauthorized: false } });

Restart Node-Red after making the changes.

I hope this helps. If someone includes this fix in a fork, please mention it here!

HonestJohn61 commented 1 year ago

Thanks @jb-nobody - that worked just fine to get Node-RED to connect to my G2. However, I've found the whole package unreliable, primarily because even with this fix in place, the nodes lose connection with the tv overnight, and the only way I can get these nodes working again is to restart Node-RED.

So instead I've added the tv to my Harmony remote and am using the node-red-contrib-harmony-websocket nodes for control. But thanks again for posting your fix to cope with the recent LG webOS change.

demosspro commented 1 year ago

not working for me (

GnomiBerlin commented 11 months ago

Thank you @jb-nobody. After the last weeks LG webOS update now the old interface didn't work for me anymore. I did your changes and it works again and also the overnight reconnect error from @HonestJohn61 did not occure so far. one remark: one line number of your changes hint is wrong:

[257] var special = new WebSocketClient.client({ tlsOptions: { rejectUnauthorized: false } });
-->
[261] var special = new WebSocketClient.client({ tlsOptions: { rejectUnauthorized: false } });

this change to "secure" communication was not downward compatible by LG. I do not understand, why thus basic programming rules are so often ignored by the companies.