Untitled
unknown
plain_text
2 years ago
1.8 kB
7
Indexable
-- Define initial configuration
local ipAddress = "192.168.1.100" -- Default IP address
local port = 23 -- Default port
local telnetSocket
local timer
-- Function to establish a telnet connection
function connectTelnet()
telnetSocket = TcpSocket.New()
telnetSocket:Connect(ipAddress, port)
telnetSocket.Data = function(socket, data) print(data) end -- Optional: Handle incoming data
telnetSocket.Connected = function(socket) sendAuthentication() end
end
-- Function to send authentication string
function sendAuthentication()
telnetSocket:Write("login netio netio\r\n")
end
-- Function to send command
function sendCommand(cmd)
if telnetSocket and telnetSocket:IsConnected() then
telnetSocket:Write(cmd .. "\r\n")
end
end
-- ScreenUp and ScreenDown button handlers
function ScreenUp()
sendCommand("port 1 1")
if timer then timer:Cancel() end
timer = Timer.New()
timer.Timeout = function()
sendCommand("port 1 0")
Timer.CallAfter(function() sendCommand("port 2 0") end, 2) -- Send "port 2 0" after 2 seconds
end
timer:Start(30) -- Set for 30 seconds
end
function ScreenDown()
sendCommand("port 2 1")
if timer then timer:Cancel() end
timer = Timer.New()
timer.Timeout = function()
sendCommand("port 1 0")
Timer.CallAfter(function() sendCommand("port 2 0") end, 2) -- Send "port 2 0" after 2 seconds
end
timer:Start(30) -- Set for 30 seconds
end
-- Function to update IP address and port from UI
function updateConnectionParameters(ip, portNum)
ipAddress = ip
port = portNum
if telnetSocket then
telnetSocket:Disconnect()
end
connectTelnet()
end
-- Initial connection
connectTelnet()
Editor is loading...
Leave a Comment