2

Description : I am trying to make a remote controller for OSMC(Kodi) media player installed on Raspberry pi. Rpi will connected to mobile app through wifi. On the other hand Rpi is connected to switch board using RS232. Let me post a picture here to get an exact idea of connectivity..

enter image description here

Now OSMC provides its APIS to control operations like menu left , right , enter , volume up etc. That through Rpi's static IP we can perform from mobile App.

Now our Main Board will have 4 zones which will be connected to 4 display among one of them will display OSMC media player. What I am trying to do is to switch between display to show osmc media player.

I am using http://pyserial.sourceforge.net/ library to send command from from Rpi to switch board to arrange connections between switch board and displays.

Now the question : How to Send commands from Mobile App to Rpi(like telling Rpi this command you have to call on Rs232), through Web Service? Mobile Developer Suggested me to use some socket programming. But I have very little knowledge about the same. I know if we have static IP of Rpi there can be some data exchange done between Mobile App and Rpi, But I am still confused regarding what medium to use for communication. Any suggestions would be appreciated.

1

The way you control Kodi (the media center application) remotely over the network is through it's JSON-RPC API. You could create a similar api to switch screens. This particular application would be well suited for a RESTful API. Your REST server on you pi will listen for GETs,PUTs,POSTs etc from your app and take action when it receives them. If it were me, I would code the server in node.js with express. Alternitively, you could use python with django or any other number of languages and frameworks. By using this method your app simply needs to send HTTP requests and parse the response, the same as when using the Kodi API.

Example API

List screens

GET RASPBERRY-PI/api/displays

Should return:

{
    "displays": [{
        "id": 0,
        "name": "outside",
        "enabled": "true"
    }, {
        "id": 1,
        "name": "inside",
        "enabled": "false"
    }, {
        "id": 2,
        "name": "downstairs",
        "enabled": "true"
    }]
}

Set screen state

PUT RASPBERRY-PI/api/displays/2

With body:

{
    "id": 2,
    "name": "outside",
    "enabled": "true"
}

Add new screen

POST RASPBERRY-PI/api/displays/4

With body:

{
    "id": 4,
    "name": "upstairs",
    "enabled": "false"
}
  • Thank you so much for answer. I am quite familiar with how to create rest api with django rest framework . I am used to host them on apache server on ubuntu, But I am confused about how to do that on OSMC. means do I have to create new server with python on osmc and create apis there or I have to write web service on the defaut web server provided by them. Even If I will come to know answer of this, I am confused about how to do this. Please provide any link which gives explanation. – Pawan Jun 26 '15 at 6:17
  • You can simply use apache on OSMC like you are used to. OSMC is based on RaspBMC is based on Raspbian is based on Debian. Ubuntu is based on Debian so information on using apache on debian is likely relevant. Alternatively, the lighter weight nginx web server is a good fit for the raspberry pi. Also, you will need to use a different port for your django app. I believe the Kodi web ui is set to port 80 in OSMC. Try having your django app on port 8000. – Kevin Brey Jun 29 '15 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.