Trying to fix the Transport control button in the Vera UI7 web GUI.
The Kodi HTTP commands are in the plugin file named “I_KODIRemote.xml”
I looked at fixing the “Back” button first.
Original Code:
function send_kodi_back_command ()
durl = "http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Input.Back%22%2c+%22id%22%3a+1%7d"
http = require("socket.http")
local body, code, headers, status = http.request(durl)
end
New Code: This DOES NOT WORK
function send_kodi_back_command ()
os.execute('curl -X POST -H "content-type:application/json" http://" .. ipAddress .. ":8080/jsonrpc -d \'{"jsonrpc":"2.0","id":1,"method":"Input.Back"}\'')
end
This does work OK however if I explicitly hardcode the Kodi PC’s IP address. When pressing the “Back” button the Kodi GUI does go back.
function send_kodi_back_command ()
os.execute('curl -X POST -H "content-type:application/json" http://192.168.0.7:8080/jsonrpc -d \'{"jsonrpc":"2.0","id":1,"method":"Input.Back"}\'')
end
In the plugin “Params” I did enter in the IP of the Kodi PC.
And also on the “Variables” tab I changed the port number from 80 to 8080
So not sure why its not working when using the " … ipAddress … " and where it’s meant to be getting that IP address from etc.
Looking at the log on the Vera controller I see this:
08 08/24/23 14:00:34.813 JobHandler_LuaUPnP::HandleActionRequest device: 174 service: urn:upnp-org:serviceId:KODIRemote1 action: KODIBack <0x6c588520>
08 08/24/23 14:00:34.813 JobHandler_LuaUPnP::HandleActionRequest argument DeviceNum=174 <0x6c588520>
08 08/24/23 14:00:34.814 JobHandler_LuaUPnP::HandleActionRequest argument serviceId=urn:upnp-org:serviceId:KODIRemote1 <0x6c588520>
08 08/24/23 14:00:34.814 JobHandler_LuaUPnP::HandleActionRequest argument action=KODIBack <0x6c588520>
02 08/24/23 14:00:34.850 JobHandler_LuaUPnP::ConfirmReturnArguments missing KODIBack <0x6c588520>
I tried adding in more quotes " but this didn’t seem to work either, as nothing happens when I press the “Back” button.
os.execute('curl -X POST -H "content-type:application/json" "http://" .. ipAddress .. ":8080/jsonrpc -d \'{"jsonrpc":"2.0","id":1,"method":"Input.Back"}"\'')
I see the same message in the log file:
08 08/24/23 14:18:36.322 JobHandler_LuaUPnP::HandleActionRequest device: 174 service: urn:upnp-org:serviceId:KODIRemote1 action: KODIBack <0x6fbbe520>
08 08/24/23 14:18:36.322 JobHandler_LuaUPnP::HandleActionRequest argument DeviceNum=174 <0x6fbbe520>
08 08/24/23 14:18:36.322 JobHandler_LuaUPnP::HandleActionRequest argument serviceId=urn:upnp-org:serviceId:KODIRemote1 <0x6fbbe520>
08 08/24/23 14:18:36.323 JobHandler_LuaUPnP::HandleActionRequest argument action=KODIBack <0x6fbbe520>
02 08/24/23 14:18:36.416 JobHandler_LuaUPnP::ConfirmReturnArguments missing KODIBack <0x6fbbe520>
Here is the entire plugin file if someone with better coding skills wants to figure it out:
<?xml version="1.0"?>
<implementation>
<functions>
local ipAddress
local port
local serviceid = "urn:upnp-org:serviceId:KODIRemote1"
local deviceid = lul_device
local endecoder = require("akb-json");
local RENDERINGCONTROL_SID = 'urn:upnp-org:serviceId:RenderingControl'
local AVTRANSPORT_SID = 'urn:upnp-org:serviceId:AVTransport'
local DEBUG_MODE = false
local function log(stuff, level)
luup.log("KODI State: " .. stuff, (level or 50))
end
local function debug(stuff)
if (DEBUG_MODE) then
log("debug " .. stuff, 1)
end
end
function getport (lul_device)
local getports = luup.variable_get(serviceid,"Port", lul_device)
return getports
end
function isup ()
pingcommand = "ping -c 1 " ..ipAddress
pingresponse = os.execute(pingcommand)
if (pingresponse == 0) then
luup.variable_set(serviceid,"PingStatus","up",lul_device)
debug("KODIRemote is UP!")
else
luup.variable_set(serviceid,"PingStatus","down",lul_device)
luup.variable_set(serviceid,"PlayerStatus","--",lul_device)
luup.variable_set(serviceid,"IdleTime","--",lul_device)
debug("KODIRemote is DOWN!")
end
PingInterval = luup.variable_get(serviceid,"PingInterval", lul_device)
luup.call_timer("isup", 1, PingInterval, "", "")
end
function init(lul_device)
ipAddress = luup.devices[lul_device].ip
if (ipAddress == nil or ipAddress == "") then
return false, "IP Address is required in Device's Advanced Settings!", "KODIRemote"
else
local Port1 = luup.variable_get(serviceid,"Port", lul_device)
if Port1 == nil then
luup.variable_set(serviceid,"Port","80",lul_device)
end
local PingInterval1 = luup.variable_get(serviceid,"PingInterval", lul_device)
if PingInterval1 == nil then
luup.variable_set(serviceid,"PingInterval","180",lul_device)
end
local PingStatus1 = luup.variable_get(serviceid,"PingStatus", lul_device)
if PingStatus1 == nil then
luup.variable_set(serviceid,"PingStatus","--",lul_device)
end
local IdleTime1 = luup.variable_get(serviceid,"IdleTime", lul_device)
if IdleTime1 == nil then
luup.variable_set(serviceid,"IdleTime","--",lul_device)
end
local PlayerStatus1 = luup.variable_get(serviceid,"PlayerStatus", lul_device)
if PlayerStatus1 == nil then
luup.variable_set(serviceid,"PlayerStatus","--",lul_device)
end
isup()
end
end
function send_kodi_home_command ()
durl = "http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Input.Home%22%2c+%22id%22%3a+1%7d"
http = require("socket.http")
local body, code, headers, status = http.request(durl)
end
function send_kodi_back_command ()
durl = "http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Input.Back%22%2c+%22id%22%3a+1%7d"
http = require("socket.http")
local body, code, headers, status = http.request(durl)
end
function send_kodi_info_command ()
durl = "http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Input.Info%22%2c+%22id%22%3a+1%7d"
http = require("socket.http")
local body, code, headers, status = http.request(durl)
end
function send_kodi_select_command ()
durl = "http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Input.Select%22%2c+%22id%22%3a+1%7d"
http = require("socket.http")
local body, code, headers, status = http.request(durl)
end
function send_kodi_up_command ()
durl = "http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Input.Up%22%2c+%22id%22%3a+1%7d"
http = require("socket.http")
local body, code, headers, status = http.request(durl)
end
function send_kodi_down_command ()
durl = "http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Input.Down%22%2c+%22id%22%3a+1%7d"
http = require("socket.http")
local body, code, headers, status = http.request(durl)
end
function send_kodi_right_command ()
durl = "http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Input.Right%22%2c+%22id%22%3a+1%7d"
http = require("socket.http")
local body, code, headers, status = http.request(durl)
end
function send_kodi_left_command ()
durl = "http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Input.Left%22%2c+%22id%22%3a+1%7d"
http = require("socket.http")
local body, code, headers, status = http.request(durl)
end
function send_kodi_play_command ()
local http1 = require("socket.http");
local status1, result1 = luup.inet.wget("http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Player.GetActivePlayers%22%2c+%22id%22%3a+1%7d", 5)
local jsondecoded = endecoder.decode(result1);
local player_id =( jsondecoded['result'][1]['playerid'] );
durl = "http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a%222.0%22%2c%22method%22%3a%22Player.PlayPause%22%2c%22params%22%3a%7b%22playerid%22%3a".. player_id .."%2c%22play%22%3atrue%7d%2c%22id%22%3a1%7d";
http2 = require("socket.http");
local body, code, headers, status2 = http2.request(durl);
end
function send_kodi_pause_command ()
local http1 = require("socket.http");
local status1, result1 = luup.inet.wget("http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Player.GetActivePlayers%22%2c+%22id%22%3a+1%7d", 5)
local jsondecoded = endecoder.decode(result1);
local player_id =( jsondecoded['result'][1]['playerid'] );
durl = "http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a%222.0%22%2c%22method%22%3a%22Player.PlayPause%22%2c%22params%22%3a%7b%22playerid%22%3a".. player_id .."%2c%22play%22%3afalse%7d%2c%22id%22%3a1%7d";
http2 = require("socket.http");
local body, code, headers, status2 = http2.request(durl);
end
function send_kodi_stop_command ()
local http1 = require("socket.http");
local status1, result1 = luup.inet.wget("http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Player.GetActivePlayers%22%2c+%22id%22%3a+1%7d", 5)
local jsondecoded = endecoder.decode(result1);
local player_id =( jsondecoded['result'][1]['playerid'] );
durl = "http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Player.Stop%22%2c+%22params%22%3a+%7b+%22playerid%22%3a+".. player_id .."+%7d%2c+%22id%22%3a+1%7d";
http2 = require("socket.http");
local body, code, headers, status2 = http2.request(durl);
end
function send_kodi_bigbackward_command ()
local http1 = require("socket.http");
local status1, result1 = luup.inet.wget("http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Player.GetActivePlayers%22%2c+%22id%22%3a+1%7d", 5)
local jsondecoded = endecoder.decode(result1);
local player_id =( jsondecoded['result'][1]['playerid'] );
durl = "http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Player.Seek%22%2c+%22params%22%3a+%7b+%22playerid%22%3a+".. player_id .."%2c+%22value%22%3a+%22bigbackward%22+%7d%2c+%22id%22%3a+1%7d+";
http2 = require("socket.http");
local body, code, headers, status2 = http2.request(durl);
end
function send_kodi_bigforward_command ()
local http1 = require("socket.http");
local status1, result1 = luup.inet.wget("http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Player.GetActivePlayers%22%2c+%22id%22%3a+1%7d", 5)
local jsondecoded = endecoder.decode(result1);
local player_id =( jsondecoded['result'][1]['playerid'] );
durl = "http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Player.Seek%22%2c+%22params%22%3a+%7b+%22playerid%22%3a+".. player_id .."%2c+%22value%22%3a+%22bigforward%22+%7d%2c+%22id%22%3a+1%7d+";
http2 = require("socket.http");
local body, code, headers, status2 = http2.request(durl);
end
function send_kodi_smallbackward_command ()
local http1 = require("socket.http");
local status1, result1 = luup.inet.wget("http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Player.GetActivePlayers%22%2c+%22id%22%3a+1%7d", 5)
local jsondecoded = endecoder.decode(result1);
local player_id =( jsondecoded['result'][1]['playerid'] );
durl = "http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Player.Seek%22%2c+%22params%22%3a+%7b+%22playerid%22%3a+".. player_id .."%2c+%22value%22%3a+%22smallbackward%22+%7d%2c+%22id%22%3a+1%7d+";
http2 = require("socket.http");
local body, code, headers, status2 = http2.request(durl);
end
function send_kodi_smallforward_command ()
local endecoder = require("akb-json");
local http1 = require("socket.http");
local status1, result1 = luup.inet.wget("http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Player.GetActivePlayers%22%2c+%22id%22%3a+1%7d", 5)
local jsondecoded = endecoder.decode(result1);
local player_id =( jsondecoded['result'][1]['playerid'] );
durl = "http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Player.Seek%22%2c+%22params%22%3a+%7b+%22playerid%22%3a+".. player_id .."%2c+%22value%22%3a+%22smallforward%22+%7d%2c+%22id%22%3a+1%7d+";
http2 = require("socket.http");
local body, code, headers, status2 = http2.request(durl);
end
function send_kodi_playpause_command ()
local http1 = require("socket.http");
local status1, result1 = luup.inet.wget("http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Player.GetActivePlayers%22%2c+%22id%22%3a+1%7d", 5)
local jsondecoded = endecoder.decode(result1);
local player_id =( jsondecoded['result'][1]['playerid'] );
durl = "http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Player.PlayPause%22%2c+%22params%22%3a+%7b+%22playerid%22%3a+".. player_id .."+%7d%2c+%22id%22%3a+1%7d+";
http2 = require("socket.http");
local body, code, headers, status2 = http2.request(durl);
end
function send_kodi_mute_command ()
durl = "http://" .. ipAddress .. ":8080/jsonrpc?request=%7b%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Application.SetMute%22%2c+%22params%22%3a+%7b+%22mute%22%3a+%22toggle%22%7d%2c+%22id%22%3a+1%7d"
http = require("socket.http")
local body, code, headers, status = http.request(durl)
end
function send_kodi_setfullscreen_command ()
local status1, result1 = luup.inet.wget("http://" .. ipAddress .. ":8080/jsonrpc?request=%7b+%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22GUI.SetFullscreen%22%2c+%22params%22%3a+%7b+%22fullscreen%22%3a+true+%7d%2c%22id%22%3a0%7d", 5)
end
function send_kodi_setVolume_command (cmd)
local status1, result1 = luup.inet.wget("http://" .. ipAddress .. ":8080/jsonrpc?request=%7b+%22jsonrpc%22%3a+%222.0%22%2c+%22method%22%3a+%22Application.SetVolume%22%2c+%22params%22%3a+%7b+%22volume%22%3a+" .. cmd .. "+%7d%2c+%22id%22%3a+1+%7d", 5)
end
</functions>
<startup>init</startup>
<actionList>
<action>
<serviceId>urn:upnp-org:serviceId:KODI1</serviceId>
<name>GetPlayerStatus</name>
<run>
luup.variable_get(serviceid, "PlayerStatus", lul_device)
</run>
</action>
<action>
<serviceId>urn:upnp-org:serviceId:KODI1</serviceId>
<name>SetPlayerStatus</name>
<run>
luup.variable_set(serviceid, "PlayerStatus", lul_settings.newPlayerStatus, lul_device)
</run>
</action>
<action>
<serviceId>urn:upnp-org:serviceId:KODIRemote1</serviceId>
<name>KODIHome</name>
<run>
send_kodi_home_command ()
</run>
</action>
<action>
<serviceId>urn:upnp-org:serviceId:KODIRemote1</serviceId>
<name>KODIBack</name>
<run>
send_kodi_back_command ()
</run>
</action>
<action>
<serviceId>urn:upnp-org:serviceId:KODIRemote1</serviceId>
<name>KODIInfo</name>
<run>
send_kodi_info_command ()
</run>
</action>
<action>
<serviceId>urn:upnp-org:serviceId:KODIRemote1</serviceId>
<name>KODISelect</name>
<run>
send_kodi_select_command ()
</run>
</action>
<action>
<serviceId>urn:upnp-org:serviceId:KODIRemote1</serviceId>
<name>KODIUp</name>
<run>
send_kodi_up_command ()
</run>
</action>
<action>
<serviceId>urn:upnp-org:serviceId:KODIRemote1</serviceId>
<name>KODIDown</name>
<run>
send_kodi_down_command ()
</run>
</action>
<action>
<serviceId>urn:upnp-org:serviceId:KODIRemote1</serviceId>
<name>KODIRight</name>
<run>
send_kodi_right_command ()
</run>
</action>
<action>
<serviceId>urn:upnp-org:serviceId:KODIRemote1</serviceId>
<name>KODILeft</name>
<run>
send_kodi_left_command ()
</run>
</action>
<action>
<serviceId>urn:upnp-org:serviceId:AVTransport</serviceId>
<name>Play</name>
<run>
send_kodi_play_command ()
</run>
</action>
<action>
<serviceId>urn:upnp-org:serviceId:AVTransport</serviceId>
<name>Pause</name>
<run>
send_kodi_pause_command ()
</run>
</action>
<action>
<serviceId>urn:upnp-org:serviceId:AVTransport</serviceId>
<name>Stop</name>
<run>
send_kodi_stop_command ()
</run>
</action>
<action>
<serviceId>urn:upnp-org:serviceId:RenderingControl</serviceId>
<name>SetVolume</name>
<run>
send_kodi_setVolume_command (lul_settings.DesiredVolume)
</run>
</action>
<action>
<serviceId>urn:upnp-org:serviceId:KODIRemote1</serviceId>
<name>KODIPlaypause</name>
<run>
send_kodi_playpause_command ()
</run>
</action>
<action>
<serviceId>urn:upnp-org:serviceId:KODIRemote1</serviceId>
<name>KODIMute</name>
<run>
send_kodi_mute_command ()
</run>
</action>
<action>
<serviceId>urn:upnp-org:serviceId:KODIRemote1</serviceId>
<name>KODISmallbackward</name>
<run>
send_kodi_smallbackward_command ()
</run>
</action>
<action>
<serviceId>urn:upnp-org:serviceId:KODIRemote1</serviceId>
<name>KODISmallforward</name>
<run>
send_kodi_smallforward_command ()
</run>
</action>
<action>
<serviceId>urn:upnp-org:serviceId:KODIRemote1</serviceId>
<name>KODIBigbackward</name>
<run>
send_kodi_bigbackward_command ()
</run>
</action>
<action>
<serviceId>urn:upnp-org:serviceId:KODIRemote1</serviceId>
<name>KODIBigforward</name>
<run>
send_kodi_bigforward_command ()
</run>
</action>
<action>
<serviceId>urn:upnp-org:serviceId:KODIRemote1</serviceId>
<name>KODISetfullscreen</name>
<run>
send_kodi_setfullscreen_command ()
</run>
</action>
</actionList>
</implementation>
I think lines 46 and 47 get the IP address
function init(lul_device)
ipAddress = luup.devices[lul_device].ip
The “function isup” must be working as it does says “down” when the PC is off and “up” when the PC is on.
EDIT:
Maybe that message “JobHandler_LuaUPnP::ConfirmReturnArguments missing KODIBack” in the log is a red herring. as I see the same thing when I put in the actual IP address in the curl command and the back button then works.
But I can’t figure out how to get it working with the " … ipAddress … " instead.