Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- rfidReader by:MRMiller
- Outputs based on RFID card input
- --]]
- local version = "0.5" --Change as needed
- local paste = "sSgdMsNN" --Change to your pastebin
- local programName = "rfidReader " -- change to your proram name
- local isDebug = true --Toggle Debug mode
- local card = {}
- local rfidReader = ""
- local rsSide = "top"
- local event = ""
- local data = ""
- local function update()
- term.clear()
- print("Checking for updates...")
- local response = http.get("http://pastebin.com/raw.php?i="..paste)
- local reply = response.readAll()
- local a, b, c, onlineVersion = string.find(reply, "([\"'])(.-)%1") --trash a,b,c http://www.lua.org/pil/20.3.html
- print("My Version: " .. version)
- print("Online Version: " .. onlineVersion)
- if(version~=onlineVersion) then
- fs.delete(programName)
- local file = fs.open(programName,"w")
- file.write(reply)
- file.close()
- print("New "..programName.." file succesfully downloaded and installed")
- if(isDebug) then
- print("Please Reboot (CTRL+R)")
- else
- shell.run("reboot")
- end
- else
- print("No update found")
- end
- end
- local function getPeripheral() -- finds a peripheral and wraps it
- for a,b in pairs(peripheral.getNames()) do
- if peripheral.getType(b) == "rfid reader" then
- rfidReader = peripheral.wrap(b)
- break
- end
- end
- end
- local function capture() -- captures events from the rfid reader and gets info from the card
- repeat
- rfidReader.scan() -- Defualt 5m (Blocks)
- --local event, data, distance, side = os.pullEvent()
- local event, data = os.pullEvent()
- sleep(1)
- until event == "rfid_detected"
- card = textutils.unserialize(data)
- if isDebug then
- print("event pulled ('rfid_data')")
- print(data)
- end
- end
- local function main()
- update()
- getPeripheral()
- capture()
- -- if card["name"] == "MRMiller" then
- print(card)
- if toString(card.name) == "MRMiller" then
- rs.setOutput(rsSide, true)
- sleep(5)
- rs.setOutput(rsSide, false)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement