iteration
This commit is contained in:
38
packages/set_lns.lua
Normal file
38
packages/set_lns.lua
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
io.write("Enter the hostname: ")
|
||||
hostname = io.read()
|
||||
|
||||
io.write("Enter the modem location: ")
|
||||
modem_location = io.read()
|
||||
|
||||
rednet.open(modem_location)
|
||||
receiverID = rednet.lookup("lns", lns_server)
|
||||
current_time = os.time()
|
||||
|
||||
|
||||
data = {
|
||||
["action"] = "register",
|
||||
["hostname"] = hostname,
|
||||
["token"] = settings.get("auth.token", nil)
|
||||
}
|
||||
|
||||
rednet.send(receiverID, data, "lns")
|
||||
|
||||
while true do
|
||||
id, msg = rednet.receive("lns")
|
||||
if id == receiverID then
|
||||
if msg == "ok" then
|
||||
print("Registered with LNS Server Successfully!")
|
||||
break
|
||||
else
|
||||
print("Failed to register with LNS Server! Error: " .. msg)
|
||||
break
|
||||
end
|
||||
|
||||
-- timeout after 5 seconds
|
||||
if os.time() - current_time > 5 then
|
||||
print("Failed to register with LNS Server! Timeout!")
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user