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.

Check connected tcp ports
#1
Hello

do somebody know:
- how can I check currently connected tcp ports?
- how can I reach the socket which is created and permanent used in resident script via event script?

The solution is necessary for Sony Bravia TV. I must have permanent tcp connection to have ability to read status when TV is off. So for this solution I've prepared the resident script 0s:
Code:
require('socket')

if not sock_bravia then
-- bravia IP
ip = '192.168.2.102'

sock_bravia = socket.tcp()
sock_bravia:settimeout(3)

res, err = sock_bravia:connect(ip, 20060)
end

-- power-status
cmd = '*SEPOWR################\n' -- Check status power

if res then
 res, err = sock_bravia:send(cmd)

 if res then
   res, err = sock_bravia:receive()

   if res then
     log('receive OK: ' .. tostring(res)) -- received ok
   else
     log('receive failed: ' .. tostring(err)) -- receive failed
   end
 else
   log('send failed: ' .. tostring(err)) -- send failed
 end
else
 log('connect failed: ' .. tostring(err)) -- connect failed
end

os.sleep(5)

But sometimes I want send command e.g. switch on but from event-based script. How can I reach currently port from other script?
Reply
#2
Each script is a separate OS process, this means you cannot access other process resources directly. You can create a local UDP server in your resident script which to proxy data from event scripts: https://forum.logicmachine.net/showthrea...15#pid2015

You can get a list of currently open TCP client connections like this:
Code:
clients = io.readproc('netstat -ptn | grep ESTABLISHED')
Reply
#3
What about using storage to send command?
in you resident script you read a table in storage and send all element you read, and in your event script you write all your command

This way you have a FIFO and can send multiple command at a time:
On, switch to channel X, volume Y, ....
Reply
#4
(23.06.2017, 12:27)mlaudren Wrote: What about using storage to send command?
in you resident script you read a table in storage and send all element you read, and in your event script you write all your command

This way you have a FIFO and can send multiple command at a time:
On, switch to channel X, volume Y, ....

I've tested in the past this solution but storage is not so fast as must be.
Reply
#5
(23.06.2017, 14:12)buuuudzik Wrote:
(23.06.2017, 12:27)mlaudren Wrote: What about using storage to send command?
in you resident script you read a table in storage and send all element you read, and in your event script you write all your command

This way you have a FIFO and can send multiple command at a time:
On, switch to channel X, volume Y, ....

I've tested in the past this solution but storage is not so fast as must be.

What speed/ time response do you target? I have some script that use storage and I didn't notice delay during the execution.
I'll do some test to see it that.
Reply
#6
I don't know exactly but this was my subject when I used the storage for such solution:
https://forum.logicmachine.net/showthrea...ight=somfy

In that case I've tried push button to e.g. rotate the slat step by step and Somfy was very slow(~0,6s for sending one command). So when I clicked very fast 3 times then I had a problem also with storage and e.g. Somfy did only 2 steps. I've tested this on LM4 on old processor so I think it could also had some influence. When I've used UDP server for this the problem gone and CPU usage go to minimum level from very high.
Reply
#7
Storage is moved to redis DB so should be much faster then inside older FW.

I would retry your previous tests as i think it's fast enough now.

We used same kind of methode that mlaudren adviced in a TCP connection to Lutron and works pretty good.

BR,

Erwin
Reply
#8
You still have race condition if you do get - change - set, no matter what kind of storage engine is used. You can use Redis list operations (lpush/lpop) which are atomic, but then you will have to poll for list changes where you can use receive with timeout when using UDP.
Reply
#9
Hi,

I have been using this, https://forum.logicmachine.net/showthread.php?tid=842

This way storage is not required to send something from the event based objects. Works well.

Thanks,

Roger
Reply


Forum Jump: