LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking > Linux - Wireless Networking
User Name
Password
Linux - Wireless Networking This forum is for the discussion of wireless networking in Linux.

Notices


Reply
  Search this Thread
Old 08-11-2017, 07:35 PM   #16
bbb123
LQ Newbie
 
Registered: Aug 2017
Posts: 2

Rep: Reputation: Disabled
Unhappy Need help automating solution from jwaters42


I followed the steps from jwaters42 (thanks!) and they work for me manually. Now I want to automate the process, but I am having no luck.

Specifically, I am doing the following:

Create directory
/usr/bin/bluez/

Edit /etc/rc.local
Add this line (right before the “exit 0” line).
/usr/bin/bluez/setpin.sh

Create the text file /usr/bin/bluez/setpin.sh
Code:
#!/bin/sh
hciconfig hci0 piscan
hciconfig hci0 sspmode 0
/usr/bin/python /usr/bin/bluez/simple-agent &
Copy these two files into /usr/bin/bluez/
simple-agent
bluezutils.py
These two files are available from downloading and untarring the latest Bluez tar file.
They are both in the test/ directory after you untar.
Copy these two files to the BeagleBone directory /usr/bin/bluez/.

You can make a file executable with these commands:
chmod +x setpin.sh
chmod +x simple-agent

Edit simple-agent
vi /usr/bin/bluez/simple-agent

Comment out contents of AuthorizeService
Code:
        def AuthorizeService(self, device, uuid):
                # print("AuthorizeService (%s, %s)" % (device, uuid))
                # authorize = ask("Authorize connection (yes/no): ")
                # if (authorize == "yes"):
               #        return
                # raise Rejected("Connection rejected by user")
Modify
Code:
        def RequestPinCode(self, device):
                # print("RequestPinCode (%s)" % (device))
                set_trusted(device)
                # return ask("Enter PIN Code: ")
                return "123456"
In main method near the bottom, change capability line to read
Code:
capability = "NoInputNoOutput"

If I start simple-agent manually from a command terminal as follows
/usr/bin/bluez/setpin.sh
and then connect to the Linux beaglebone via Bluetooth from a disconnected laptop, I will be prompted to enter the PIN. I must enter 123456 to match method RequestPinCode. Then the laptop connects. Good!

UNRESOLVED PROBLEM
If I reboot the beaglebone, so that simple-agent is started by /etc/rc.local, which starts /usr/bin/bluez/setpin.sh, then I will NOT be asked to enter a PIN. The laptop just connects. Bad!

Any advice, suggestions, and tips are appreciated.

Last edited by bbb123; 08-11-2017 at 07:39 PM.
 
Old 08-22-2017, 04:24 PM   #17
bbb123
LQ Newbie
 
Registered: Aug 2017
Posts: 2

Rep: Reputation: Disabled
Smile I resolved my issue as follows...

Continuing from my previous post, but now with the fix:

I remove the line I had added to /etc/rc.local
(I don't use /etc/rc.local now.)

I modify the text file /usr/bin/bluez/setpin.sh as follows
Code:
#!/bin/sh
sleep 120
hciconfig hci0 piscan
sleep 10
hciconfig hci0 sspmode 0
sleep 10
/usr/bin/python /usr/bin/bluez/simple-agent &
As root create a crontab entry with this command.
crontab -e
Choose to use nano and add this line to the end of the file.
Code:
@reboot sleep 5; /usr/bin/bluez/setpin.sh
Exit Nano (Cntl-X) and save (Y).

Also, I had no previous experience with Python and I discovered you need to be really careful with indentation.
I used one or two tabs instead of spaces.
Also, I found that I need to explicitly return from this method
Code:
def AuthorizeService(self, device, uuid):
# print("AuthorizeService (%s, %s)" % (device, uuid)) # authorize = ask("Authorize connection (yes/no): ") # if (authorize == "yes"): return # raise Rejected("Connection rejected by user")
Now after I reboot my beaglebone and wait 2.5 minutes, I am required to enter PIN 123456 when connecting to beaglebone via bluetooth.

There is a weakness with this approach. The beaglebone allows bluetooth connection without PIN during 140 seconds until simple-agent starts up.
You might want to cut down the sleep times (120, 10, 10 seconds) to something more appropriate for your system. However, if simple-agent runs too early, then it fails to start up properly and a PIN is never required.

Last edited by bbb123; 08-22-2017 at 04:35 PM. Reason: more info
 
  


Reply

Tags
bluetooth, bluez, iphone


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bluez passkey-agent, fails ebinjose Linux - Wireless Networking 2 05-18-2010 12:33 AM
Bluetooth headset, Alsa - no soundcard in /proc/asound/cards (but headset works) simopal6 Linux - Hardware 1 04-29-2009 09:07 AM
Issue with BlueZ pin (I think) adriaan.klue Linux - General 2 01-15-2009 08:25 AM
kbluetoothd invalid arguments to passkey sfrdll Linux - Newbie 8 10-15-2007 10:47 AM
CPU 12-V power supply: 4-pin or 8-pin? michapma Linux - Hardware 3 07-23-2007 10:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking > Linux - Wireless Networking

All times are GMT -5. The time now is 09:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration