Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remote control samsung TV
#! /usr/bin/python
# Title: samsungremote.py
# Author: Asif Iqbal
# Adapted By: Julien LEICHER
# Date: 05APR2012
# Info: To send remote control commands to the Samsung tv over LAN
# TODO:
import sys
import socket
import base64
import time, datetime
#IP Address of TV
tvip = "192.168.0.17"
#IP Address of TV
myip = ""
#Used for the access control/validation, but not after that AFAIK
mymac = ""
#What the iPhone app reports
appstring = "iphone..iapp.samsung"
#Might need changing to match your TV type
tvappstring = "iphone.UE40ES5500.iapp.samsung"
#What gets reported when it asks for permission
remotename = "Python Samsung Remote"
# Function to send keys
def sendKey(skey, dataSock, appstring):
messagepart3 = chr(0x00) + chr(0x00) + chr(0x00) + chr(len(
base64.b64encode(skey))) + chr(0x00) + base64.b64encode(skey);
part3 = chr(0x00) + chr(len(appstring)) + chr(0x00) \
+ appstring + chr(len(messagepart3)) + chr(0x00) + messagepart3
dataSock.send(part3);
# Open Socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((tvip, 55000))
# First configure the connection
ipencoded = base64.b64encode(myip)
macencoded = base64.b64encode(mymac)
messagepart1 = chr(0x64) + chr(0x00) + chr(len(ipencoded)) \
+ chr(0x00) + ipencoded + chr(len(macencoded)) + chr(0x00) \
+ macencoded + chr(len(base64.b64encode(remotename))) + chr(0x00) \
+ base64.b64encode(remotename)
part1 = chr(0x00) + chr(len(appstring)) + chr(0x00) + appstring \
+ chr(len(messagepart1)) + chr(0x00) + messagepart1
sock.send(part1)
messagepart2 = chr(0xc8) + chr(0x00)
part2 = chr(0x00) + chr(len(appstring)) + chr(0x00) + appstring \
+ chr(len(messagepart2)) + chr(0x00) + messagepart2
sock.send(part2)
# Now send the keys as you like, e.g.,
#sendKey("KEY_VOLUP",sock,tvappstring)
#time.sleep(1)
#sendKey("KEY_TOOLS",sock,tvappstring)
#time.sleep(1)
#sendKey("KEY_RIGHT",sock,tvappstring)
#time.sleep(1)
#sendKey("KEY_DOWN",sock,tvappstring)
#time.sleep(1)
#sendKey("KEY_RIGHT",sock,tvappstring)
#sendKey("KEY_TV",sock,tvappstring)
if len(sys.argv) > 1:
sendKey(sys.argv[1], sock, tvappstring)
else:
print """KEY_0,
KEY_1,
KEY_2,
KEY_3,
KEY_4,
KEY_5,
KEY_6,
KEY_7,
KEY_8,
KEY_9,
KEY_11,
KEY_12,
KEY_3SPEED,
KEY_4_3,
KEY_16_9,
KEY_AD,
KEY_ADDDEL,
KEY_ALT_MHP,
KEY_ANGLE,
KEY_ANTENA,
KEY_ANYNET,
KEY_ANYVIEW,
KEY_APP_LIST,
KEY_ASPECT,
KEY_AUTO_ARC_ANTENNA_AIR,
KEY_AUTO_ARC_ANTENNA_CABLE,
KEY_AUTO_ARC_ANTENNA_SATELLITE,
KEY_AUTO_ARC_ANYNET_AUTO_START,
KEY_AUTO_ARC_ANYNET_MODE_OK,
KEY_AUTO_ARC_AUTOCOLOR_FAIL,
KEY_AUTO_ARC_AUTOCOLOR_SUCCESS,
KEY_AUTO_ARC_CAPTION_ENG,
KEY_AUTO_ARC_CAPTION_KOR,
KEY_AUTO_ARC_CAPTION_OFF,
KEY_AUTO_ARC_CAPTION_ON,
KEY_AUTO_ARC_C_FORCE_AGING,
KEY_AUTO_ARC_JACK_IDENT,
KEY_AUTO_ARC_LNA_OFF,
KEY_AUTO_ARC_LNA_ON,
KEY_AUTO_ARC_PIP_CH_CHANGE,
KEY_AUTO_ARC_PIP_DOUBLE,
KEY_AUTO_ARC_PIP_LARGE,
KEY_AUTO_ARC_PIP_LEFT_BOTTOM,
KEY_AUTO_ARC_PIP_LEFT_TOP,
KEY_AUTO_ARC_PIP_RIGHT_BOTTOM,
KEY_AUTO_ARC_PIP_RIGHT_TOP,
KEY_AUTO_ARC_PIP_SMALL,
KEY_AUTO_ARC_PIP_SOURCE_CHANGE,
KEY_AUTO_ARC_PIP_WIDE,
KEY_AUTO_ARC_RESET,
KEY_AUTO_ARC_USBJACK_INSPECT,
KEY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AME,
KEY_GREEN,
KEY_GUIDE,
KEY_HDMI,
KEY_HDMI1,
KEY_HDMI2,
KEY_HDMI3,
KEY_HDMI4,
KEY_HELP,
KEY_HOME,
KEY_ID_INPUT,
KEY_ID_SETUP,
KEY_INFO,
KEY_INSTANT_REPLAY,
KEY_LEFT,
KEY_LINK,
KEY_LIVE,
KEY_MAGIC_BRIGHT,
KEY_MAGIC_CHANNEL,
KEY_MDC,
KEY_MENU,
KEY_MIC,
KEY_MORE,
KEY_MOVIE1,
KEY_MS,
KEY_MTS, //Dual
KEY_MUTE,
KEY_NINE_SEPERATE,
KEY_OPEN,
KEY_PANNEL_CHDOWN,
KEY_PANNEL_CHUP,
KEY_PANNEL_ENTER,
KEY_PANNEL_MENU,
KEY_PANNEL_POWER,
KEY_PANNEL_SOURCE,
KEY_PANNEL_VOLDOW,
KEY_PANNEL_VOLUP,
KEY_PANORAMA,
KEY_PAUSE,
KEY_PCMODE,
KEY_PERPECT_FOCUS,
KEY_PICTURE_SIZE,
KEY_PIP_CHDOWN,
KEY_PIP_CHUP,
KEY_PIP_ONOFF,
KEY_PIP_SCAN,
KEY_PIP_SIZE,
KEY_PIP_SWAP,
KEY_PLAY,
KEY_PLUS100,
KEY_PMODE,
KEY_POWER,
KEY_POWEROFF,
KEY_POWERON,
KEY_PRECH,
KEY_PRINT,
KEY_PROGRAM,
KEY_QUICK_REPLAY,
KEY_REC,
KEY_RED,
KEY_REPEAT,
KEY_RESERVED1,
KEY_RETURN,
KEY_REWIND,
KEY_REWIND_,
KEY_RIGHT,
KEY_RSS, // Internet
KEY_INTERNET(KEY_RSS), // Proxy for KEY_RSS
KEY_RSURF,
KEY_SCALE,
KEY_SEFFECT,
KEY_SETUP_CLOCK_TIMER,
KEY_SLEEP,
KEY_SOUND_MODE,
KEY_SOURCE,
KEY_SRS,
KEY_STANDARD,
KEY_STB_MODE,
KEY_STILL_PICTURE,
KEY_STOP,
KEY_SUB_TITLE,
KEY_SVIDEO1,
KEY_SVIDEO2,
KEY_SVIDEO3,
KEY_TOOLS,
KEY_TOPMENU,
KEY_TTX_MIX,
KEY_TTX_SUBFACE,
KEY_TURBO,
KEY_TV,
KEY_TV_MODE,
KEY_UP,
KEY_VCHIP,
KEY_VCR_MODE,
KEY_VOLDOWN,
KEY_VOLUP,
KEY_WHEEL_LEFT,
KEY_WHEEL_RIGHT,
KEY_W_LINK, // Media P
KEY_YELLOW,
KEY_ZOOM1,
KEY_ZOOM2,
KEY_ZOOM_IN,
KEY_ZOOM_MOVE,
KEY_ZOOM_OUT;"""
# Close the socket when done
sock.close()
@nandishyb

This comment has been minimized.

Copy link

@nandishyb nandishyb commented Sep 7, 2021

How to we send the mouse pointer coordinates , I see in on of the app below:
Can you help me decode and help me send the mouse position:

0000  00 14 00 69 70 68 6f 6e  65 2e 2e 69 61 70 70 2e       ...iphon e..iapp.
0010  73 61 6d 73 75 6e 67 0e  00 07 00 0d 00 00 00 e5   samsung. ........
0020  ff ff ff 1d 01 00 00                               .......
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment