Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- startup.lua (GPS node with hard-coded coords; CC:Tweaked)
- -- Edit these:
- local X, Y, Z = 100.0, 72.0, -340.0
- local function findWirelessModem()
- return peripheral.find("modem", function(_, p) return p.isWireless() end)
- end
- term.clear(); term.setCursorPos(1,1)
- print(("GPS node @ (%.3f, %.3f, %.3f)"):format(X,Y,Z))
- local modem = findWirelessModem()
- if not modem then error("No wireless modem") end
- local modemName = peripheral.getName(modem)
- rednet.open(modemName)
- -- Try to advertise on the "gps" service (optional). Ignore errors if unavailable.
- pcall(function() rednet.host("gps", "gps_"..os.getComputerID()) end)
- print("Wireless open on "..modemName..". Serving replies on protocol 'gps'.")
- -- Minimal GPS responder. Replies with {x=,y=,z=} to any 'gps' request.
- while true do
- local senderId, msg, proto = rednet.receive("gps", 5)
- if senderId then
- rednet.send(senderId, { x = X, y = Y, z = Z }, "gps")
- end
- -- heartbeat
- term.setCursorPos(1,4)
- term.setTextColor(colors.lightGray)
- print("Last tick: "..textutils.formatTime(os.time(), true).." ")
- term.setTextColor(colors.white)
- end
Advertisement
Add Comment
Please, Sign In to add comment