LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-19-2019, 05:25 AM   #1
Chams Akrout
LQ Newbie
 
Registered: Jul 2019
Posts: 2

Rep: Reputation: Disabled
How do I use bluetoothctl in a bash script to advertise a custom BLE service ?


Hello everyone,
So I'm trying to execute bluetoothctl cammands in a script but I haven't been successful.
I want to use bluetoothctl in a script in odrer to advertise a custom BLE service and it actually works in terminal but in script it doesn't get past the first line.
There are the commands that I want to use:

bluetoothctl and then
menu gatt
back
register-service <<uuid>>
register-characteristic <<uuid>>
advertise on

In the script I put:

#!/bin/bash

bluetoothctl <<EOF menu gatt
back
register-service 0xffe0
EOF

Unfortunatly it just outputs the menu as if it's not reading the following command. Can anyone please help me out??
 
Old 07-20-2019, 05:04 PM   #2
teckk
Senior Member
 
Registered: Oct 2004
Distribution: FreeBSD Arch
Posts: 2,241

Rep: Reputation: 474Reputation: 474Reputation: 474Reputation: 474Reputation: 474
Can't make anything from what you posted.

Quote:
and it actually works in terminal
Show what commands you executed in the terminal and the results.
Copy/paste the whole thing if you want to.
 
Old 07-20-2019, 07:03 PM   #3
rigor
Member
 
Registered: Sep 2011
Posts: 277

Rep: Reputation: Disabled
Hi Chams Akrout,

It might be helpful if you could give us some additional details, such as what Linux Distribution you are using, or how you came to use the particular collection of inputs you are using to the bluetoothctl command.

In the Linux Distribution I'm using, the bluetoothctl is in the bluez package, but AFAIK, although there are manual pages on some of the other bluetooth related commands, there is no manual page or info document on the bluetoothctl command provided by the Linux Distribution. While it is possible to get the source for the package through the source repository for the Linux Distribution, or through bluez.org then look through the source, and realize that there seem to be some directives such as you are using that are supported by the bluez.org source, a particular Distribution might have chosen to change the behavior of the command.

Just in general terms, if I put the following code in a BASH script within the Linux Distribution I'm using, the "menu gatt" WILL be passed to the bluetoothctl command ( or virtually any other command for that matter ) as options. I've actually tested this.

Code:
#!/bin/bash

bluetoothctl <<EOF menu gatt 
back
register-service 0xffe0
EOF
AFAIK, the following approach is much more reliable:
Code:
#!/bin/bash

bluetoothctl <<EOF
menu gatt 
back
register-service 0xffe0
EOF
Hope this helps.

Last edited by rigor; 07-20-2019 at 07:11 PM.
 
1 members found this post helpful.
Old 07-22-2019, 02:33 AM   #4
Chams Akrout
LQ Newbie
 
Registered: Jul 2019
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks for answering me, as for the linux distribution I'm using ubuntu 18.04 and it contains the latest version of BlueZ and I actually didn't know about it untill I had to dive deeper into the uses of bluetooth because I'm using it to communicate with my phone using a web app and web bluetooth. That's why I need my computer to start advertising this ble service that I made in order for my phone to detect it. I know that maybe this is not really clear but that's what I'm trying to do. So some reasurch led me to this bluetoothctl and I'm trying to figure out its uses and if it's going to be helpfull or not.

Code:
#!/bin/bash

bluetoothctl <<EOF
menu gatt 
back
register-service 0xffe0
EOF
This actually worrks thank you.
Now I need to figure out how to make use of it and how it will serve my purposes.
 
  


Reply


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
[SOLVED] Control bluetoothctl with scripting? Jason_25 Programming 10 07-30-2018 12:43 AM
[SOLVED] Problems with bluetooth (bluetoothctl, blueman, rfcomm) ahTh6aaf Slackware 5 10-08-2017 10:56 PM
bluetoothctl can't find keyboard on certain computer dpeterson3 Linux - Hardware 0 06-23-2016 04:45 AM
LXer: Adventures in Self-Publishing: To Advertise or Not to Advertise? LXer Syndicated Linux News 0 03-26-2014 02:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:56 AM.

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