PDA

View Full Version : OT: LUA question



yonu
November 29th, 2013, 12:37 AM
I figure since girder uses Lua this may be a good place to ask this question I am attempting to write a lua script to control a Video Conferencing system script via telnet however I am having some problems with the Luasocket code as it keeps locking up the lua engine on my linux box for about 2 min until it decides to return the data if I use a telnet client it is displayed in the client in aboot 2 sec.

here is the code I have so far

local socket = require("socket")
client = socket.connect("192.168.2.5", 23)
client:send("password\n")
while true do
s, status, partial = client:receive(1024)
print(s or partial)
if status == "closed" then
break
end
end
client:close()

Thanks,
Yonu

Ron
November 29th, 2013, 08:01 AM
By the looks of it. Lua Socket is waiting for 1024 bytes or a timeout in the receive call. Maybe you should change that a bit.

http://w3.impa.br/~diego/software/luasocket/tcp.html

If the answer has an endline termination you could use client:receive("*l")

yonu
November 29th, 2013, 10:18 AM
thanks I didn't realize the 1024 was a byte count as it was in every example I could fine as to a terminator the first line doesn't as it stops and waits for a password

thanks,
Yonu

yonu
November 29th, 2013, 10:20 AM
thanks that is perfect now to coad all the controls if I could get the company to just replace the old hardware controller that went out this would be easier :0

yonu

Ron
November 29th, 2013, 10:21 AM
Excellent!

yonu
November 29th, 2013, 10:24 AM
It always seems to be the stupidiest thing that mess-up code :)

yonu

Ron
November 29th, 2013, 10:26 AM
Oh I can fully sympathize...

yonu
January 10th, 2014, 11:35 PM
Hey I hate to ask but you helped me on the first rendition of the code and it works fine but I am trying to do some nested if to check if the mics are on before sending the command however it keeps locking up lua rather I use straight Lua or put it in a scripting action. sorry for the loopback ip but didn't want to post a fully public ip to the net
Thanks,
Yonu


function micoff()
local socket = require("socket")
client = socket.connect("127.0.0.1", 23)
client:send("TANDBERG\n")
client:send("mic\n")
--client:send("exit\n")
while true do
s, status, partial = client:receive("*l")
if status == "*P mic off" or "*P mic on" then
if status == "*P mic off" then
client:send("mic on\n")
print ("if on")
client:send("exit\n")
client:close()
else
if status == "*P mic on" then
client:send("mic off\n")
print ("if off")
client:send("exit\n")
client:close()
end
end
else
--client:send("exit\n")
end
print(s or partial)
--gir.TriggerEvent(s,18,1)
if status == "closed" then
client:close()
break
end
end
end