Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ccomp=4 -- Controlling computer
- local modempos="left" -- Modem placement
- local senspos="right" -- Sensor placement
- local tankpos="-1,1,-1" -- Tank placement, relative to sensor
- local reqstring="DREQ" -- Data request string
- local dbgr=false -- Debug mode
- local version="1.7" -- Version number, as string in case of finer point releases
- print ("Remote Fluid Sensor v"..version.."\nBy Shurhaian\n")
- os.loadAPI("ocs/apis/sensor") -- Load the sensors API
- if dbgr then
- print ("Debug mode active\nSensors API loaded")
- sleep (0.5)
- end
- tank=sensor.wrap(senspos) -- ...and the tank sensor
- if dbgr then
- print ("Sensor wrapped")
- sleep (0.5)
- end
- rednet.open(modempos) -- Open Rednet
- if dbgr then
- print ("Channel open")
- sleep (0.5)
- end
- local compID=os.getComputerID()
- print ("Modem position: "..modempos.."\nSensor position: "..senspos.."\nTank location: "..tankpos.."\n")
- print ("Controlling computer: #"..ccomp.."\nRunning on computer: #"..compID.."\n")
- local tankrep=nil -- Tank details
- local fluid=0 -- Fluid amount, declared in advance
- if dbgr then
- print ("Fetching tank details...\n")
- tankrep=tank.getTargetDetails(tankpos)
- print ("Details:\n-----\n"..textutils.serialize(tankrep).."\n-----")
- fluid=tankrep.Tanks[1].Amount
- print ("fluid amount: "..fluid)
- else
- print ("Now active and listening...")
- end
- while not dbgr do
- message,id=myNet.receive()
- if id==ccomp and message==reqstring then
- tankrep=tank.getTargetDetails(tankpos)
- fluid=tankrep.Tanks[1].Amount
- myNet.send(fluid,ccomp)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement