PIN requester
Dear BlueZ Developers!
My name is Fulop Balazs. I study at the Budapest University of Technology and Economics.
As a Christmas present, I got a Bluetooth USB adapter yesterday. I wanted to see it in action immediately so I booted up my Linux box (running 2.4.28) and started to look for the necessary tools.
After some workaround I had a feeling that I was close to the solution but something was wrong. I loaded the necessary modules, and I started the required daemons. When I started gnokii, it connected to my mobile phone, and I was asked to enter a PIN code on the phone. It did not matter what I gave it, it did not work. The computer did not ask me to give a code.
I knew I needed to specify the PIN, but I did not know how, because I did not get any error messages about this. After a while I realised that /usr/bin/bluepin is invoked in the situation. It is a Python script and it imports the pygtk module which was not available on my machine. After installing the python-gtk package on my Debian Woody, nothing changed.
I am not familiar with Python but I think it needs a Gtk 2.0 module which is not available as a package for Debian Woody 3.0 r1. Because of this I wrote a Perl-tk script to do the job and now it just works fine.
If you are interested in my solution, take a look at the attachment. It is not a big deal, but I am quite proud of it. Moreover, if you would like to include it in bluez-utils go right ahead. It is released under GPL ;-)
I am not on the list, so please reply to [email protected]. Sorry for the long letter, and Merry Christmas to Everyone.
Hail,
Fulop Balazs
#!/usr/bin/perl -w
# PIN code requester
# Satisfies BlueZ requirements
# Written by Fulop Balazs <[email protected]>, 2004
use strict;
use Tk;
my $mainwin = new MainWindow ( -title => "Enter PIN", -borderwidth => 20 );
my $frame = $mainwin -> Frame ( -borderwidth => 5 );
$frame -> Label ( -text => "PIN:" ) -> pack ( -side => "left" );
my $pin = $frame -> Entry (
-justify => "center",
-validate => "key",
-validatecommand => \&check) -> pack ( -side => "right" );
$pin -> bind ( "<Return>" => \&ok );
$pin -> bind ( "<Escape>" => \&cancel );
$pin -> focus;
$frame -> pack ( -side => "top" );
$mainwin -> Button ( -text => "Ok", -command => \&ok ) ->
pack ( -side => "left" );
$mainwin -> Button ( -text => "Cancel", -command => \&cancel ) ->
pack ( -side => "right" );MainLoop;
sub check {
return 1 if ($_[1] =~ /[0-9]/);
return 0;
}sub ok {
my $code = $pin -> get;
cancel () if ("" eq $code);
print "PIN:" . $code . "\n";
exit;
}sub cancel {
print "ERR\n";
exit;
}