Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local m = peripheral.find "modem"
- local function exec_command(cmd, ...)
- m.transmit(666, 666, { "command", cmd, ... })
- m.open(666)
- local timer = os.startTimer(2)
- while true do
- local e, timer_ID, c, _, msg = os.pullEvent()
- if e == "timer" and timer_ID == timer then
- error("command " .. cmd .. " timed out")
- elseif e == "modem_message" and c == 666 and type(msg) == "table" and msg[2] == cmd then
- if msg[1] == "error" then
- error("remote error from command " .. cmd .. ": " .. msg[3])
- elseif msg[1] == "result" then
- return msg[3]
- end
- end
- end
- end
- local weather = ...
- print("Selected weather:", weather)
- print "Sending command..."
- local res = exec_command("set_weather", weather)
- print("Remote result:", res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement