robathome

Basic miner remote console

Oct 27th, 2025
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. -- remote_console.lua (CC:Tweaked)
  2. -- Advanced wireless computer. Mirrors turtle logs and sends basic controls.
  3. -- Keys: [P]=pause [R]=resume [S]=stop [Q]=quit viewer
  4.  
  5. local PROTO = "tmine.v1"
  6.  
  7. local function openAnyModem()
  8. for _,side in ipairs(rs.getSides()) do
  9. if peripheral.getType(side) == "modem" then
  10. local m = peripheral.wrap(side)
  11. if m and m.isWireless and m.isWireless() then
  12. rednet.open(side)
  13. return true
  14. end
  15. end
  16. end
  17. return false
  18. end
  19.  
  20. assert(openAnyModem(), "No wireless modem found/opened")
  21.  
  22. local filterID = nil
  23. term.clear(); term.setCursorPos(1,1)
  24. print("Turtle Log Console")
  25. print("Optional: enter a Turtle computer ID to filter, or press Enter:")
  26. local line = read()
  27. if line and line:match("%d+") then filterID = tonumber(line) end
  28. term.clear(); term.setCursorPos(1,1)
  29. print("Listening for logs... [P]=pause [R]=resume [S]=stop [Q]=quit")
  30.  
  31. local function sendCmd(cmd)
  32. rednet.broadcast({cmd=cmd}, PROTO)
  33. end
  34.  
  35. local function keyTask()
  36. while true do
  37. local e, key = os.pullEvent("key")
  38. if key == keys.p then sendCmd("pause")
  39. elseif key == keys.r then sendCmd("resume")
  40. elseif key == keys.s then sendCmd("stop")
  41. elseif key == keys.q then break
  42. end
  43. end
  44. end
  45.  
  46. local function logTask()
  47. while true do
  48. local _, sender, payload, proto = os.pullEvent("rednet_message")
  49. if proto == PROTO and type(payload)=="table" and payload.msg then
  50. if not filterID or filterID == payload.id then
  51. local ts = os.date("!%H:%M:%S", math.floor((payload.t or 0)/1000))
  52. print(("[%s] #%s: %s"):format(ts, tostring(payload.id or "?"), payload.msg))
  53. end
  54. end
  55. end
  56. end
  57.  
  58. parallel.waitForAny(keyTask, logTask)
  59. print("Console closed.")
  60.  
Advertisement
Add Comment
Please, Sign In to add comment