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.

Reboot Chromecast
#1
Hi,
I'm struggling with controlling a Chromecast from LM. I'm using  this script provided by Erwin:
Code:
-- ****** Control Chromecast with 1 byte object version 1.0 created by Erwin van der Zwart ******* --
-- **************************************** SET PARAMETERS *************************************** --

-- Chromecast IP address
ip_chromecast = '192.168.10.23'

-- Additional info from browser about
-- http://192.168.10.23:8008/ssdp/device-desc.xml
-- http://192.168.10.23:8008/setup/scan_results
-- http://192.168.10.23:8008/setup/eureka_info?options=detail
-- http://192.168.10.23:8008/setup/supported_timezones
-- http://geeknizer.com/how-chromecast-works-chromecast-protocol-explained/

value = event.getvalue()

require 'socket.http'

function control_chromecast(uri, request)
 local request_body = request
 local response_body = { }
 local res, code, response_headers = socket.http.request
 {
   url = "http://" .. ip_chromecast .. ":8008/" .. uri;
   method = "POST";
   headers =
   {
     ["Content-Type"] = "application/x-www-form-urlencoded";
     ["Content-Length"] = #request_body;
   };
   source = ltn12.source.string(request_body);
   sink = ltn12.sink.table(response_body);
 }
 return res, code, response_headers
end

-- Action on value 1
if value == 1 then
    -- Start Youtube video
    res, code, response_headers = control_chromecast('apps/YouTube', [[v=_iuBO1lkch8]])
end

-- Action on value 2
if value == 2 then
    -- Stop Youtube video
    res, code, response_headers = control_chromecast('apps/YouTube', [[DELETE]])
end

-- Action on value 3
if value == 3 then
    -- Start Chromecast Homescreen
    res, code, response_headers = control_chromecast('apps/ChromeCast', [[]])
end

-- Log results
resulthandling = false

if resulthandling == true then
 -- Handler for results
 log("Status:", res and "OK" or "FAILED")
 log("HTTP code:", code)
 log("Response headers:")
 if type(response_headers) == "table" then
   for k, v in pairs(response_headers) do
     log(k, ":", v)
   end
 else
   -- Would be nil, if there is an error
   log("Not a table:", type(response_headers))
 end
 log("Response body:")
 if type(response_body) == "table" then
   log(table.concat(response_body))
 else
 end
end
Action value 1 and 2 does work. Value 3 gives an error 404 on the tv screen.

From my windows command line I can reboot the chromecast by doing this:
curl -Lv -H Content-Type:application/json http://192.168.22.99:8008/setup/reboot  -d "{""params"":""now""}" 

and start youtube with this:
curl -Lv -H Content-Type:application/json http://192.168.22.99:8008/apps/YouTube -d v=_iuBO1lkch8



I would like to do a reboot and get the homescreen/screensaver running from the LM.

I've added:

Code:
-- Action on value 4
if value == 4 then
 -- Reboot Chromecast
 res, code, response_headers = control_chromecast('setup/reboot', [[{params=now}]] )
end

But the response is 400 bad request (from Wireshark). I've tried changing the parameters to "{""params"":""now""}", [["{""params"":""now""}" ]] and all possible variations in between. I'm out of clue.

Would anyone help me?

Best regards
Bjorn
Reply
#2
I just needed to post here before I saw what I had to do:

This script reboots the Chromecast:

Code:
require'socket.http'
response_body = {}
request_body = [[{"params":"now"}]]
socket.http.request{
 url = "http://192.168.22.99:8008/setup/reboot";
   method = "POST";
   headers = {
   ["Content-Type"] = "application/json";
        ["Content-Length"] = string.len(request_body)
    };
    source = ltn12.source.string(request_body);
    sink = ltn12.sink.table(response_body);
}
 
I still cant force the screensaver back though.
Reply


Forum Jump: