24.04.2016, 19:44
I am one step further, but not there yet
- communication works, but command is probably not correct because I get a weird response
my user script
my trigger script
the response that I get for all commands
- communication works, but command is probably not correct because I get a weird response
my user script
Code:
--------------------------------------
-- Author: Nicky Wessels
-- Last Modified: 24/04/2016
--
-- Change Log:
-- 24/04/2016 Intial Version
--------------------------------------
-- IP of the projector
PROJECTOR_IP = '192.168.0.20'
PROJECTOR_PORT = '53484'
-- Power ON
-- 'h01 h00 hA9 h17 h2F h00 h00 h00 h3F h9A'
SONYPJ_CMD_ON = string.char(0x01, 0x00, 0xA9, 0x17, 0x2F, 0x00, 0x00, 0x00, 0x3F, 0x9A)
-- Power Off
-- 'h01 h00 hA9 h17 h2E h00 h00 h00 h3F h9A'
SONYPJ_CMD_OFF = string.char(0x01, 0x00, 0xA9, 0x17, 0x2E, 0x00, 0x00, 0x00, 0x3F, 0x9A)
-- change input s-video
-- 'h01 h00 ha9 h00 h01 h00 h00 h01 h01 h9a'
SONYPJ_SET_SVIDEO = string.char(0x01, 0x00, 0xA9, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x9A)
-- funtion to send basic commands to the receiver
function sonypj_send_cmd(cmd, ip, port)
require 'socket.http'
response_tbl = { }
-- fill up optional parameters
if (ip == nil) then
ip = PROJECTOR_IP
end
if (port == nil) then
port = PROJECTOR_PORT
end
response_tbl['ip']=ip
response_tbl['port']=port
response_tbl['cmd']=cmd
-- Send command to projector
sock = socket.tcp()
sock:settimeout(3)
result, err = sock:connect(ip, port)
response_tbl['result']=result
if result then
result, err = sock:send(cmd)
response_tbl['result']=result
response_tbl['error']=error
-- Check response from projector
if result then
alert('send OK')
else
alert('send failed: ' .. tostring(err), response_tbl)
end
else
alert('connect failed: ' .. tostring(err), response_tbl)
end
sock:close()
return response_tbl
end
Code:
require 'user.sony_pjtalk'
-- object mapped to this event must have its data type set
bStatus = event.getvalue()
-- get the status of the projector
if (bStatus) then
status_tbl = sonypj_send_cmd(SONYPJ_CMD_ON)
else
status_tbl = sonypj_send_cmd(SONYPJ_CMD_OFF)
end
log('status',status_tbl)
the response that I get for all commands
Code:
* arg: 2
* table:
[error]
* function: builtin#19
[ip]
* string: 192.168.0.20
[result]
* number: 10
[cmd]
* string: