robathome

RoboMiner_gps

Oct 18th, 2025 (edited)
693
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. -- startup.lua (GPS node with hard-coded coords; CC:Tweaked)
  2. -- Edit these:
  3. local X, Y, Z = 100.0, 72.0, -340.0
  4.  
  5. local function findWirelessModem()
  6. return peripheral.find("modem", function(_, p) return p.isWireless() end)
  7. end
  8.  
  9. term.clear(); term.setCursorPos(1,1)
  10. print(("GPS node @ (%.3f, %.3f, %.3f)"):format(X,Y,Z))
  11.  
  12. local modem = findWirelessModem()
  13. if not modem then error("No wireless modem") end
  14. local modemName = peripheral.getName(modem)
  15. rednet.open(modemName)
  16.  
  17. -- Try to advertise on the "gps" service (optional). Ignore errors if unavailable.
  18. pcall(function() rednet.host("gps", "gps_"..os.getComputerID()) end)
  19.  
  20. print("Wireless open on "..modemName..". Serving replies on protocol 'gps'.")
  21.  
  22. -- Minimal GPS responder. Replies with {x=,y=,z=} to any 'gps' request.
  23. while true do
  24. local senderId, msg, proto = rednet.receive("gps", 5)
  25. if senderId then
  26. rednet.send(senderId, { x = X, y = Y, z = Z }, "gps")
  27. end
  28. -- heartbeat
  29. term.setCursorPos(1,4)
  30. term.setTextColor(colors.lightGray)
  31. print("Last tick: "..textutils.formatTime(os.time(), true).." ")
  32. term.setTextColor(colors.white)
  33. end
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment