This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Control KODI
#2
(18.04.2017, 15:32)Superchango Wrote: Good afternoon,

Has anyone tried to control KODI through homelynk?
I would like to know if it is possible and how it can be done in such a case.


Thank you so much,

Hello, yes i use it but my code is very basic and needs some beautification Sad

the library
Code:
function kodiHandler(iServer,iPort,sendPort)  -- first call  if not ready then    require('socket')        lastdatareceived = nil    ready = true  end    -- client connected  if connected then    while true do      char, err = client:receive(1)      -- error while receiving, closed socket      if err == 'closed' then          connected = false        sleep(1)        break      end              if char ~= nil then        lastdatareceived = os.time()        warningclosed = true        warningfailed = true        warningerrors = true        warningtimeou = true                         table.insert(buffer, char)        tmpbuf = table.concat(buffer)        if ( json.pdecode(tmpbuf) ) then          data = tmpbuf          parse(data)          buffer = {}        end      else        now = os.time()        deltatime = now - lastdatareceived      end              -- receive incoming send requests          msg, ip, port = sendServer:receivefrom()             if msg then        -- send command        --log("send: "..msg)        client:send(msg)             end            --[[ clear not complete buffer      if deltatime > 10 and #buffer > 0 then        log( #buffer )        buffer = {}        lastdatareceived = os.time()      end      -]]    end        -- first call or previously disconnected  else    -- close previous connection when disconnected    if client then      client:close()      client = nil    end    if sendServer then      sendServer:close()      sendServer = nil    end        -- create tcp client    client = socket.tcp()    client:settimeout(5)    connected, err = client:connect(iServer, iPort)        -- connect ok, reset buffer    if connected then      lastdatareceived = os.time()      warningclosed = true      warningfailed = true      warningerrors = true      warningtimeou = true      --log('[KODI-client] connection ok: '..iServer)      buffer = {}            -- create udp server to receive incoming send requests             if not sendServer then               sendServer = socket.udp()               sendServer:setsockname('*', sendPort)               sendServer:settimeout(0.1)             end            sleep(5)            -- send initial command      --client:send( '{"jsonrpc": "2.0", "method": "Player.PlayPause", "params": { "playerid": 0 }, "id": 1}' )                -- error while connecting,    else             --log(err)      if warningfailed then log('[KODI-client] connection failed (conn): '.. err) end      warningfailed = false      sleep(5)    end  end    -- incoming command parser  function parse(data)    -- log other info, not mapped, if useful    --log("data received: "..data)    --log(json.pdecode(data))  end end

the resident script
Code:
require('user.nit_kodi') require('json') kodiHandler("192.168.x.x","9090","18007") -- callback from handler -- tv recording play function tvrecPlay()  log("test1") end -- tv recording - pause or stop function tvrecStop()   log("test2") end
in another script u can use for example:
Code:
udpsend( '{ "jsonrpc": "2.0", "id": 1, "method": "Application.SetVolume", "params": { "volume": 50 } }', "18007" )
Reply


Messages In This Thread
Control KODI - by Superchango - 18.04.2017, 15:32
RE: Control KODI - by gjniewenhuijse - 19.04.2017, 05:45
RE: Control KODI - by Superchango - 19.04.2017, 07:44
RE: Control KODI - by baggins - 19.04.2017, 12:04
RE: Control KODI - by Bart - 11.09.2017, 21:02
RE: Control KODI - by baggins - 13.09.2017, 14:59
RE: Control KODI - by leonidas - 19.04.2017, 14:23
RE: Control KODI - by gjniewenhuijse - 19.04.2017, 14:28
RE: Control KODI - by leonidas - 20.04.2017, 07:25
RE: Control KODI - by gjniewenhuijse - 20.04.2017, 08:26
RE: Control KODI - by Kellystewart - 02.10.2018, 09:02

Forum Jump: