Go Down

Topic: Control XBMC trough JSON from arduino (Read 2014 times) previous topic - next topic

redcell

Jul 10, 2014, 04:32 am Last Edit: Aug 22, 2014, 09:13 pm by redcell Reason: 1
I created some code to control XBMC trough JSON from an arduino.

You need an arduino with ethernet or wifi shield, configure xbmc to not use a password and login.

you can trigger the code with for example a webserver running on the arduino, create url's to visit wich trigger the code..
or use an infrared or RF sensor to trigger what the arduino needs to send to XBMC etc..

in your own project you just need this code:

Code: [Select]

byte xbmchost[] = {192, 168, 2, 10}; // change to ip of htpc/computer running xbmc
unsigned int xbmcport = 8080; // change to xbmc port

// funtion wich sends the commands to xbmc
void xbmc(char *method, char *params)
{
 if (client.connect(xbmchost,xbmcport))
 {
   client.print("GET /jsonrpc?request={\"jsonrpc\":\"2.0\",\"method\":\"");
   client.print(method);
   client.print("\",\"params\":{\"");
   client.print(params);
   client.println("},\"id\":1}  HTTP/1.1");
   client.println("Host: XBMC");
   client.println("Connection: close");
   client.println();
   client.stop();
 }
 else
 {
   client.stop();
 }
}

// commands to send:

/********** media controls ***********/

// play/pause
xbmc("Player.PlayPause","playerid\":1");
// stop
xbmc("Player.Stop","playerid\":1");
// small step backwards
xbmc("Player.Seek","playerid\":1,\"value\":\"smallbackward");
// small step forward
xbmc("Player.Seek","playerid\":1,\"value\":\"smallforward");
// big step backward
xbmc("Player.Seek","playerid\":1,\"value\":\"bigbackward");
// big step forward
xbmc("Player.Seek","playerid\":1,\"value\":\"bigforward");
// increase speed
xbmc("Player.SetSpeed","playerid\":1,\"speed\":\"increment\"");
// decrease speed
xbmc("Player.SetSpeed","playerid\":1,\"speed\":\"decrement\"");

/********** navigation **********/

// up
xbmc("Input.ExecuteAction","action\":\"up\"");
// down
xbmc("Input.ExecuteAction","action\":\"down\"");
// left
xbmc("Input.ExecuteAction","action\":\"left\"");
// right
xbmc("Input.ExecuteAction","action\":\"right\"");
// select
xbmc("Input.ExecuteAction","action\":\"select\"");
// back
xbmc("Input.ExecuteAction","action\":\"back\"");

/********** subtitles **********/

// subtitle on
xbmc("Player.SetSubtitle","playerid\":1,\"subtitle\":\"on\"");
// subtitle off
xbmc("Player.SetSubtitle","playerid\":1,\"subtitle\":\"off\"");
// switch subtitle
xbmc("Player.SetSubtitle","playerid\":1,\"subtitle\":\"next\"");
// search subtitle
xbmc("Addons.ExecuteAddon","addonid\":\"script.xbmc.subtitles\"");

/********** language **********/

// switch language
xbmc("Player.SetAudioStream","playerid\":1,\"stream\":\"next\"");


/********** trigger addons **********/

// show tvguide
xbmc("Addons.ExecuteAddon","addonid\":\"script.tv.show.next.aired\"");
// watch trailers
xbmc("Addons.ExecuteAddon","addonid\":\"plugin.video.itunes_trailers\"");
// start youtube
xbmc("Addons.ExecuteAddon","addonid\":\"plugin.video.youtube\"");
// xot
xbmc("Addons.ExecuteAddon","addonid\":\"net.rieter.xot\"");


/********** open menu's **********/

// home screen
xbmc("GUI.ActivateWindow","window\":\"home\"");
// favourites
xbmc("GUI.ActivateWindow","window\":\"favourites\"");
// weather
xbmc("GUI.ActivateWindow","window\":\"weather\"");
// music
xbmc("GUI.ActivateWindow","window\":\"music\"");
// movies
xbmc("GUI.ActivateWindow","window\":\"video\",\"parameters\":[\"MovieTitles\"]");
// recently added movies
xbmc("GUI.ActivateWindow","window\":\"video\",\"parameters\":[\"RecentlyAddedMovies\"]");
// series
xbmc("GUI.ActivateWindow","window\":\"video\",\"parameters\":[\"TVShowTitles\"]");
// recently added series episodes
xbmc("GUI.ActivateWindow","window\":\"video\",\"parameters\":[\"RecentlyAddedEpisodes\"]");


/********** music **********/

// party mode
xbmc("Player.Open","item\":{\"partymode\":\"music\"}},\"id\":1");


/********** select tv channels **********/

// select channel 41
xbmc("Player.Open","item\":{\"channelid\":41}}"); // change 41 to whatever channel you want


more detailed sketch posted on github: https://github.com/spambus/XBMCArduino

enjoy!

MKSaeed

Could you please explain how if I want to trigger control command with web page or remote?

Go Up