Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- -- Code by minecraft: montana_1
- -- please send comments or questions to [email protected] with a subject I might read
- --
- -- Description of code:
- -- This is a program written for use in minecraft with the mod "OpenComputers"
- -- This is the server side or host code for a single computer or possible micro-controller to broadcast
- -- a signal from a minimum of 4 (possibly more but not tested) access points containing there predetermined
- -- co-ordinates which are entered into the program upon first run and saved in a file for later use.
- -- The co-ordinates can then be determined by a client program from this information
- -- Note:
- -- Because the co-ordinates are calculated by the distance from each access point,
- -- it is very important that all other access points within range are set to NOT REPEAT.
- -- Which by default is ON. If you do not know how to change this, there is another program
- -- on my pastebin account (montana_1) that will first find all access points on a network
- -- and second set there range to zero and turn Repeating OFF. This is good practice with any programs
- -- to turn the access points effectively off when not being immediately used to save power and
- -- prevent errors.
- -- Also Note:
- -- The timings for this program are set so that there are no processors placed within the access points
- ]]--
- function getAccessPoints()
- local component = require("component")
- local event = require("event")
- local t = component.list()
- local accessPoints = {}
- local i = 0
- for address,componentType in pairs(t) do
- if(componentType == "access_point") then
- accessPoints[i] = address
- i = i + 1
- end
- end
- return accessPoints
- end
- function turnOffRepeaters(accessPoints)
- local component = require("component")
- for i=0, #accessPoints do
- print(accessPoints[i])
- component.proxy(accessPoints[i]).setRepeater(false)
- component.proxy(accessPoints[i]).setStrength(0)
- print(component.proxy(accessPoints[i]).isRepeater())
- end
- end
- function split(inputstr, sep)
- if(inputstr == nil or inputstr == "") then
- return nil
- end
- if sep == nil then
- sep = ","
- end
- local t={} ; i=0
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- t[i] = str
- i = i + 1
- end
- return t
- end
- local fileSystem = require("filesystem")
- local accessPoints = getAccessPoints()
- turnOffRepeaters(accessPoints)
- local gps_port = 3665
- local signal_strength = 400
- if(#accessPoints+1 < 4) then
- print("Insuficient access_points, 4 are required you have (".. #accessPoints+1 ..")")
- error()
- end
- local term = require("term")
- local shell = require("shell")
- local component = require("component")
- local hostCoordinates = {}
- if(fileSystem.exists(shell.resolve("gpsHostData"))) then
- local file = io.open(shell.resolve("gpsHostData"), "r")
- local i = 0
- for line in io.lines(shell.resolve("gpsHostData")) do
- hostCoordinates[i] = split(line,",")
- i=i+1
- end
- file:close()
- else
- local file = io.open(shell.resolve("gpsHostData"), "a")
- for i=0, #accessPoints do
- print("Enter coordinates (x,y,z) for access_point: " .. accessPoints[i])
- local tmp = term.read()
- hostCoordinates[i] = split(accessPoints[i]..","..tmp,",")
- file:write(accessPoints[i]..","..tmp)
- end
- file:close()
- end
- component.modem.open(gps_port)
- while true do
- for i=0, #hostCoordinates do
- io.write(i..": "..hostCoordinates[i][0].." "..hostCoordinates[i][1]..","..hostCoordinates[i][2]..","..hostCoordinates[i][3])
- component.setPrimary("access_point",hostCoordinates[i][0])
- print("Primary set")
- component.proxy(hostCoordinates[i][0]).setStrength(signal_strength)
- component.modem.broadcast(gps_port, tonumber(hostCoordinates[i][1]),tonumber(hostCoordinates[i][2]),tonumber(hostCoordinates[i][3]))
- os.sleep(0.25)
- component.getPrimary("access_point").setStrength(0)
- os.sleep(1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement