Developing network service
#1
Hi there

I want to develop an add-on for Kodi that will need to take instructions (via network, probably using HTTP/REST) and interact with Kodi. I'm wondering what's the best (or only) way to go about it.

Does Kodi have a way to run an add-on like this (as if it's a service, so indefinitely) and allow it to interact with Kodi (so using xbmc, etc. modules)?

If not, from what I read, it looks like the only way to interact with Kodi by not using the Python modules is via the JSON-RPC API?

What type of extension like this does Kodi class it as? Would that be an add-on, script, etc?
Reply
#2
If the features of Kodi JSON-RPC API are not enough for you, Kodi includes a full-featured Python (or more exactly, CPython) runtime, so you can use any Python libraries for your purposes. I guess, you can even use Django inside Kodi, but that would be a huge overkill for any purpose. The only recommendation is not to use Python libraries which include binary components. Technically, you can use such libraries but maintaining such addon is real PITA, especially if you want to support several platforms.

As for addon type, you need a service addon that will run in the background, hosting your network server. In this case it is strongly recommended for your service to periodically poll xbmc.abortRequested flag so that your server could be gracefully terminated along with Kodi.
Reply
#3
Thanks for that. A service extension sounds like that's exactly what I need, and I can just import the Kodi Python modules. Would there be any disadvantage to doing that instead of using the JSON-RPC API or any other way?

All the service needs to do is listen for REST/HTTP and also act on various Kodi events.
Reply
#4
if the json api provides all you need to interact with kodi, your rest stuff can also live outside of kodi as a kind of proxy.
Reply
#5
(2016-03-26, 16:18)jgivings Wrote: Would there be any disadvantage to doing that instead of using the JSON-RPC API or any other way?

Your question doesn't sound quite right. It's not "either this or that" situation. If JSON-RPC satisfies your needs, then you can use it without organizing your own service. If JSON-RPC lacks features that you need, you can create your own network service that complements JSON-RPC. The disadvantage is that, well, you need to create this service.

You can look at my YATP addon as a practical example of an addon with its own web/JSON server.
Reply
#6
I might elaborate on my project a bit more. It's actually part of an academic study. The plan is to put Kodi boxes (probably on Raspberry Pi) in participants' homes and send/receive data. We'll use their existing Internet, so to send data to the boxes, we'll need to traverse NAT. Therefore, we'll need to have the boxes establish and maintain a connection to a remote server. We could use SSH forwarding, VPNs, etc., but the plan for now is to keep it lightweight and standalone.

It looks like I'll need to create a service for that reason alone. Now, the service can either be a Kodi add-on or independent. If an add-on, then I at least have the choice of importing the Kodi modules and using them directly. I could also use other methods (like JSON-RPC API), but there doesn't seem to be a good reason to, and would only increase the complexity. If an independent service, then it looks like I only have the choice of JSON-RPC API or the runtime mentioned.

The simplest option seems to be service add-on and using Kodi Python modules directly. What do you guys think?
Reply
#7
given that you want to build a "phone home" system, going with a python based service addon seems reasonable.

I'd be interested in the details of the data you're looking for in this study.
Reply

Logout Mark Read Team Forum Stats Members Help
Developing network service0