mmende / homebridge-samsungtv-control2

homebridge-samsungtv-control2
MIT License
71 stars 17 forks source link

Pairing error #27

Open Maze2Go opened 4 years ago

Maze2Go commented 4 years ago

Hi, I tried to connect 2 of my Samsung TVs. One of them the pairing didn't worked completely, but the second one gave me a code to enter in the console. If I type in the code the code on the TV disappears and I get an error like this:

Ok... sending "1907" to your tv to see if it works...
(node:12517) UnhandledPromiseRejectionWarning: Error: Unable to handleEvent
    at /usr/local/lib/node_modules/homebridge-samsungtv-control/node_modules/samsung-remote-pin-paired/lib/Connection/SamsungTvConnection.js:130:13
    at /usr/local/lib/node_modules/homebridge-samsungtv-control/node_modules/samsung-remote-pin-paired/lib/Connection/Messages.js:30:31
    at new Promise (<anonymous>)
    at Messages.handle (/usr/local/lib/node_modules/homebridge-samsungtv-control/node_modules/samsung-remote-pin-paired/lib/Connection/Messages.js:29:12)
    at onMessageEmitter (/usr/local/lib/node_modules/homebridge-samsungtv-control/node_modules/samsung-remote-pin-paired/lib/Connection/SamsungTvConnection.js:45:12)
    at WebSocket.<anonymous> (/usr/local/lib/node_modules/homebridge-samsungtv-control/node_modules/samsung-remote-pin-paired/lib/Connection/SamsungTvConnection.js:157:9)
    at WebSocket.emit (events.js:315:20)
    at Receiver._receiver.onmessage (/usr/local/lib/node_modules/homebridge-samsungtv-control/node_modules/ws/lib/websocket.js:137:47)
    at Receiver.dataMessage (/usr/local/lib/node_modules/homebridge-samsungtv-control/node_modules/ws/lib/receiver.js:409:14)
    at Receiver.getData (/usr/local/lib/node_modules/homebridge-samsungtv-control/node_modules/ws/lib/receiver.js:347:12)
    at Receiver.startLoop (/usr/local/lib/node_modules/homebridge-samsungtv-control/node_modules/ws/lib/receiver.js:143:16)
    at Receiver.add (/usr/local/lib/node_modules/homebridge-samsungtv-control/node_modules/ws/lib/receiver.js:117:10)
    at Socket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:271:9)
    at Socket.Readable.push (_stream_readable.js:212:10)
(node:12517) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:12517) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code

Complete LOG:

Linux raspberrypi 5.4.51-v7+ #1333 SMP Mon Aug 10 16:45:19 BST 2020 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sat Sep  5 11:49:38 2020 from 192.168.178.48
pi@raspberrypi:~ $ npx homebridge-samsungtv-control pair2 192.168.178.28 CC:B1:1A:B6:CF:FE
Ok... sending the pairing request to your tv. Please click allow when asked
(node:12335) [DEP0123] DeprecationWarning: Setting the TLS ServerName to an IP address is not permitted by RFC 6066. This will be ignored in a future version.
That didn't work unfortunatelly. Here are some other possible solutions:
        1. Try another port npx homebridge-samsungtv-control pair2 192.168.178.28 CC:B1:1A:B6:CF:FE --port 8001
        2. Try another port npx homebridge-samsungtv-control pair2 192.168.178.28 CC:B1:1A:B6:CF:FE --port 55000
        3. Try the other pairing method npx homebridge-samsungtv-control pair1 192.168.178.28 CC:B1:1A:B6:CF:FE
        4. Try the legacy protocol npx homebridge-samsungtv-control legacy 192.168.178.28 CC:B1:1A:B6:CF:FE
pi@raspberrypi:~ $ npx homebridge-samsungtv-control pair2 192.168.178.28 CC:B1:1A:B6:CF:FE --port 8001
Ok... sending the pairing request to your tv. Please click allow when asked
That didn't work unfortunatelly. Here are some other possible solutions:
        1. Try another port npx homebridge-samsungtv-control pair2 192.168.178.28 CC:B1:1A:B6:CF:FE --port 8002
        2. Try another port npx homebridge-samsungtv-control pair2 192.168.178.28 CC:B1:1A:B6:CF:FE --port 55000
        3. Try the other pairing method npx homebridge-samsungtv-control pair1 192.168.178.28 CC:B1:1A:B6:CF:FE
        4. Try the legacy protocol npx homebridge-samsungtv-control legacy 192.168.178.28 CC:B1:1A:B6:CF:FE
pi@raspberrypi:~ $ npx homebridge-samsungtv-control pair2 192.168.178.28 CC:B1:1A:B6:CF:FE --port 8002
Ok... sending the pairing request to your tv. Please click allow when asked
(node:12382) [DEP0123] DeprecationWarning: Setting the TLS ServerName to an IP address is not permitted by RFC 6066. This will be ignored in a future version.
That didn't work unfortunatelly. Here are some other possible solutions:
        1. Try another port npx homebridge-samsungtv-control pair2 192.168.178.28 CC:B1:1A:B6:CF:FE --port 8001
        2. Try another port npx homebridge-samsungtv-control pair2 192.168.178.28 CC:B1:1A:B6:CF:FE --port 55000
        3. Try the other pairing method npx homebridge-samsungtv-control pair1 192.168.178.28 CC:B1:1A:B6:CF:FE
        4. Try the legacy protocol npx homebridge-samsungtv-control legacy 192.168.178.28 CC:B1:1A:B6:CF:FE
pi@raspberrypi:~ $ npx homebridge-samsungtv-control pair2 192.168.178.28 CC:B1:1A:B6:CF:FE --port 55000
Port 55000 is usually the port for the legacy protocol without pairing and most likely won't work with pair2. Trying anyway.
Ok... sending the pairing request to your tv. Please click allow when asked
Device is off or unreachable
/usr/local/lib/node_modules/homebridge-samsungtv-control/node_modules/samsung-tv-control/lib/samsung.js:66
                throw new Error('Error send Key');
                ^

Error: Error send Key
    at /usr/local/lib/node_modules/homebridge-samsungtv-control/node_modules/samsung-tv-control/lib/samsung.js:66:23
    at Socket.<anonymous> (/usr/local/lib/node_modules/homebridge-samsungtv-control/node_modules/samsung-tv-control/lib/samsung.js:369:17)
    at Socket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
pi@raspberrypi:~ $ npx homebridge-samsungtv-control legacy 192.168.178.28 CC:B1:1A:B6:CF:FE
Sending the mute key to see if your device is controlable with the legacy protocol over port 55000.
Device is off or unreachable
That didn't work unfortunatelly. Here are some other possible solutions:
        1. Try pairing method 1 npx homebridge-samsungtv-control pair1 192.168.178.28 CC:B1:1A:B6:CF:FE
        2. Try pairing method 2 npx homebridge-samsungtv-control pair2 192.168.178.28 CC:B1:1A:B6:CF:FE
pi@raspberrypi:~ $ npx homebridge-samsungtv-control pair1 192.168.178.28 CC:B1:1A:B6:CF:FE
Please enter the pin you see on your tv
1907
Ok... sending "1907" to your tv to see if it works...
(node:12517) UnhandledPromiseRejectionWarning: Error: Unable to handleEvent
    at /usr/local/lib/node_modules/homebridge-samsungtv-control/node_modules/samsung-remote-pin-paired/lib/Connection/SamsungTvConnection.js:130:13
    at /usr/local/lib/node_modules/homebridge-samsungtv-control/node_modules/samsung-remote-pin-paired/lib/Connection/Messages.js:30:31
    at new Promise (<anonymous>)
    at Messages.handle (/usr/local/lib/node_modules/homebridge-samsungtv-control/node_modules/samsung-remote-pin-paired/lib/Connection/Messages.js:29:12)
    at onMessageEmitter (/usr/local/lib/node_modules/homebridge-samsungtv-control/node_modules/samsung-remote-pin-paired/lib/Connection/SamsungTvConnection.js:45:12)
    at WebSocket.<anonymous> (/usr/local/lib/node_modules/homebridge-samsungtv-control/node_modules/samsung-remote-pin-paired/lib/Connection/SamsungTvConnection.js:157:9)
    at WebSocket.emit (events.js:315:20)
    at Receiver._receiver.onmessage (/usr/local/lib/node_modules/homebridge-samsungtv-control/node_modules/ws/lib/websocket.js:137:47)
    at Receiver.dataMessage (/usr/local/lib/node_modules/homebridge-samsungtv-control/node_modules/ws/lib/receiver.js:409:14)
    at Receiver.getData (/usr/local/lib/node_modules/homebridge-samsungtv-control/node_modules/ws/lib/receiver.js:347:12)
    at Receiver.startLoop (/usr/local/lib/node_modules/homebridge-samsungtv-control/node_modules/ws/lib/receiver.js:143:16)
    at Receiver.add (/usr/local/lib/node_modules/homebridge-samsungtv-control/node_modules/ws/lib/receiver.js:117:10)
    at Socket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:271:9)
    at Socket.Readable.push (_stream_readable.js:212:10)
(node:12517) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:12517) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code
tituswoo commented 3 years ago

Aw, I am getting this exact same error as well on my Samsung KS8000 series TV 😅

AlexGustafsson commented 3 years ago

I'm also having some issues pairing due to Error: Unable to handleEvent.

I've researched this a bit. This occurs when a message encrypted with AES 128 ECB fails to decrypt. This package uses a dependency for actually performing the pairing, samsung-remote-pin-paired which in turn is a copy of samsung-remote-models-2014-and-newer (see https://github.com/tdudek/samsung-remote-models-2014-and-newer/issues/38) which in turn is a copy of the code available here: https://github.com/Ape/samsungctl/issues/22#issuecomment-359063253. Both projects looks rather stale and the code itself uses some non-standard code to actually perform the decryption.

Since bytes and cryptos are quire hard to debug, my best guess at the moment is that Samsung changed their encryption scheme entirely (quite unlikely), changed their padding scheme (possible) or there's simply an edge case we're finding.

If @mmende would be interested in using it, I'm all for providing a new package written in TypeScript which could increase the stability of the pairing process and hopefully solve some edge cases like this. The goal would be to be a more or less drop-in replacement for the pairing dependency. I might have misunderstood the relationship or use case for the samsung-remote-pin-paired. If that's the case, please let me know.

I've got a TV in the KS7000 series which I will be able to test this on, but I would need help testing it on other devices.