Skip to content

Instantly share code, notes, and snippets.

@adamtaylor
Forked from cubabit/gist:5504048
Created May 2, 2013 22:54
Show Gist options
  • Save adamtaylor/5506085 to your computer and use it in GitHub Desktop.
Save adamtaylor/5506085 to your computer and use it in GitHub Desktop.
#!perl
use Dancer;
use LWP::UserAgent;
get '/' => sub {
return <<EOF;
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
setInterval(function (){
\$.get('tag', function(data) {
\$('#rfid').val(data);
//alert('Load was performed.'+data);
})
},5000);
</script>
<title>RFID Sample Scanner</tile>
</head>
<body>
<h1>Sample Check-in</h1>
<form action="/check-in" method="post">
RFID: &nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="rfid" id="rfid"/> <br />
PID: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="pid" name="pid" /> <br />
Location: <input type="location" name="location" /> <br />
Size: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="size" name="size" /> <br />
<input type="submit" value="&raquo; Check-in" />
</form>
</body>
</html>
EOF
};
get '/tag' => sub {
#my @out = `nfc-list`;
my @out;
my $rfid;
foreach my $line ( @out ) {
if ( $line =~ /UID/ ) {
$rfid = $line;
$rfid =~ s/UID\s+\(.+\)://;
$rfid =~ s/\s+//g;
}
}
if ( int(rand(10)) >= 5 ) {
$rfid = int(rand(10000));
};
return $rfid;
};
post '/check-in' => sub {
my $pid = param('pid');
my $rfid = param('rfid');
my $location = param('location');
my $size = param('size');
my $ua = LWP::UserAgent->new();
};
dance;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment