Author Topic: Best Approach to Controlling a Network Device  (Read 51317 times)

CentralMedia

  • Guru
  • ****
  • Posts: 161
    • View Profile
Best Approach to Controlling a Network Device
« on: October 16, 2013, 02:14:24 am »
I have a PI running raspbmc, finally figured out some of the JSON RPC code, this afternoon.

Got the TCP connection to work, once, but work, its output is like, no separation for response

Quote
{"id":1,"jsonrpc":"2.0","result":"OK"}{ "jsonrpc": "2.0", "method": "Input.Down", "id": 1 }
{"id":1,"jsonrpc":"2.0","result":"OK"}{ "jsonrpc": "2.0", "method": "Input.Select", "id": 1 }
{"id":1,"jsonrpc":"2.0","result":"OK"}{ "jsonrpc": "2.0", "method": "Input.Home", "id": 1 }
{"id":1,"jsonrpc":"2.0","result":"OK"}

Also got the html request to work, also did the right, left, down

Quote
http://192.168.80.149:80/jsonrpc?request={ "jsonrpc": "2.0", "method": "Input.Select", "id": 1 }

Have not tried the websocket option, honestly have not wrapped my head around initiating or using it.

My question is, how best to implement the HTML  feature and if there are any example devices using this?

Would websocket be preferable and any example code.

Suggestions are also welcomed

 

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5549
  • DOES work for LinuxMCE.
    • View Profile
Re: Best Approach to Controlling a Network Device
« Reply #1 on: October 16, 2013, 07:52:55 pm »
How best to "implement the HTML feature?" I'm confused.

-Thom

seth

  • Guru
  • ****
  • Posts: 485
  • A day w/o LinuxMCE is like a day w/o sunshine!
    • View Profile
Re: Best Approach to Controlling a Network Device
« Reply #2 on: October 16, 2013, 09:25:51 pm »
Hi.

This post has caught my attention.
Do you intend to create an Orbiter Remote for an xbmc media device.
I have often thought about this, as I have 3 raspbmc raspberry pi's currently running as low power media centers back-ended by the LinuxMCE core PC (well one is openelec). Sharing media and assigning network addresses and such. As xbmc by default allows for web based control, which is how all the android and iDevices in my house control it, a new orbiter screen, and even possibly two way communications between xbmc and LinuxMCE using xbmc as a frontend and the core LinuxMCE server would be quite the rig.

I have been working on an xbmc screen to set up LinuxMCE functions, lighting, climate, etc. as it is silly easy to skin. But I have run out of available free time. This will be remedied over the upcoming holidays with any luck.

If I get it to a point that it is functional, I can at least attach the code bits for the xbmc > LinuxMCE interface. That coupled with a possible communication interface that is two-way between the two devices......that would be amazing. PI's running xbmc as a media device not unlike the Roku, would be like a Roku to the power of 10.  ;)

I will keep an eye on this thread.

Regards,

Seth
".....Because Once you've LinuxMCE'd....."
System stats located at my user page:

http://wiki.linuxmce.org/index.php/User:Seth

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5549
  • DOES work for LinuxMCE.
    • View Profile
Re: Best Approach to Controlling a Network Device
« Reply #3 on: October 16, 2013, 09:28:15 pm »
XBMC support will need to be written as a Plugin and Player pair, using C++. See Developing a DCE Device, on the wiki.

-Thom

seth

  • Guru
  • ****
  • Posts: 485
  • A day w/o LinuxMCE is like a day w/o sunshine!
    • View Profile
Re: Best Approach to Controlling a Network Device
« Reply #4 on: October 16, 2013, 09:40:46 pm »
 :)
I agree Thom.
I was hoping to create it as a device, but as I seem to never have time, I am torn between helping with the moonpi, or creating a service for xbmc.

Maybe the forum would like to push me one way or the other.

The raspberry Pi is just such a tasty little device. Low power. Easily concealed. CeC enabled.

Oh my.

Regards,

Seth
".....Because Once you've LinuxMCE'd....."
System stats located at my user page:

http://wiki.linuxmce.org/index.php/User:Seth

phenigma

  • LinuxMCE God
  • ****
  • Posts: 1758
    • View Profile
Re: Best Approach to Controlling a Network Device
« Reply #5 on: October 16, 2013, 10:14:37 pm »
It depends on what you want.  Is your goal to use the Pi? or is your goal to use xbmc?

If the goal is to use the Pi then I would push you incredibly towards helping with qOrbiter on the rPi.  This will be an 'integrated' way forward for orbiter/md control/media playback on the pi.  We need a DCE aware libCEC device to run on the moonPi (this could operate as a standalone DCE-libCEC interface on Pi and it could also be used on a moonPi).  We need testing.  I don't know if more than 2-3 people have even tried to install an MD on a Pi, and I only hear from 1 or 2 people sporadically.

If the goal is to use xbmc (on whatever) then an xbmc device and plugin could be pursued.  I don't see this as useful unless complete orbiter functionality can be brought to xbmc.  Use nfs/smb/upnp/dlna connectivity to play media from the core otherwise.

Both have their usefullness.  For lmce project purposes I will push qOrbiter and moonPi.   ;D

J.

golgoj4

  • NEEDS to work for LinuxMCE
  • ***
  • Posts: 1193
  • hrumpf!
    • View Profile
    • Mah Website
Re: Best Approach to Controlling a Network Device
« Reply #6 on: October 17, 2013, 01:52:18 am »
It depends on what you want.  Is your goal to use the Pi? or is your goal to use xbmc?

If the goal is to use the Pi then I would push you incredibly towards helping with qOrbiter on the rPi.  This will be an 'integrated' way forward for orbiter/md control/media playback on the pi.  We need a DCE aware libCEC device to run on the moonPi (this could operate as a standalone DCE-libCEC interface on Pi and it could also be used on a moonPi).  We need testing.  I don't know if more than 2-3 people have even tried to install an MD on a Pi, and I only hear from 1 or 2 people sporadically.

If the goal is to use xbmc (on whatever) then an xbmc device and plugin could be pursued.  I don't see this as useful unless complete orbiter functionality can be brought to xbmc.  Use nfs/smb/upnp/dlna connectivity to play media from the core otherwise.

Both have their usefullness.  For lmce project purposes I will push qOrbiter and moonPi.   ;D

J.

As the developer of qOrbiter, im partial to that
As a guy who likes making stuff go, im open to making the device. ive made a couple already. if it speaks json then thats stupid easy to work with.

But alas,
broham is like developing qorbiter skins, qorbiter backend, qorbiter for mobile devices, trying to maintain autotagger... did i mention i added phillips hue lighting control? but yeah...point me to a spec and lets see how much work it actually is.

-golgoj4
i am also somewhat of a qt fanatic and like to put it everywhere.
anyways, as you can see, i have crap to do. discuss amongst yourselves :p
Linuxmce - Where everyone is never wrong, but we are always behind xbmc in the media / ui department.

CentralMedia

  • Guru
  • ****
  • Posts: 161
    • View Profile
Re: Best Approach to Controlling a Network Device
« Reply #7 on: October 17, 2013, 01:59:54 pm »
tschak909
The question should be how to send this type of HTML from a shell script, or what device has this feature that I can attempt to familiarize.

My programming languages are non existent, but plan on getting this to work.

Seth

You have this figured out much better than I, actually my focus now, is just getting navigation, once done, move from there, did not want to bit of more than I can cope with.

CentralMedia

  • Guru
  • ****
  • Posts: 161
    • View Profile
Re: Best Approach to Controlling a Network Device
« Reply #8 on: October 30, 2013, 12:36:19 am »
Ok, figured out how to use curl to send the commands, even figured out how to play a file, LNMCE shares not working, feel I need to pass the password along with the smb call, hopefully will figure out how to.

Working
Quote
curl -i -X POST -H "Content-Type: application/json" -d "{\"jsonrpc\": \"2.0\", \"method\": \"Player.Open\", \"params\": { \"item\": { \"file\": \"/home/pi/Video/skyfall.mp4\"} , \"options\":{ \"resume\":true } }, \"id\": 1}" http://192.168.80.150:80/jsonrpc
curl -i -X POST -H "Content-Type: application/json" -d "{\"jsonrpc\": \"2.0\", \"method\": \"Player.GetActivePlayers\", \"id\": 1}" http://192.168.80.150:80/jsonrpc
curl -i -X POST -H "Content-Type: application/json" -d "{\"jsonrpc\": \"2.0\", \"method\": \"Player.PlayPause\", \"params\": { \"playerid\": 1}, \"id\": 1}" http://192.168.80.150:80/jsonrpc
curl -i -X POST -H "Content-Type: application/json" -d "{\"jsonrpc\": \"2.0\", \"method\": \"Player.Stop\", \"params\": { \"playerid\": 1}, \"id\": 1}" http://192.168.80.150:80/jsonrpc
curl -i -X POST -H "Content-Type: application/json" -d "{\"jsonrpc\": \"2.0\", \"method\": \"Input.Home\", \"id\": 1}" http://192.168.80.150:80/jsonrpc
curl -i -X POST -H "Content-Type: application/json" -d "{\"jsonrpc\": \"2.0\", \"method\": \"Input.Left\", \"id\": 1}" http://192.168.80.150:80/jsonrpc
curl -i -X POST -H "Content-Type: application/json" -d "{\"jsonrpc\": \"2.0\", \"method\": \"Input.Right\", \"id\": 1}" http://192.168.80.150:80/jsonrpc
curl -i -X POST -H "Content-Type: application/json" -d "{\"jsonrpc\": \"2.0\", \"method\": \"Input.Down\", \"id\": 1}" http://192.168.80.150:80/jsonrpc
curl -i -X POST -H "Content-Type: application/json" -d "{\"jsonrpc\": \"2.0\", \"method\": \"Input.Select\", \"id\": 1}" http://192.168.80.150:80/jsonrpc

Not Working, think I need to pass the password some how, not figured out as yet.
Quote
curl -i -X POST -H "Content-Type: application/json" -d "{\"jsonrpc\": \"2.0\", \"method\": \"Player.Open\", \"params\": { \"item\": { \"file\": \"smb://DCEROUTER/public/videos/DespicableMe2Test.mkv\"} , \"options\":{ \"resume\":true } }, \"id\": 1}" http://192.168.80.150:80/jsonrpc
curl -i -X POST -H "Content-Type: application/json" -d "{\"jsonrpc\": \"2.0\", \"method\": \"Player.Open\", \"params\": { \"item\": { \"file\": \"smb://192.168.80.1/public/videos/DespicableMe2Test.mkv\"} , \"options\":{ \"resume\":true } }, \"id\": 1}" http://192.168.80.150:80/jsonrpc

Can anymore can shed some light how tothe capture the response by curl, in a shell script, need to get the player id seen below

Quote
linuxmce@dcerouter:~/CodingWork/XBMC$ curl -i -X POST -H "Content-Type: application/json" -d "{\"jsonrpc\": \"2.0\", \"method\": \"Player.GetActivePlayers\", \"id\": 1}" http://192.168.80.150:80/jsonrpc
HTTP/1.1 200 OK
Content-Length: 65
Content-Type: application/json
Date: Tue, 29 Oct 2013 23:15:30 GMT

{"id":1,"jsonrpc":"2.0","result":[{"playerid":1,"type":"video"}]}

As I learn how to communicate with devices on the network, the next device is the WD live HD, borrowed a switch from a friend, where I can mirror the port, so I can see how the Andriod app connects and send commands, by collecting the data with wireshark, doing that tomorrow. Had written WD about an API, but got no definitive feedback from them

Fun times

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5549
  • DOES work for LinuxMCE.
    • View Profile
Re: Best Approach to Controlling a Network Device
« Reply #9 on: October 30, 2013, 12:39:23 am »
As I said before, this will need to be done as a C++ device.

-Thom

Stash_CEO

  • Regular Poster
  • **
  • Posts: 42
    • View Profile
Re: Best Approach to Controlling a Network Device
« Reply #10 on: October 30, 2013, 03:40:25 pm »
I also have a RPI and it's been sitting in my desk drawer waiting to be unleashed.  I played around with RaspBMC a little and liked it but am trying to get more from LMCE so I've put it on hold.  I'd like to see the PI running as an MD but I'm also going to use them as squeezeslaves.  I know zero about coding and wish I could give you guys a hand other than testing.  Anyone have any ideas where and what code I can learn to help you guys out.

Dap-P

  • Veteran
  • ***
  • Posts: 106
    • View Profile
Re: Best Approach to Controlling a Network Device
« Reply #11 on: October 30, 2013, 11:49:21 pm »
Code: [Select]
linuxmce@dcerouter:~/CodingWork/XBMC$ curl -i -X POST -H "Content-Type: application/json" -d "{\"jsonrpc\": \"2.0\", \"method\": \"Player.GetActivePlayers\", \"id\": 1}" http://192.168.80.150:80/jsonrpc
HTTP/1.1 200 OK
Content-Length: 65
Content-Type: application/json
Date: Tue, 29 Oct 2013 23:15:30 GMT

{"id":1,"jsonrpc":"2.0","result":[{"playerid":1,"type":"video"}]}

I know a little about capturing data from scripts, this is as i would do this:
playerid=$(curl -i -X POST -H "Content-Type: application/json" -d "{\"jsonrpc\": \"2.0\", \"method\": \"Player.GetActivePlayers\", \"id\": 1}" http://192.168.80.150:80/jsonrpc | grep playerid | awk -F'playerid":' '{print $2}' | awk -F',' '{print $1}')

something like this should capture the player id in a variable called playerid

Anton

CentralMedia

  • Guru
  • ****
  • Posts: 161
    • View Profile
Re: Best Approach to Controlling a Network Device
« Reply #12 on: October 31, 2013, 10:48:59 pm »
Thanks, will play with that for now, trying to organize in my head how all this work. I currently have a shell script that accepts one input and does basic navigation. The media control, was doing that at the command prompt, all in a effort to rap my head around this.

Investigating, as I do not know how, using curl within c++, following tschak900 suggestion, found including libcurl.h, but really trying to use the executable directly. I believe that what he suggested, the system will handle all sending the file to play to the PI, I just need to be able to process it.


tschak909

  • LinuxMCE God
  • ****
  • Posts: 5549
  • DOES work for LinuxMCE.
    • View Profile
Re: Best Approach to Controlling a Network Device
« Reply #13 on: November 01, 2013, 06:35:43 am »
You may want to look at the src/Roku_LTHDXD_Streaming_Pla code. It uses libcurl to send HTTP requests to ask the player to do things via its ECP port. There are plenty of C++ examples for parsing JSON, as well.

-Thom

CentralMedia

  • Guru
  • ****
  • Posts: 161
    • View Profile
Re: Best Approach to Controlling a Network Device
« Reply #14 on: November 01, 2013, 09:28:43 pm »
Ok

Went through the code, forgive me but I am strickly green, lets see if I have the logic correct
The RokuDevice.h sets up the ground work, defining what should happen to initiate a connection, while the RokuDevice.cpp, implements the the constructure and the two functions
defined in RokuDevice.h. The Roku_LTHDXDXS_Streaming_Pla.cpp, implements what is defined in its corresponding Roku_LTHDXDXS_Streaming_Pla.h.

I actually see where the commands are coded

Quote
void Roku_LTHDXDXS_Streaming_Pla::CMD_EnterGo(int iStreamID,string &sCMD_Result,Message *pMessage)
   //<-dceag-c190-e->
   {
      cout << "Need to implement command #190 - Enter/Go" << endl;
      cout << "Parm #41 - StreamID=" << iStreamID << endl;
      PLUTO_SAFETY_LOCK(rm, m_RokuMutex);
      m_pRokuDevice->SendToRoku("POST /keypress/Select HTTP/1.1\r\n\r\n");

   }

The question comes, is it at this point, see below, that libcurl is being used or I have completely missed the boat?

Quote
m_pRokuDevice->SendToRoku("POST /keypress/Select HTTP/1.1\r\n\r\n");