put cardnumber from SmartX into content
[Biblio-RFID.git] / scripts / RFID-JSONP-server.pl
index 8d44048..974a316 100755 (executable)
@@ -91,6 +91,9 @@ sub http_server {
        print "Server $0 ready at $server_url\n";
 
        while (my $client = $server->accept()) {
+
+           eval { # don't die inside here!
+
                $client->autoflush(1);
                my $request = <$client>;
 
@@ -138,6 +141,7 @@ sub http_server {
                                                        warn "ERROR ", dump($borrower);
                                                } else {
                                                        $hash->{borrower} = $borrower->{borrower};
+                                                       $hash->{content}  = $borrower->{borrower}->{cardnumber}; # compatibile with 3M tags
                                                }
                                        } else {
                                                $hash->{security} = uc unpack 'H*', $rfid->afi( $tag );
@@ -178,7 +182,7 @@ sub http_server {
                                        $status = 302;
 
                                        warn "SECURE $tag $data\n";
-                                       $rfid->write_afi( $tag => hex($data) );
+                                       $rfid->write_afi( $tag => chr(hex($data)) );
                                }
 
                                if ( $json ) {
@@ -195,6 +199,12 @@ sub http_server {
                        print $client "HTTP/1.0 500 No method\r\n\r\n";
                }
                close $client;
+
+           }; # end of eval
+           if ( $@ ) {
+               warn "ERROR: $@";
+           }
+
        }
 
        die "server died";