Remote Control by json etc

Yeah correct the port need to match what Kodi is using. If you use port 80 you even can leave it out.
I wrote 8080 as I have my Kodi webinterface running to avoid conflict with Webserver on Port 80

Curl is surely the better option especially also if you want to put this in a batch file and use the return code

OMG, Thank You Thank You Thank You.

I copied your script into a batch file (changed the address) and ran it. It worked perfectly.

Just so I’m clear, all I have to do is replace “Input.Right” with other commands, without changing anything else, and I can get all my needed commands working?

FYI, for anybody else who might be using old girder (3.2) and want to do what I’m doing (not likely), the command is:

Execute
File:  C:\Windows\System32\curl.exe 
Step Size:  -X POST -H "content-type:application/json" http://osmc:osmc@192.168.86.36:80/jsonrpc -d {\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"Input.Right\"}
Startup Options:  Hidden

Then name this command “Arrow Right”. Then create a netremote button and aim it at girder’s “arrow right” command.

darwindesign, you are the man.

If I get stuck again, I’ll come back. But, I think I’m OK.

1 Like

All the http commands are listed in the forum thread I linked above

Yes, thanks fzinken, I think I’ll find them all.

Indeed, and some of them require additional information/parameters. But, if I understand this correctly (big IF :grin:) you can steal the parts from that thread inside of the {curly brackets} and then add a "\" preceding every quote inside the curly brackets and should be good to go.

Now I will have:
girder talking to girder for the htpc
girder talking to wget for the directv box
girder talking to curl for the vero.

Whoever bet that I would have additional questions … you win.

I’ve locked in my 7 “navigation” commands (commands where you are moving around the GUI, etc (arrow right). They all share the same command structure “Input.???”

I also need commands that control the player, such as PlayPause (Player.PlayPause). They seem to share the same command structure “Player.???”.

What I’m concerned about is that other elements of the syntax may need to change as well.

Here is the example that darwindesign provided and that I’m using as the basis:
-X POST -H “content-type:application/json” http://osmc:osmc@192.168.86.36:80/jsonrpc -d {"jsonrpc":"2.0","id":1,"method":"Input.Right"}

Can someone let me know if something other than the specific command needs to change and, if so, what is that change.

I just realized my copy/paste of darwindesign example is not an exact match (it gets rid of the backslashes) . So, if possible, please refer to darwindesign original code.

I only can repeat myself

Yes, fzinken, I know and have read that entire thread.

Here is the code for Player.PlayPause:

http://192.168.100.13:8080/jsonrpc?request={“jsonrpc”:“2.0”,“method”:“Player.PlayPause”,“params”:{ “playerid”: 1},“id”:1} – play pause

As you can see, it is very, very different from darwindesign code. Since I don’t speak code, I’m not capable of looking at the other threads code and interpreting it into darwindesign code. Best I can tell, no other changes (other than the specific command) are needed, but I’m not sure of that at all.

To let you know that I’m not simply asking unnecessary questions, at the present time, my vero is not in a position to actually play anything. So trying different things would not be easy. Unlike navigation commands which are easily testable.

As I stated above you need to escape the quotes with back slashes. If you’re copying a command that has any spaces inside the curly brackets you will need to remove them as well. As for the code above the " – play pause" at the end was just a note that person tagged onto the end in that post to specify what the command does and it cannot be included.

{\"jsonrpc\":\"2.0\",\"method\":\"Player.PlayPause\",\"params\":{\"playerid\":1},\"id\":1}

I’m not a programmer and I don’t speak code either. I literally just put in a bit of effort trying things in that thread that fzinken linked to and a bit of searching on the interwebs to find what worked which led me to the realization of that I could just grab stuff from that thread and tweak it like I posted above to be able to use it in the Windows terminal. I just copy/pasted from linked threads into notepad++, tweaked, and then copy/pasted it into CMD. If there is an issue the return message lets you know.

When you are typing your reply there is a button </> that you can press after highlighting text and then it will display code correctly.

It dawned on me that there is another method that may prove helpful here for some commands to use in concert with what you have already started. This is slower, so you probably wouldn’t want to use it for navigation, but it is easier to understand and may allow for some things to happen that you can’t find sample json code for.

I’m going to assume you are running a new enough windows that it has ssh at the terminal and that you either enabled ssh during the Vero’s initial setup or installed it via My OSMC afterwards. Thus you should be able to run via CMD…

ssh osmc@192.168.86.36

and that should connect to your Vero and ask you for a password (default is “osmc”). If that is all good then type “exit” to get back to windows and type in…

ssh-keygen

It will ask you a couple things. Don’t type anything in, just hit enter at each prompt. You will then need to open the following file with a text editor in Windows…

C:\Users\YOUR_USERNAME/.ssh/id_rsa.pub

Of course using your account name. The output from the previous command will show you the exact path it was saved in. Once you have that open, ctrl+a, ctrl+c, and then go back to the terminal where we will need to add this to your Vero.

ssh osmc@192.168.86.36
[enter your password which is likely "osmc"]
mkdir .ssh
nano .ssh/authorized_keys
[clicking your right mouse button should paste the text]
ctrl+x, y, then enter [to save the file and exit]
exit
ssh osmc@192.168.86.36

That last command should have dropped you back into the Vero’s terminal but not ask you for a password. If so, then you are setup correctly.

From here we can push the same commands that the remote controls use from windows using the following format…

ssh osmc@192.168.86.36 "kodi-send -a info"

The only part of that line that you will change will be the action which is where the above says “info”. A list of the actions available can be found here…

https://kodi.wiki/view/Action_IDs

Although you may find it a bit easier to reference from here…

https://kodi.wiki/view/Keymap

If you have an action you want to use that has an argument that is contained in parentheses such as “UpdateLibrary(video)” you will need to escape with the parentheses with a backslash like the following in order for it to actually work…

ssh osmc@192.168.86.36 "kodi-send -a UpdateLibrary\(video\)"

You will probably want to test them at the command prompt while you can see Kodi for the response to make sure each command works. There exist some actions that will not pass with Kodi-send, although most do.

EDIT: I figured out that instead of escaping the parentheses you can just wrap the Kodi action in single quotes and that works as well…

ssh osmc@192.168.86.36 "kodi-send -a 'UpdateLibrary(video)'"

Sorry for being away, but other priorities came up.

Since I last posted, I moved the Vero into the theater so that I could test the player commands.

darwindesign, I read your incredibly detailed extremely helpful post. I’m honored that you took all that time.

Anyway, I tried moving to ssh rather than curl. That is the perfect solution for me. I can read and understand the commands and the list of commands contain everything I need.

Unfortunately for me, the server (contains all content and commands) is Windows 8.1, so I had to install ssh onto the machine. Fortunately a great youtube video exists to do exactly that.

I didn’t bother migrating the navigation commands from curl to ssh (since they already worked), but I did complete my list with ssh.

This also enabled me to test the Vero for the purpose I bought it … to play frame-packed 3D with passthru HD audio. It works perfectly. It works so perfectly that I ran all media content to the Vero and now the Vero is my HTPC.

Thanks everybody for your help and I am very, very happy with my purchase.

2 Likes

I don’t think changing navigation from json to ssh would be optimal as the latter is slower due to adding the extra steps of opening the ssh tunnel and running an extra program. The delay would be of little consequence for something like calling up an information widow but would be annoying for stepping through your library with the navigation actions.

Perhaps I can simplify the json command a bit so it is not quite as confusing. I will use this command from above as an example…

curl.exe -X POST -H "content-type:application/json" http://osmc:osmc@192.168.86.36:80/jsonrpc -d {\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"Input.Right\"}

None of the parts outside of the braces is going to change from command to command for you so lets ignore those for now…

{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"Input.Right\"}

Because we are working in Windows CMD we had to use backslashes to escape the double quotes (meaning this is how we tell CMD to keep passing along the quotes as regular text to the application being called instead of interpreting the quotes as something it should act on itself). I also removed the spaces inside the braces for a similar reason. Lets revert that for now to make it a bit more readable…

{ "jsonrpc": "2.0", "id": 1, "method": "Input.Right"}

Which should be clear is just using the schema…

{ "key1": "value1", "key2": value2, "key3": "value3"}

The jsonrpc and id keys are going to be the same for all commands so for the more basic stuff their is really only one key:value pair you would need to swap out to form a different request. So lets use this information on some random example you might find on the interwebs…

 curl -s -L -m3 --connect-timeout 5 -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"VideoLibrary.Clean", "params": { "showdialogs": false }, "id":1}' http://<MrMC_host>:8080/jsonrpc > /dev/null 

We only need pay attention to the request itself…

{"jsonrpc":"2.0","method":"VideoLibrary.Clean", "params": { "showdialogs": false }, "id":1}

which shows that what we need is the keys for method and params since we already have jsonrpc and id. This is easy enough to insert into the part of your command that is not changing ie…

curl.exe -X POST -H "content-type:application/json" http://osmc:osmc@192.168.86.36:80/jsonrpc -d {\"jsonrpc\":\"2.0\",\"id\":1,}

remembering to remove spaces and insert backslashes to escape any double quotes which gives us the finished command…

curl.exe -X POST -H "content-type:application/json" http://osmc:osmc@192.168.86.36:80/jsonrpc -d {\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"VideoLibrary.Clean\",\"params\":{\"showdialogs\":false }}

BTW the above command cleans your video library WITHOUT popping up a progress screen in Kodi. If someone is actively using Kodi this is much nicer than calling for a library clean using other methods. Also note that like the ‘1’ value for ‘id’ the ‘false’ value for ‘showdialogs’ is NOT double quoted. This is important as that would change what is a required boolean true/false value and change it to a string which will produce an error.

I’ve been playing around with this quite a bit this week making a batch script maintenance utility for myself and have found there is quite a lot you can do. In your case I would recommend you take a look at this…
https://kodi.wiki/view/Archive:JSON-RPC_API/v6#Input.Action
If you click [expand] under Input.Action you will see there is a massive amount of control available over what you find as examples in that Kodi forum post.

Thanks again, darwindesign.

After much trial/error, I have successfully moved 6 more commands from ssh to curl. It is snappier. I now only have 6 commands that are still ssh. They are:

-Skip forward 30 seconds
-Skip backwards 11 seconds
-Toggle subtitles On/Off
-Go to next audio stream
-Go to top
-Go to bottom

The top and bottom commands are meant to jump to the first movie in the list and the last movie in the list (I have 88 pages worth of movies in fanart kodi).

I looked for these curl commands both on the kodi thread and the json wiki and either couldn’t find them or couldn’t identify them.

Does anyone know the curl commands for the above buttons?

top and bottom I would guess would be firstpage and lastpage. Although you might want to consider adding in either nextletter/prevletter or a set of buttons attached to the jumpsms’s. For the skip forward thing why would you do it like that? Look up the Kodi wiki on skip steps and it will tell you how to add in an entry into advanced settings to enable a 11 second skip into your list. You can then go into Kodi’s settings and make the first left/right 30 and -11, with no extra clutter in your controls needed. Subs would be “showsubtitles”, and audio stream “audionextlanguage”.

They are in the link I posted at the bottom of my last reply. If you are confused on the naming check out the keymap wiki I think I posted a link to earlier. The names are not going to all be identical, but should be close enough to figure it out. The keymap wiki gives some extra info about what some of this stuff actually does so it should prove useful.

I tried to follow your last post, but I could not get it to work (and really didn’t understand). I’ll just stick to ssh commands for those since the slight lag isn’t that annoying.

{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"input.executeaction\",\"params\":{\"action\":\"firstpage\"}}

Navigates to the top of some screens including the libraries

{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"input.executeaction\",\"params\":{\"action\":\"lastpage\"}}

Navigates to the last entry of some screens including the libraries

{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"input.executeaction\",\"params\":{\"action\":\"nextletter\"}}

In the libraries each time it is pressed it navigates to the first entry using the next letter in the alphabet from what is currently selected.

{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"input.executeaction\",\"params\":{\"action\":\"prevletter\"}}

Ditto, but in reverse.

{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"input.executeaction\",\"params\":{\"action\":\"jumpsms2\"}}

Numbers 2-9 each have three letters they cycle through. SMS2 for example does a, b, and c. Each time you activate sms2 it navigates to the library item starting with a, then b, then c, then back to a on a fourth activation. Once you get used to it this allows faster navigation than page up/down, nextletter, or similar, while needing less input buttons than a full alphabetical keypad. There is also a filter variant of sms. I personally could never wrap my head around why someone would actually want that ability.

{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"input.executeaction\",\"params\":{\"action\":\"showsubtitles\"}}

Toggles subtitles on/off during playback.

{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"input.executeaction\",\"params\":{\"action\":\"audionextlanguage\"}}

During playback if more than one audio track is present this will cycle through them.

1 Like

Changed the title as this has become a rich resource for anyone looking for json tips. ie not just about remote controllers.

In case anyone is interested I figured out a better (IMO) way to format the escape characters to get the json to pass using CMD. Taking the example from earlier…

{"jsonrpc":"2.0", "method":"VideoLibrary.Clean", "params": { "showdialogs": false }, "id":1}

Instead of changing it to this…

{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"VideoLibrary.Clean\",\"params\":{\"showdialogs\":false }}

I change the formatting to…

"{""jsonrpc"":""2.0"", ""method"":""VideoLibrary.Clean"", ""params"": { ""showdialogs"": false }, ""id"":1}"

I find this style quicker to type and easier to read. The rules that are in play here are that a double quote preceding a double quote escapes the second double quote so it passes without being interpreted by CMD. It provides the same function as the backslash preceding a double quote to escape it and both methods can be used interchangeably. The single set of double quotes that are wrapping the entire json request (ie "{...}") keeps the entire thing as a single block which allows spaces to exist within the request. The block starts with a single double quote and ends with the first double quote that is not escaped.

On a somewhat related note I also found (the hard way) the above command (with showdialogs set to false ) to be (potentially) a bit dangerous. Back in the day XBMC would happily remove ALL content from your library if you ran a clean and your source location happened to not be accessible at that moment. At some point a check was added so if your source location went missing and you told it to clean your library a warning would popup asking you to confirm this mass destruction. I don’t think this check happens when running a clean silently with this particular command.

2 Likes