Made the serial loop run twice because sometimes it doesn't catch on the first try.

This commit is contained in:
hsl-access 2011-07-04 03:14:20 -06:00
parent 2b4f5dde6e
commit 60c2d681e2

View File

@ -28,44 +28,48 @@ users = JSON.parse(userfile)
puts "Content-type: text/html \r\n\r\n" puts "Content-type: text/html \r\n\r\n"
if users[cgi['user']]['pass'].to_s == (Digest::SHA2.new(bitlen=512) << cgi['pass']).to_s then if users[cgi['user']]['pass'].to_s == (Digest::SHA2.new(bitlen=512) << cgi['pass']).to_s then
serial = SerialPort.new("/dev/ttyUSB0", 57600, 8, 1, SerialPort::NONE)
serial.print "e 1234\r"
case cgi['cmd'] 2.times do #do the serial stuff twice as sometimes the serial port is occupied
when "open-front"
puts "Front door opened." serial = SerialPort.new("/dev/ttyUSB0", 57600, 8, 1, SerialPort::NONE)
serial.print "o 1\r" serial.print "e 1234\r"
when "open-rear"
puts "Rear door opened." case cgi['cmd']
serial.print "o 2\r" when "open-front"
when "unlock" puts "Front door opened."
puts "Doors unlocked, remember to re-lock them." serial.print "o 1\r"
serial.print "u\r" when "open-rear"
when "lock" puts "Rear door opened."
puts "Doors locked." serial.print "o 2\r"
serial.print "l\r" when "unlock"
when "arm" puts "Doors unlocked, remember to re-lock them."
if(users[cgi['user']]['admin'] == true) then serial.print "u\r"
puts "Armed." when "lock"
serial.print "2\r" puts "Doors locked."
else serial.print "l\r"
when "arm"
if(users[cgi['user']]['admin'] == true) then
puts "Armed."
serial.print "2\r"
else
puts "Fail. Don't be a naughty user!"
end
when "disarm"
if(users[cgi['user']]['admin'] == true) then
puts "Disarmed."
serial.print "1\r"
else
puts "Fail. Don't be a naughty user!"
end
else
puts "Fail. Don't be a naughty user!" puts "Fail. Don't be a naughty user!"
end end
when "disarm"
if(users[cgi['user']]['admin'] == true) then serial.close
puts "Disarmed." puts ' <a href="/~access">Return.</a>'
serial.print "1\r"
else
puts "Fail. Don't be a naughty user!"
end
else
puts "Fail. Don't be a naughty user!"
end end
serial.close
puts ' <a href="/~access">Return.</a>'
else else
puts "Invalid username or password." puts "Invalid username or password."
end end