Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Previous section Next section Previous page Next page Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Page 1 of 3
Topic:
Working on KODI feedback
This thread has 41 replies. Displaying posts 1 through 15.
Post 1 made on Saturday August 1, 2020 at 12:20
mpg7321
Regular Member
Joined:
Posts:
June 2020
109
So this is my first attempt working on feedback and not having luck yet. So was wondering if I have the logic down. So in the below script, when I send the command to retrieve whats playing, the returned data should be put into the variable "info" because of this line "info = socket.read(100, 3000);", Correct? If so then shouldn't the data then be displayed in a panel with the Pronto Script name: "KODI_INFO". So far I have had no luck.

var url = CF.widget("Kodi_aURL","Kodi_PARAMETERS_test").label;
var info;

function kodi(command) {
var socket = new TCPSocket();
socket.onConnect = function() {
prefix = 'GET /jsonrpc?request='
postfix = ' HTTP/1.0\r\n"'
try {
socket.write(prefix+command+postfix);
socket.write("HOST:+url+\r\n\r\n");
info = socket.read(100, 3000);
CF.widget("KODI_INFO").label=info;
} catch(e) {
socket.close()
}}
socket.onData = function() {
socket.close()
}
socket.onIOError = function(e) {
socket.close()
}
socket.connect(url, 9090, 300);
};
Post 2 made on Saturday August 1, 2020 at 15:03
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
Several points.

1. You are creating a new socket every time you call the kodi function. Not sure if that is your intent but you can only have 16 sockets open at one time.

2. The socket.onData function you have defined is immediately closing the socket when server sends a response. You won't get any data because you are closing the socket without first 'read'ing it.

3. You talk about using socket.read() with parameters. Parameters are only supported if you are using synchronous/blocking sockets (constructed using new TCPSocket(true)). The example that you have suggests you want asynchronous socket behavior because you are defining onData. I am a bit


In a previous thread where you requested socket help to send command such as MVUp, I provided an asynchronous example that contained a socket.onData function that did a this.read and appended the received data to a string buffer which is initialized as an empty string when the request was made. Can you review that example and then apply to the approach you are attempting.

[Link: remotecentral.com]

Specifically you will likely want to do System.print showing the blocks of data that are received to isolate your issue.

I suspect that the issue you are seeing is because you are not adding a 'Host' header in your HTTP request.

Last edited by Lyndel McGee on August 1, 2020 15:12.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 3 made on Saturday August 1, 2020 at 15:11
mpg7321
Regular Member
Joined:
Posts:
June 2020
109
I understand that yes I am opening a new socket right now. Just starting with a very basic sample before I move on. I removed the socket.onData function buut still not seeing data in the panel on the page.
Post 4 made on Saturday August 1, 2020 at 15:13
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
See my edited reply above. You are constructing an asynchronous socket but you want synchronous behavior.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 5 made on Saturday August 1, 2020 at 16:47
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
On August 1, 2020 at 15:11, mpg7321 said...
I understand that yes I am opening a new socket right now. Just starting with a very basic sample before I move on. I removed the socket.onData function buut still not seeing data in the panel on the page.

construct your socket with

new TCPSocket(true);

Don't worry about assigning onData, onConnect, onIOError functions as they are not used if you supply 'true' in the constructor.

Next, issue your call to connect()

followed by call to write()

followed by read()
Note that you may have to loop until you get 0 bytes returned.

followed by call to close()

Not sure this will work as you don't know how many bytes are actually there.

Also, note that as this is HTTP protocol, the data you are expecting to put in the label will not be pretty, meaning that you will have to parse out text you might want.

I've never used KODI so I won't be of much help with deciphering the responses.

Lyndel
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 6 made on Saturday August 1, 2020 at 16:54
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
assuming that the button you are pressing and the label is on the same page, instead of using CF.widget(), use GUI.widget() .
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 7 made on Saturday August 1, 2020 at 18:40
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
Try this... you cannot read the socket synchronously if doing async. You also need to be reading within onData. Look at the changes in bold below.
var url = CF.widget("Kodi_aURL","Kodi_PARAMETERS_test").label;
var info;

function kodi(command) {
var socket = new TCPSocket();
socket.onConnect = function() {
prefix = 'GET /jsonrpc?request='
postfix = ' HTTP/1.0\r\n"'
try {
socket.write(prefix+command+postfix);
socket.write("HOST:+url+\r\n\r\n");
} catch(e) {
socket.close()
}}
socket.onData = function() {
info = socket.read();
CF.widget("KODI_INFO").label=info;

socket.close()
}
socket.onIOError = function(e) {
socket.close()
}
socket.connect(url, 9090, 300);
};
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 8 made on Saturday August 1, 2020 at 23:01
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
I did some late night digging into KODI jsonrpc. It uses JsonRPC 2.0 and the query strings will need to be in the body of a POST request to really be useful.

I'm not sure if anyone has done any scripting here for JsonRPC 2.0.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 9 made on Sunday August 2, 2020 at 00:18
mpg7321
Regular Member
Joined:
Posts:
June 2020
109
so got this to work,

var url = CF.widget("Kodi_aURL","Kodi_PARAMETERS_test").label;
var info;
function kodi() {
var socket = new TCPSocket();
socket.onConnect = function() {
prefix = 'GET /jsonrpc?request={"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title"], "playerid": 1 }, "id": "1"}'
postfix = ' HTTP/1.0\r\n'
try {
socket.write(prefix+postfix);
socket.write("HOST:+url+\r\n\r\n");
} catch(e) {
socket.close()
}}
socket.onData = function() {
info = socket.read();
var title = info.split('title":"').pop().split('","type')[0];
CF.widget("KODI_INFO").label=title;
socket.close()
}
socket.onIOError = function(e) {
socket.close()
}
socket.connect(url, 9090, 3000);
};


but not this, and Im not sure why,


var url = CF.widget("Kodi_aURL","Kodi_PARAMETERS_test").label;
var info;
function kodi() {
var socket = new TCPSocket();
socket.onConnect = function() {
try {
socket.write("GET /jsonrpc?request={"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title"], "playerid": 1 }, "id": "1"} HTTP/1.0\r\n");
socket.write("HOST:+url+\r\n\r\n");
} catch(e) {
socket.close()
}}
socket.onData = function() {
info = socket.read();
var title = info.split('title":"').pop().split('","type')[0];
CF.widget("KODI_INFO").label=title;
socket.close()
}
socket.onIOError = function(e) {
socket.close()
}
socket.connect(url, 9090, 3000);
};
OP | Post 10 made on Sunday August 2, 2020 at 00:24
mpg7321
Regular Member
Joined:
Posts:
June 2020
109
Anotehr question I would have, is to get all the data I want from KODI I would have to send two commands,

{"jsonrpc": "2.0", "method": "Player.GetProperties", "params": { "properties": ["currentaudiostream", "percentage", "totaltime", "speed"], "playerid": 1 }, "id": "VideoGetItem"}


{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title", "thumbnail"], "playerid": 1 }, "id": "1"}

till this day I can not find a way to do this in one command. What would you recommend on how to send both from the same script.
OP | Post 11 made on Sunday August 2, 2020 at 00:35
mpg7321
Regular Member
Joined:
Posts:
June 2020
109
On August 1, 2020 at 23:01, Lyndel McGee said...
I did some late night digging into KODI jsonrpc. It uses JsonRPC 2.0 and the query strings will need to be in the body of a POST request to really be useful.

I'm not sure if anyone has done any scripting here for JsonRPC 2.0.

So far every thing is working. I have full IP control and as you read, I got some of the feedback started.
Post 12 made on Sunday August 2, 2020 at 12:30
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
Do google search for jsonrpc 2 batch. Not sure if KODI supports it yet but you send an array of requests and get back an array of responses.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 13 made on Sunday August 2, 2020 at 12:33
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
With regard to your 2nd try, it is possible that the data is arriving in multiple blocks and you are only reading the first one. You’d have to do some debugging of this to find out if this is the case.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 14 made on Sunday August 2, 2020 at 12:38
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
Note that with jsonrpc, requests need to have a unique ‘id’. You are using a value of 1 for both requests. If sending both concurrently, that could also be the cause.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 15 made on Sunday August 2, 2020 at 14:06
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
I sent you RC Mail. Please check it and get back to me.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Page 1 of 3


Jump to


Protected Feature Before you can reply to a message...
You must first register for a Remote Central user account - it's fast and free! Or, if you already have an account, please login now.

Please read the following: Unsolicited commercial advertisements are absolutely not permitted on this forum. Other private buy & sell messages should be posted to our Marketplace. For information on how to advertise your service or product click here. Remote Central reserves the right to remove or modify any post that is deemed inappropriate.

Hosting Services by ipHouse