Posted 19 April 2014 - 06:10 PM
Just showing a program I made to use the new Protocol system.
This works in three parts: A Master Control Computer, DoorLock computers, and a PDA for remote control.
MCC Code:
DoorLock Code (Used in three different computers but each is just a clone of the original with new ID)
PDA code:
Just set the first two on startup and the third as whatever program name you want.
This works in three parts: A Master Control Computer, DoorLock computers, and a PDA for remote control.
MCC Code:
rednet.open("top")
rednet.host("Security", "MCC")
while true do
local ID, command, protocol = rednet.receive()
if protocol == "Security" then
if command == "Back Open" then
rednet.send(11, "Open", "Security")
rednet.send(ID, "Clear.")
elseif command == "Front Open" then
rednet.send(13, "Open", "Security")
rednet.send(14, "Open", "Security")
rednet.send(ID, "Clear.")
elseif command == "Lockdown" then
rednet.send(11, "Lock", "Security")
rednet.send(13, "Lock", "Security")
rednet.send(14, "Lock", "Security")
rednet.send(ID, "Lockdown in effect.")
else
sleep(0.5)
rednet.send(ID, "Invalid Command.")
end
else
sleep(0.5)
rednet.send(ID, "Invalid Code.")
end
end
DoorLock Code (Used in three different computers but each is just a clone of the original with new ID)
rednet.open("back")
rednet.host("Security", "BackDoor")
while true do
local ID, command, protocol = rednet.receive()
if ID == 12 and protocol == "Security" then
if command == "Open" then
rs.setOutput("top", false)
elseif command == "Lock" then
rs.setOutput("top", true)
end
else
rednet.send(ID, "Incorrect ID or Code")
end
end
PDA code:
rednet.open("back")
print("Input Command:")
local command = read()
print("Input code:")
local security = read("*")
rednet.send(12, command, security)
local ID,ReturnVal = rednet.receive()
print(ReturnVal)
sleep(1)
term.clear()
term.setCursorPos(1,1)
Just set the first two on startup and the third as whatever program name you want.