Skip to content

Instantly share code, notes, and snippets.

@Stanback
Forked from danielfaust/samsung_remote.py
Last active September 29, 2022 05:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Stanback/13697957b44a23ceb79aeaaa2685e7d0 to your computer and use it in GitHub Desktop.
Save Stanback/13697957b44a23ceb79aeaaa2685e7d0 to your computer and use it in GitHub Desktop.
Samsung TV Remote Control Node.js Script
const net = require('net');
//
// A Node.js port of this original Gist: https://gist.github.com/danielfaust/998441
// To find hosts on the network: nmap -Pn -p55000 192.168.12.1/24
//
// Note: This is for Samsung TVs circa 2012-2015 that use a service running on port 55000
// Samsung TV's circa 2016 and later use a WebSocket service on port 8001 which is different
//
const src = '192.168.12.1'; // IP of our virtual remote control (doesn't seem to be really used)
const mac = '36-58-d1-4e-65-47'; // MAC of our remote (used for the access control confirmation)
const remote = 'node remote'; // Name of our remote (shown for access control confirmation and in General -> Wireless Remote Control)
const dst = '192.168.12.237'; // IP of TV
const app = 'node'; // Name of app (iPhone app reports: iphone..iapp.samsung)
const tv = 'UN60F8000'; // TV model (iPhone app reports: iphone.LE32C650.iapp.samsung)
const chr = (i) => String.fromCharCode(i);
const b64 = (s) => Buffer.from(s).toString('base64');
const send = (pkt) => {
const socket = new net.Socket();
socket.connect(55000, dst, () => { socket.end(pkt); });
};
// Authorize new remote (call this and authorize the remote on your TV before calling push)
const auth = () => {
const msg = chr(0x64) + chr(0x00)
+ chr(b64(src).length) + chr(0x00) + b64(src)
+ chr(b64(mac).length) + chr(0x00) + b64(mac)
+ chr(b64(remote).length) + chr(0x00) + b64(remote);
const pkt = chr(0x00)
+ chr(app.length) + chr(0x00) + app
+ chr(msg.length) + chr(0x00) + msg;
send(pkt);
};
// Send a button press
const push = (key) => {
const msg = chr(0x00) + chr(0x00) + chr(0x00)
+ chr(b64(key).length) + chr(0x00) + b64(key);
const pkt = chr(0x00)
+ chr(tv.length) + chr(0x00) + tv
+ chr(msg.length) + chr(0x00) + msg;
send(pkt);
};
auth();
// push('KEY_MENU');
@Stanback
Copy link
Author

Stanback commented Aug 15, 2019

Key names are similar to those supported by LIRC. I published a very simple MQTT to Samsung TV bridge here: https://github.com/Stanback/samsung2mqtt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment