Dukrobber

Reactor information wireless [Server]

Oct 14th, 2014
1,565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.26 KB | None | 0 0
  1. local function openRednet()
  2. local listOfSides = rs.getSides()
  3. local listofPossibles = {}
  4. local counter1 = 0
  5. while true do
  6.   counter1 = counter1 +1
  7.  
  8.   if peripheral.isPresent(tostring(listOfSides[counter1])) and peripheral.getType(listOfSides[counter1]) == "modem" then
  9.    table.insert(listofPossibles,tostring(listOfSides[counter1]))
  10.   end
  11.  
  12.   if counter1 == 6 and table.maxn(listofPossibles) == 0 then
  13.    print("no wifi present")
  14.    return nil
  15.   end
  16.  
  17.   if counter1 == 6 and table.maxn(listofPossibles) ~= 0 then
  18.    rednet.open(listofPossibles[1])
  19.    return listofPossibles[1]
  20.   end
  21. end
  22. end
  23. modemOn = openRednet()
  24. if modemOn == nil then
  25. print("No Modem")
  26. print("Will shutdown in 3 seconds")
  27. sleep(3)
  28. os.shutdown()
  29. else
  30. print("Opened modem on "..modemOn.." side")
  31. end
  32.  
  33. id, message = rednet.receive()
  34. term.setCursorPos(1,1)
  35. print ("Device " .. id .. " sent a " .. message .. " ")
  36. os.sleep(1)
  37. term.setCursorPos(1,2)
  38. print ("Sending reactor info...")
  39. local reactor
  40.    reactor = peripheral.wrap("back")
  41.    if peripheral.wrap("back") then
  42.    term.setCursorPos(1,3)
  43.    print ("Found Reactor")
  44.    end
  45.    active = reactor.getActive(1)
  46.    if active then
  47.    term.setCursorPos(1,5)
  48.    print ("The Reactor is: ")
  49.    term.setTextColor(colors.green)
  50.    print ("ON")
  51.    else term.setTextColor(colors.white)
  52.    print ("The Reactor is: ")
  53.    term.setTextColor(colors.red)
  54.    print ("OFF")
  55.    rednet.send(15, "The Reactor is: OFF")
  56.    os.reboot()
  57.    end
  58.    term.setTextColor(colors.white)
  59.    lvl = reactor.getControlRodLevel(1)
  60.    if lvl then
  61.    print ("Control rod level is " .. lvl .. "% closed")
  62.    end
  63.    tick = reactor.getEnergyProducedLastTick(1)
  64.    if tick then
  65.    print (" " .. tick .. " RF/t ")
  66.    end
  67. rednet.send(15, "The Reactor is: ON")
  68. os.sleep(1)
  69. rednet.send(15, "Control rod level is " .. lvl .. "% closed")
  70. os.sleep(1)
  71. rednet.send(15, " " .. tick .. " RF/t ")
  72. os.reboot()
  73.  
  74. -- This is some simple code i made to get information about a Big Reactor wireless using a Pocket computer.
  75. -- Place a computer with a wireless modem on the left side and the Computercraft Big Reactor port right behind it.
  76. -- UPDATE! you need to input the right computer IDs in both programs respectivly
  77. -- The Pocket computer program is at /bkc8M1Bi
  78. -- Made by Dukrobber
Advertisement
Add Comment
Please, Sign In to add comment