Advertisement
osmarks

OC Remote Wake

May 22nd, 2020 (edited)
1,523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.82 KB | None | 0 0
  1. local wlan = component.proxy(component.list "modem"())
  2. local computer_peripheral = component.proxy(component.list "computer"())
  3. wlan.setWakeMessage("poweron", true)
  4.  
  5. local function sleep(timeout)
  6.     local deadline = computer.uptime() + (timeout or 0)
  7.     repeat
  8.         computer.pullSignal(deadline - computer.uptime())
  9.     until computer.uptime() >= deadline
  10. end
  11.  
  12. local function try_power_on(comp)
  13.     local p = component.proxy(comp)
  14.     if p.isOn and p.turnOn then
  15.         if not p.isOn() then
  16.             p.turnOn()
  17.             computer_peripheral.beep(440)
  18.         end
  19.     end
  20.     if p.isRunning and p.start then
  21.         if not p.isRunning() then
  22.             p.start()
  23.             computer_peripheral.beep(800)
  24.         end
  25.     end
  26. end
  27.  
  28. while true do
  29.     for addr in component.list "turtle" do try_power_on(addr) end
  30.     for addr in component.list "computer" do try_power_on(addr) end
  31.     sleep(1)
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement