Advertisement
osmarks

Weather Control System Control System - Client

Jul 29th, 2019
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.74 KB | None | 0 0
  1. local m = peripheral.find "modem"
  2. local function exec_command(cmd, ...)
  3.     m.transmit(666, 666, { "command", cmd, ... })
  4.     m.open(666)
  5.     local timer = os.startTimer(2)
  6.     while true do
  7.         local e, timer_ID, c, _, msg = os.pullEvent()
  8.         if e == "timer" and timer_ID == timer then
  9.             error("command " .. cmd .. " timed out")
  10.         elseif e == "modem_message" and c == 666 and type(msg) == "table" and msg[2] == cmd then
  11.             if msg[1] == "error" then
  12.                 error("remote error from command " .. cmd .. ": " .. msg[3])
  13.             elseif msg[1] == "result" then
  14.                 return msg[3]
  15.             end
  16.         end
  17.     end
  18. end
  19.  
  20. local weather = ...
  21. print("Selected weather:", weather)
  22. print "Sending command..."
  23. local res = exec_command("set_weather", weather)
  24. print("Remote result:", res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement