Posts: 215
Threads: 65
Joined: Sep 2015
Reputation:
0
please help me!
Hope everyone has opinions to this problem !
To determine the status of television, we use the TCP protocol. If the TV is on, the status will return to 1, otherwise it will be empty:
sock = socket.tcp ()
sock: setTimeout (1)
status = sock: connect ('100.100.100.92', 55000)
if status == 1 then --- Tivi on
....v...v....
But there are some television via TCP is impossible. turn off the TV when the status remains 1.
In this case, the TCP protocol can not be used anymore. If anyone has encountered this case (Sony TV) and there are workarounds, please help me.
I am very thankful.!
Posts: 1764
Threads: 6
Joined: Jul 2015
Reputation:
117
Hi,
When NIC is turned off in stand-by we use a chromecast in a HDMI port
and we send a command to the device that causes the tv to turn on again.
From there you can use normal NIC again (:
This is a € 35,- solution
BR,
Erwin van der Zwart
Posts: 215
Threads: 65
Joined: Sep 2015
Reputation:
0
(14.07.2016, 17:02)Erwin van der Zwart Wrote: Hi,
When NIC is turned off in stand-by we use a chromecast in a HDMI port
and we send a command to the device that causes the tv to turn on again.
From there you can use normal NIC again (:
This is a € 35,- solution
BR,
Erwin van der Zwart
==============================================
I mean, when the TV is in standby mode (or sleep), the NIC still on (value 1) I want NIC = 0. from which we determine when to turn on the tv (tv on the NIC = 1).
"We use a HDMI port in a chromecast", you can specify how to do it? Thank you so much!
Who are somehow via USB, HDMI, UDP, TCP another, which can identify the TV on and off. Can guide me?
Thank so much! everyone!
Posts: 1764
Threads: 6
Joined: Jul 2015
Reputation:
117
21.07.2016, 19:41
(This post was last modified: 21.07.2016, 20:29 by Erwin van der Zwart.)
Hi Phongvucba.
Here is a script example for controlling Chromecast:
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
BR,
Erwin
Posts: 215
Threads: 65
Joined: Sep 2015
Reputation:
0
(21.07.2016, 19:41)Erwin van der Zwart Wrote: Hi Phongvucba.
Here is a script example for controlling Chromecast:
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
BR,
Erwin Thank you very much !
I have the following code, via UDP:
sock = socket.udp ()
sock: setTimeout (1)
status = sock: connect ('192.168.10.10', 5353)
== 1 if status bars --- TV on
--tivi else off
Similar to TCP, the code is correct?
thank so much
Posts: 133
Threads: 28
Joined: May 2016
Reputation:
3
Hi Erwin,
it would be nice if you can post an example for this three commands.
TV Off, TV On and TV State
I've read a little bit about the dial protocol, but I don't want to control apps on the chromecast. I want to integrate this commands written above in my scene/device controls.
Thx4forwards :-)
|