Made the serial loop run twice because sometimes it doesn't catch on the first try.
This commit is contained in:
parent
2b4f5dde6e
commit
60c2d681e2
|
@ -29,43 +29,47 @@ 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)
|
2.times do #do the serial stuff twice as sometimes the serial port is occupied
|
||||||
serial.print "e 1234\r"
|
|
||||||
|
|
||||||
case cgi['cmd']
|
serial = SerialPort.new("/dev/ttyUSB0", 57600, 8, 1, SerialPort::NONE)
|
||||||
when "open-front"
|
serial.print "e 1234\r"
|
||||||
puts "Front door opened."
|
|
||||||
serial.print "o 1\r"
|
case cgi['cmd']
|
||||||
when "open-rear"
|
when "open-front"
|
||||||
puts "Rear door opened."
|
puts "Front door opened."
|
||||||
serial.print "o 2\r"
|
serial.print "o 1\r"
|
||||||
when "unlock"
|
when "open-rear"
|
||||||
puts "Doors unlocked, remember to re-lock them."
|
puts "Rear door opened."
|
||||||
serial.print "u\r"
|
serial.print "o 2\r"
|
||||||
when "lock"
|
when "unlock"
|
||||||
puts "Doors locked."
|
puts "Doors unlocked, remember to re-lock them."
|
||||||
serial.print "l\r"
|
serial.print "u\r"
|
||||||
when "arm"
|
when "lock"
|
||||||
if(users[cgi['user']]['admin'] == true) then
|
puts "Doors locked."
|
||||||
puts "Armed."
|
serial.print "l\r"
|
||||||
serial.print "2\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
|
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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user