#!/bin/bash

PRINTER=$(echo $1 | cut -f1 -d#)
PIN=$(echo $1 | cut -f2 -d#)

if [ "$PRINTER" = "" ]; then
  echo "Usage: $0 <printer>[#pin]"
  exit
fi
echo $PRINTER
echo $PIN
# hcitool scan
# printer
#PRINTER="00:1F:B7:06:B9:EA"
# scale
#SCALE="00:06:66:00:54:CC"


# PIN: 1234
if [ "$PIN" = "" ]; then
  bluez-simple-agent hci0 $PRINTER
else
  echo $PIN | bluez-simple-agent hci0 $PRINTER
fi

bluez-test-device trusted $PRINTER
/etc/init.d/bluetooth restart
rfcomm bind /dev/rfcomm0 $PRINTER 1

#rfcomm bind /dev/rfcomm0 $SCALE 1

