Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local comp = require("component")
- local thread = require("thread")
- local modem = comp.modem
- local port = 1
- local PING = "ping"
- local devices = {}
- local commands = {
- collect = function()
- local collect_thread = thread.create(function()
- print("Collecting devices...")
- modem.broadcast(port, PING)
- while true do
- local _, _, remoteAddress, _, _, payload = event.pull("modem_message")
- table.insert(devices, remoteAddress)
- end
- end)
- os.sleep(5)
- collect_thread:kill()
- end
- }
- while true do
- local input = io.read()
- if input == "quit" or input == "q" then os.exit(0) end
- if commands[input] == nil then
- print("Command not found!")
- else
- pcall(commands[input])
- print()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement