Posts: 23
Threads: 7
Joined: Aug 2017
Reputation:
0
Hi control is working but I am get respond with timeout. why?
Command function:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
function tcp_oppo (
data ,
ip ,
port )
local sock =
require (
'socket' ).
tcp ()
sock :
settimeout (
3 )
local res ,
err =
sock :
connect (
ip ,
port or 23 )
if res then
res ,
err =
sock :
send (
'#' ..
data ..
'\r' )
if res then
res ,
err =
sock :
receive (
'*a' )
else
alert (
'send failed: ' ..
tostring (
err ))
end
else
alert (
'connect failed: ' ..
tostring (
err ))
end
sock :
close ()
return res ,
err
end Event:
Code:
1 2 3 4 5 6
ip =
'192.168.11.105'
if (
event.getvalue () ==
true )
then
res ,
err =
tcp_oppo (
'POW' ,
ip )
end
log (
res ,
err )
Manual
Posts: 8106
Threads: 43
Joined: Jun 2015
Reputation:
471
Try adding a new line character when sending:
Code:
1
res ,
err =
sock :
send (
'#' ..
data ..
'\r\n' )
Posts: 23
Threads: 7
Joined: Aug 2017
Reputation:
0
(04.12.2018, 13:45) admin Wrote: Try adding a new line character when sending:
Code:
1
res ,
err =
sock :
send (
'#' ..
data ..
'\r\n' )
Nop it`s not hellp in logs I got the same:
Code:
1 2 3 4 5
Event for Test 2 (
32 /
5 /
1 )
04.12.2018 16 :
36 :
21
*
arg :
1
*
nil
*
arg :
2
*
string :
timeout
Posts: 8106
Threads: 43
Joined: Jun 2015
Reputation:
471
The remote host probably is not closing the socket after command that's why receive all (*a) is not working. You can get partial response like this:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
function tcp_oppo (
data ,
ip ,
port )
local sock =
require (
'socket' ).
tcp ()
sock :
settimeout (
3 )
local res ,
err =
sock :
connect (
ip ,
port or 23 )
if res then
res ,
err =
sock :
send (
'#' ..
data ..
'\r' )
if res then
res ,
err ,
partial =
sock :
receive (
'*a' )
else
alert (
'send failed: ' ..
tostring (
err ))
end
else
alert (
'connect failed: ' ..
tostring (
err ))
end
sock :
close ()
return res ,
err ,
partial
end
ip =
'192.168.11.105'
if (
event.getvalue () ==
true )
then
res ,
err ,
partial =
tcp_oppo (
'POW' ,
ip )
end
log (
res ,
err ,
partial )
Posts: 23
Threads: 7
Joined: Aug 2017
Reputation:
0
(04.12.2018, 14:45) admin Wrote: The remote host probably is not closing the socket after command that's why receive all (*a) is not working. You can get partial response like this:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
function tcp_oppo (
data ,
ip ,
port )
local sock =
require (
'socket' ).
tcp ()
sock :
settimeout (
3 )
local res ,
err =
sock :
connect (
ip ,
port or 23 )
if res then
res ,
err =
sock :
send (
'#' ..
data ..
'\r' )
if res then
res ,
err ,
partial =
sock :
receive (
'*a' )
else
alert (
'send failed: ' ..
tostring (
err ))
end
else
alert (
'connect failed: ' ..
tostring (
err ))
end
sock :
close ()
return res ,
err ,
partial
end
ip =
'192.168.11.105'
if (
event.getvalue () ==
true )
then
res ,
err ,
partial =
tcp_oppo (
'POW' ,
ip )
end
log (
res ,
err ,
partial )
Thanks admin its working I get 'partial'
How you think how to do to get status of device power when device will be turn on over remote that LM will know of Player status.
Posts: 8106
Threads: 43
Joined: Jun 2015
Reputation:
471
Upgrade LuaSocket package via System config > System > Packages:
https://dl.openrb.com/lm-18-imx6/pkg/lua...1_imx6.ipk
Then replace receive part with:
Code:
1
res ,
err ,
partial =
sock :
receive (
'*r' )
Posts: 23
Threads: 7
Joined: Aug 2017
Reputation:
0
(05.12.2018, 08:32) admin Wrote: Upgrade LuaSocket package via System config > System > Packages:
https://dl.openrb.com/lm-18-imx6/pkg/lua...1_imx6.ipk
Then replace receive part with:
Code:
1
res ,
err ,
partial =
sock :
receive (
'*r' )
OK that working now I get sting in res.
How do that I get status of player in KNX objekt about power status. I mean that sometime can be that player will be turn on from original remote control I need to know.
Thanks.
Posts: 8106
Threads: 43
Joined: Jun 2015
Reputation:
471
You need to send QPW command then parse the result and update status object if needed. You will need a separate resident script for that. Make sure that you don't use one object for both control and status, otherwise you can get an infinite script loop.