
Thanks for your reply.
Moderators: leecollings, remb0
I don't see this option on my tv.. it isn'r present.* Check the "settings" of the tv about the "wireless remote control", if it accepts request... (i think 4 is the limit, if you already used that up...)
How can I check this information?* Your model is too new and the changed the api.
No I'm using the code found in this topic:* Do you use the code on the wiki? ( https://www.domoticz.com/wiki/Samsung_TV )? or the above code... script?
Code: Select all
#! /usr/bin/python
# Title: samsungremote.py
# Author: Asif Iqbal
# Date: 05APR2012
# Info: To send remote control commands to the Samsung tv over LAN
# TODO:
import socket
import base64
import time, datetime
#
# Variables
#
#IP Address of TV
tvip = "192.168.178.16"
#IP Address of TV
myip = "192.168.178.14"
#Used for the access control/validation, but not after that AFAIK
mymac = "b8-27-eb-f1-5a-f3"
#Might need changing to match your TV type
tvappstring = "iphone.UE46ES8000.iapp.samsung"
#What gets reported when it asks for permission
remotename = "Domoticz Samsung Remote"
#What the iPhone app reports (don't change this)
appstring = "iphone..iapp.samsung"
# 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_TVPOWEROFF",sock,tvappstring)
# Close the socket when done
sock.close()
Code: Select all
STVCLI $1 -SMS "" "" "" "" "" "" $2
SLEEP 0.3
STVCLI $1 -KEY KEY_ENTER
SLEEP 3
STVCLI $1 -KEY KEY_ENTER
Code: Select all
/*
* SamsungTV Remote C++ Command Line Interface v0.02 April 2013 TRiXWooD (cris.wood.org -AD- gmail.com)
*
* Network Error Handling (Mostly Missing)
* Key &| Text Input Checking, some chars will result in disabling the tv's remote part
*
* April 2013
* v0.00 Prototype
* v0.01 Remote Working
* v0.02 SOAP Message Working
*
*
* modified base64 (Base64EncodeDecode.c) from Sam Ernest Kumar
* part code/research from various places/people on the samygo forum
*/
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <netdb.h>
int samsungtv_base64encodeblock(char *input, char *output, int oplen){
int rc = 0, iplen = 0;
char encodedstr[5] = "";
char encodingtabe[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
iplen = strlen(input);
encodedstr[0] = encodingtabe[ input[0] >> 2 ];
encodedstr[1] = encodingtabe[ ((input[0] & 0x03) << 4) | ((input[1] & 0xf0) >> 4) ];
encodedstr[2] = (iplen > 1 ? encodingtabe[ ((input[1] & 0x0f) << 2) | ((input[2] & 0xc0) >> 6) ] : '=');
encodedstr[3] = (iplen > 2 ? encodingtabe[ input[2] & 0x3f ] : '=');
strncat(output, encodedstr, oplen-strlen(output));
return rc;
}
int samsungtv_base64encode(char *input, char *output, int oplen){
int rc = 0;
int index = 0, ipindex = 0, iplen = 0;
char encoderinput[4] = "";
iplen = strlen(input);
while(ipindex < iplen){
for(index = 0; index < 3; index++){
if(ipindex < iplen){
encoderinput[index] = input[ipindex];
}else{
encoderinput[index] = 0;
}
ipindex++;
}
rc = samsungtv_base64encodeblock(encoderinput, output, oplen);
}
return rc;
}
int samsungtv_response(int net_socket) {
unsigned char message[256];
memset (message,0x00,256);
int i = 3;
recv(net_socket,message,3,0);
recv(net_socket,message+i,message[1],0);
i += message[1];
recv(net_socket,message+i,2,0);
i += 2;
unsigned char response = message[i-2];
recv(net_socket,message+i,response,0);
i += response;
if (message[i-4] == 0x00 && message[i-3] == 0x00 && message[i-2] == 0x00 && message[i-1] == 0x00)
if (message[0] == 0x01) return 4; // success repeat keystroke...
else return 0; // success
if (message[i-response] == 0x65) return 3; // timeoutt....
if (message[i-4] == 0x64 && message[i-2] == 0x00) return 1; // access denied...
if (message[i-4] == 0x64 && message[i-2] == 0x01) return 0; // success
if (message[i-response] == 0x0A) return 2; // waiting for user...
return -1; // bug!
}
int samsungtv_setlength(unsigned char message[], unsigned int length) {
message[0] = (unsigned char) (length & 0xFF);
message[1] = (unsigned char) ((length >> 8) & 0xFF);
}
int samsungtv_setstring(unsigned char message[],unsigned char string[],int base64) {
unsigned char s[512];
memset (s,0x00,512);
if (base64 == 1) samsungtv_base64encode(string,s,strlen(string)*2);
else strncpy(s,string,strlen(string));
samsungtv_setlength(message,strlen(s));
strncpy(message+2,s,strlen(s));
return strlen(s)+2;
}
enum modes {eKey, eText, eSMS, eCall, eSchedule, eAuth, eUnknown};
int samsungtv_message(unsigned char string[], int net_socket,int type) {
unsigned char remote[] = "SamsungTVRemote";
unsigned char message[1024];
memset (message,0x00,1024);
unsigned int s = samsungtv_setstring(message+1,"iphone.iapp.samsung",0) + 1;
unsigned int i = s + 4 + (type==eKey?1:0);
i += samsungtv_setstring(message+i,string,1);
if (type == eAuth) {
message[s+2] = 0x64;
i += samsungtv_setstring(message+i,remote,1);
i += samsungtv_setstring(message+i,remote,1);
}
if (type == eText) {
message[0] = 0x01;
message[s+2] = 0x01;
}
samsungtv_setlength(message+s,i-s-2);
send(net_socket,message, i, 0);
return (type==eText?0:samsungtv_response(net_socket));
}
int samsungtv_authenticate(unsigned char ip[], int net_socket) { return samsungtv_message(ip,net_socket,eAuth); }
int samsungtv_key(unsigned char key[], int net_socket) { return samsungtv_message(key,net_socket,eKey); }
int samsungtv_text(unsigned char text[], int net_socket) { return samsungtv_message(text,net_socket,eText); }
int samsungtv_sms(char ip[], int net_socket, char date[], char time[], char from[], char fromnumber[], char to[],
char tonumber[], char message[]) {
char request[3072];
sprintf( request,"<Category>SMS</Category>"
"<DisplayType>Maximum</DisplayType>"
"<ReceiveTime>"
"<Date>%s</Date>"
"<Time>%s</Time>"
"</ReceiveTime>"
"<Receiver>"
"<Number>%s</Number>"
"<Name>%s</Name>"
"</Receiver>"
"<Sender>"
"<Number>%s</Number>"
"<Name>%s</Name>"
"</Sender>"
"<Body>%s</Body>",date,time,tonumber,to,fromnumber,from,message);
return samsungtv_soap(ip,net_socket,request);
}
int samsungtv_schedule(char ip[], int net_socket, char subject[], char startdate[], char starttime[], char enddate[], char endtime[], char location[], char owner[], char number[], char message[]) {
char request[3072];
sprintf( request,"<Category>Schedule Reminder</Category>"
"<DisplayType>Maximum</DisplayType>"
"<StartTime>"
"<Date>%s</Date>"
"<Time>%s</Time>"
"</StartTime>"
"<Owner>"
"<Number>%s</Number>"
"<Name>%s</Name>"
"</Owner>"
"<Subject>%s</Subject>"
"<EndTime>"
"<Date>%s</Date>"
"<Time>%s</Time>"
"</EndTime>"
"<Location>%s</Location>"
"<Body>%s</Body>",startdate,starttime,number,owner,subject,enddate,endtime,location,message);
return samsungtv_soap(ip,net_socket,request);
}
int samsungtv_call(char ip[], int net_socket, char date[], char time[], char from[], char fromnumber[], char to[] , char tonumber[]) {
char request[3072];
sprintf( request,"<Category>Incoming Call</Category>"
"<DisplayType>Maximum</DisplayType>"
"<CallTime>"
"<Date>%s</Date>"
"<Time>%s</Time>"
"</CallTime>"
"<Callee>"
"<Number>%s</Number>"
"<Name>%s</Name>"
"</Callee>"
"<Caller>"
"<Number>%s</Number>"
"<Name>%s</Name>"
"</Caller>",date,time,tonumber,to,fromnumber,from);
return samsungtv_soap(ip,net_socket,request);
}
int samsungtv_soap(unsigned char ip[], int net_socket,char requestbody[]) {
char request[3072];
char buffer[4096];
strcpy( request,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
"<s:Body>"
" <u:AddMessage xmlns:u=\"urn:samsung.com:service:MessageBoxService:1\">"
" <MessageType>text/xml</MessageType>"
" <MessageID>anything</MessageID>"
"<Message>");
strcat(request,requestbody);
strcat(request,
"</Message>"
" </u:AddMessage>"
" </s:Body>"
"</s:Envelope>" );
sprintf( buffer,
"POST /PMR/control/MessageBoxService HTTP/1.0\r\n"
"Content-Type: text/xml; charset=\"utf-8\"\r\n"
"HOST: %s\r\n"
"Content-Length: %d\r\n"
"SOAPACTION: \"uuid:samsung.com:service:MessageBoxService:1#AddMessage\"\r\n"
"Connection: close\r\n"
"\r\n", ip, strlen( request));
strcat( buffer, request );
int numbytes;
if((numbytes = send(net_socket, buffer, strlen( buffer ), 0)) == -1) { }
if((numbytes = recv(net_socket, buffer, 10000, 0)) == -1) { }
}
int main(int argc, char *argv[]) {
struct addrinfo hints, *res, *p;
int net_status, net_socket;
enum modes mode = eUnknown;
if (argc > 2) {
if (strcmp(argv[2],"-TEXT") == 0) mode = eText;
if (strcmp(argv[2],"-KEY") == 0) mode = eKey;
if (strcmp(argv[2],"-SMS") == 0) mode = eSMS;
if (strcmp(argv[2],"-CALL") == 0) mode = eCall;
if (strcmp(argv[2],"-SCHEDULE") == 0) mode = eSchedule;
}
if (argc < 4 || mode == eUnknown ||
!(mode == eText && argc == 4) &&
!(mode == eKey && argc == 4) &&
!(mode == eSMS && argc == 10) &&
!(mode == eCall && argc == 9) &&
!(mode == eSchedule && argc == 12)
) {
printf("SamsungTV Remote Control CLI v0.02 April 2013 TRiXWooD\n");
printf("usage: STVCLI IP -KEY KEY\n");
printf(" STVCLI IP -TEXT TEXT\n");
printf(" STVCLI IP -SMS DATE TIME FROM NUMBER TO NUMBER MESSAGE\n");
printf(" STVCLI IP -CALL DATE TIME FROM NUMBER TO NUMBER\n");
printf(" STVCLI IP -SCHEDULE SUBJECT STARTDATE STARTTIME ENDDATE ENDTIME LOCATION OWNER NUMBER MESSAGE\n\n");
printf("examples: STVCLI 192.168.1.11 -KEY KEY_VOLUP\n --Simulates Press Volume Up\n");
printf(" STVCLI 192.168.1.11 -TEXT \"Colour Haze\"\n --Sends Text To Youtube...\n");
printf(" STVCLI 192.168.1.11 -SMS 2013-6-24 \"7:01:01 PM\" Cris +555-4323 Me +555-2343 \"Get Off The Couch\"\n --Show Incomming SMS...\n");
printf(" STVCLI 192.168.1.11 -CALL 23:06:01 Cris +555-4323 \"\" \"\"\n --Show Incomming Call (skips input with empty strings)...\n\n\n");
printf("exmaple script for displaying popup message\n(hint forward ports 52235 & 55000 on your internet router so you can reach your tv from anywhere)\n\nusage popup.sh 10.0.0.2 \"Pop Says The Message on C6710\"\n\nSTVCLI $1 -SMS \"\" \"\" \"\" \"\" \"\" \"\" $2\nSLEEP 0.3\nSTVCLI $1 -KEY KEY_ENTER\nSLEEP 3\nSTVCLI $1 -KEY KEY_ENTER\n");
return 1;
}
char port[] = "55000";
if (mode != eKey && mode != eText) strcpy(port,"52235");
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC; // AF_INET or AF_INET6 to force version
hints.ai_socktype = SOCK_STREAM;
if ((net_status = getaddrinfo(argv[1],port, &hints, &res)) != 0) {
fprintf(stderr, "SamsungTV Remote Control: Connection Failure: (%s)\n", gai_strerror(net_status));
return 2;
}
net_socket = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if ((net_status = connect(net_socket, res->ai_addr, res->ai_addrlen)) != 0) {
fprintf(stderr, "SamsungTV Remote Control: Connected Failure (%s)\n", gai_strerror(net_status));
return 2;
}
if (mode == eKey || mode == eText) {
int response,auth_status = samsungtv_authenticate(argv[1],net_socket);
if (auth_status == 0) {
if (mode == eText) response = samsungtv_text(argv[3],net_socket);
else response = samsungtv_key(argv[3],net_socket);
if (response != 0 && response != 4) fprintf(stderr, "SamsungTV Remote Control: Bug!\n");
}
else
{ if (auth_status == -1) fprintf(stderr, "SamsungTV Remote Control: Bug!\n");
if (auth_status == 1) fprintf(stderr, "SamsungTV Remote Control: Access Denied\n");
if (auth_status == 2) fprintf(stderr, "SamsungTV Remote Control: Waiting On User\n");
if (auth_status == 3) fprintf(stderr, "SamsungTV Remote Control: Time Out\n");
}
}
else {
if (mode == eSMS) samsungtv_sms(argv[1],net_socket,argv[3],argv[4],argv[5],argv[6],argv[7],argv[8],argv[9]);
if (mode == eCall) samsungtv_call(argv[1],net_socket,argv[3],argv[4],argv[5],argv[6],argv[7],argv[8]);
if (mode == eSchedule) samsungtv_schedule(argv[1],net_socket,argv[3],argv[4],argv[5],argv[6],argv[7],argv[8],argv[9],argv[10],argv[11]);
}
close(net_socket);
freeaddrinfo(res);
return 0;
}
Code: Select all
gcc stvcli.c
Code: Select all
STVCLI 192.168.1.11 -KEY KEY_VOLUP
Code: Select all
-bash STVCLI command not found domoticz
Code: Select all
mv stvcli STVCLI
@ Trixwood, I followed the Github instructions for the Raspberry Pi and my Samsung F serie tv does work when I send the command via putty as shown in the examples. Awesometrixwood wrote:I have updated the command line code and it should work on a Samsung Series C, D, E and F. For those who want to script in the Samsung TV remote functions or even a notification popup,...
https://github.com/Tristan79/iSamsungTV
Working on getting the volume from upnpsoap, things
Code: Select all
nmap -p 1-65535 192.168.1.106
Code: Select all
apt-get install nmap
Code: Select all
pi@smarthome:~/iSamsungTV $ nmap -p 1-65535 10.0.0.92
Starting Nmap 6.47 ( http://nmap.org ) at 2016-11-17 22:14 UTC
Nmap scan report for 10.0.0.92
Host is up (0.00087s latency).
Not shown: 65531 closed ports
PORT STATE SERVICE
5601/tcp open unknown
52235/tcp open unknown
52396/tcp open unknown
55000/tcp open unknown
Nmap done: 1 IP address (1 host up) scanned in 7.11 seconds
and when its off
[code]
pi@smarthome:~/iSamsungTV $ nmap -p 1-65535 10.0.0.92
Starting Nmap 6.47 ( http://nmap.org ) at 2016-11-17 22:14 UTC
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 3.36 seconds
pi@smarthome:~/iSamsungTV $
Code: Select all
sudo ln -s /usr/local/bin/iSamsungTV ~/domoticz/scripts/
Code: Select all
script://iSamsungTV 10.0.0.92 -KEY KEY_VOLUP
Indeed that works! Manny thanks. I will have a look at the other post as well.trixwood wrote:I have no idea why and I am tired... so workaround:
run this (with the correct location of your domoticz) and make sure iSamsungTV is in the /usr/local/bin
it creates a link to iSamsungTV in the domoticz script folder..Code: Select all
sudo ln -s /usr/local/bin/iSamsungTV ~/domoticz/scripts/
leave out /usr/local/bin in the script:// thingy-me-dingy...
That works...Code: Select all
script://iSamsungTV 10.0.0.92 -KEY KEY_VOLUP
Code: Select all
pi@raspberrypi:~$ nmap -p 1-65535 192.168.1.106
Starting Nmap 6.47 ( http://nmap.org ) at 2016-11-18 07:53 CET
Nmap scan report for 192.168.1.106
Host is up (0.018s latency).
Not shown: 65527 closed ports
PORT STATE SERVICE
80/tcp open http
443/tcp open https
4443/tcp open pharos
6000/tcp filtered X11
7676/tcp open imqbrokerd
9080/tcp open glrpc
55000/tcp open unknown
55001/tcp open unknown
Nmap done: 1 IP address (1 host up) scanned in 78.66 seconds
pi@raspberrypi:~$ nmap -p 1-65535 192.168.1.106
Starting Nmap 6.47 ( http://nmap.org ) at 2016-11-18 07:58 CET
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 5.28 seconds
Code: Select all
*** buffer overflow detected ***: iSamsungTV terminated
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7fbdeab477e5]
/lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x5c)[0x7fbdeabe856c]
/lib/x86_64-linux-gnu/libc.so.6(+0x116570)[0x7fbdeabe6570]
/lib/x86_64-linux-gnu/libc.so.6(+0x116a13)[0x7fbdeabe6a13]
iSamsungTV[0x40125b]
iSamsungTV[0x4012ef]
iSamsungTV[0x4022d6]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7fbdeaaf0830]
iSamsungTV[0x400a29]
======= Memory map: ========
00400000-00405000 r-xp 00000000 fc:00 926472 /usr/local/bin/iSamsungTV
00604000-00605000 r--p 00004000 fc:00 926472 /usr/local/bin/iSamsungTV
00605000-00606000 rw-p 00005000 fc:00 926472 /usr/local/bin/iSamsungTV
010b4000-010d5000 rw-p 00000000 00:00 0 [heap]
7fbdea8ba000-7fbdea8d0000 r-xp 00000000 fc:00 524823 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fbdea8d0000-7fbdeaacf000 ---p 00016000 fc:00 524823 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fbdeaacf000-7fbdeaad0000 rw-p 00015000 fc:00 524823 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fbdeaad0000-7fbdeac8f000 r-xp 00000000 fc:00 541085 /lib/x86_64-linux-gnu/libc-2.23.so
7fbdeac8f000-7fbdeae8f000 ---p 001bf000 fc:00 541085 /lib/x86_64-linux-gnu/libc-2.23.so
7fbdeae8f000-7fbdeae93000 r--p 001bf000 fc:00 541085 /lib/x86_64-linux-gnu/libc-2.23.so
7fbdeae93000-7fbdeae95000 rw-p 001c3000 fc:00 541085 /lib/x86_64-linux-gnu/libc-2.23.so
7fbdeae95000-7fbdeae99000 rw-p 00000000 00:00 0
7fbdeae99000-7fbdeaebf000 r-xp 00000000 fc:00 541081 /lib/x86_64-linux-gnu/ld-2.23.so
7fbdeb0b2000-7fbdeb0b5000 rw-p 00000000 00:00 0
7fbdeb0bb000-7fbdeb0be000 rw-p 00000000 00:00 0
7fbdeb0be000-7fbdeb0bf000 r--p 00025000 fc:00 541081 /lib/x86_64-linux-gnu/ld-2.23.so
7fbdeb0bf000-7fbdeb0c0000 rw-p 00026000 fc:00 541081 /lib/x86_64-linux-gnu/ld-2.23.so
7fbdeb0c0000-7fbdeb0c1000 rw-p 00000000 00:00 0
7ffec08b3000-7ffec08d4000 rw-p 00000000 00:00 0 [stack]
7ffec0905000-7ffec0907000 r--p 00000000 00:00 0 [vvar]
7ffec0907000-7ffec0909000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
Aborted (core dumped)
Code: Select all
#!/bin/bash
iSamsungTV $1 $2 -SMS "" "" "" "" "" "" $3
sleep 0.3
iSamsungTV $1 $2 -KEY KEY_ENTER
sleep 3
iSamsungTV $1 $2 -KEY KEY_ENTER
Users browsing this forum: No registered users and 0 guests