blaablaaguy
Posts: 623
Joined: Sun Sep 27, 2015 3:26 pm

Use app to connect to pi via bluetooth.

Wed Apr 06, 2016 4:53 pm

Theres this app I found and id like to use it with my pi and python. Basically i want to be able to make python stuff happen when a specific button is pressed in the app. Ive got a bluetooth dongle but dont know what version it uses since ive had it for years and its pretty much ancient.

EDIT: Oops forgot to post app... :oops:
https://play.google.com/store/apps/deta ... Controller
This signature intentionally left blank.

User avatar
Douglas6
Posts: 4558
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Use app to connect to pi via bluetooth.

Wed Apr 06, 2016 6:35 pm

You'll need to add the SP profile to the Pi. Edit this file:

Code: Select all

sudo nano /etc/systemd/system/dbus-org.bluez.service
Add the compatibility flag, ' -C', at the end of the 'ExecStart=' line. Add a new line after that to add the SP profile. The two lines should look like this:

Code: Select all

ExecStart=/usr/lib/bluetooth/bluetoothd -C
ExecStartPost=/usr/bin/sdptool add SP
Save the file and reboot. Pair and trust your Pi and phone with bluetoothctl.

Now, in a terminal on the Pi, enter the following:

Code: Select all

sudo rfcomm watch hci0
Now you can connect from the app and send text or macros. You can read it on the Pi with minicom, or in Python with PySerial or whatever serial comm software you prefer.

blaablaaguy
Posts: 623
Joined: Sun Sep 27, 2015 3:26 pm

Re: Use app to connect to pi via bluetooth.

Wed Apr 06, 2016 7:23 pm

Thanks, ill try it out when im next at my pi.
This signature intentionally left blank.

blaablaaguy
Posts: 623
Joined: Sun Sep 27, 2015 3:26 pm

Re: Use app to connect to pi via bluetooth.

Fri Apr 08, 2016 4:18 pm

Thanks, ive connected to my pi, but how do i use pyserial to read the button presses? Google revealed nothing...
This signature intentionally left blank.

User avatar
Douglas6
Posts: 4558
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Use app to connect to pi via bluetooth.

Fri Apr 08, 2016 4:46 pm

blaablaaguy wrote:Google revealed nothing...
Wow, seriously? A search for 'pyserial' returns this (and hundreds of thousands others) : https://pythonhosted.org/pyserial/. PySerial comes installed in Raspbian, for Python 2, anyways.

I used to have some code that read from /dev/rfcomm0. If I can find it or recreate it, I'll post it here.

[EDIT: You can perform a simple test with 'cat /dev/rfcomm0']

blaablaaguy
Posts: 623
Joined: Sun Sep 27, 2015 3:26 pm

Re: Use app to connect to pi via bluetooth.

Fri Apr 08, 2016 5:22 pm

Thanks, got pyserial working!
This signature intentionally left blank.

mukut_mukherjee
Posts: 13
Joined: Mon Jan 18, 2016 6:58 am

Re: Use app to connect to pi via bluetooth.

Sun Oct 02, 2016 4:02 am

I certainly managed to get a CSR v4.0 bluetooth module which claims itself to be compatible with the pi. So once again will the steps mentioned above work for me?

Douglas, you said to edit that blues bluesman package but is that package included in the is by default or we need to get it. If so then can tell me the command?

User avatar
Douglas6
Posts: 4558
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Use app to connect to pi via bluetooth.

Sun Oct 02, 2016 4:54 am

I don't recall ever suggesting to 'edit that blues bluesman package'. Using a dongle versus the Pi3 onboard Bluetooth is identical, although on the Pi3 you'll need to disable the onboard Bluetooth first.

mukut_mukherjee
Posts: 13
Joined: Mon Jan 18, 2016 6:58 am

Re: Use app to connect to pi via bluetooth.

Sun Oct 02, 2016 6:24 am

Oops sorry it seems I have forgot to tell that I have a pi 2 and not pi3 and I had confused this post with another. I am very sorry and apologise for the inconvenience Douglas.

baruchli
Posts: 5
Joined: Thu Dec 15, 2016 3:51 pm

Re: Use app to connect to pi via bluetooth.

Sat Dec 17, 2016 8:01 pm

Douglas6 wrote:You'll need to add the SP profile to the Pi. Edit this file:

Code: Select all

sudo nano /etc/systemd/system/dbus-org.bluez.service
Add the compatibility flag, ' -C', at the end of the 'ExecStart=' line. Add a new line after that to add the SP profile. The two lines should look like this:

Code: Select all

ExecStart=/usr/lib/bluetooth/bluetoothd -C
ExecStartPost=/usr/bin/sdptool add SP
Save the file and reboot. Pair and trust your Pi and phone with bluetoothctl.

Now, in a terminal on the Pi, enter the following:

Code: Select all

sudo rfcomm watch hci0
Now you can connect from the app and send text or macros.
I had followed your suggestions.
Good news: I was able to connect Android (Bluetooth Terminal application) to Pi (when sudo rfcomm watch hci0 is running).

Now I would like to send serial data back and forth. So, the questions:

1. Should I keep Pi Serial interface enabled in this configuration?
2. What port I should config on Pi minicom to observe and send serial data? Is it /dev/rfcomm0? Are there any serial port parameters I should set on minicom for successful data exchange?
3. What is connection between /dev/rfcomm0 and hci0

User avatar
Douglas6
Posts: 4558
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Use app to connect to pi via bluetooth.

Sat Dec 17, 2016 8:34 pm

baruchli wrote: 1. Should I keep Pi Serial interface enabled in this configuration?
2. What port I should config on Pi minicom to observe and send serial data? Is it /dev/rfcomm0? Are there any serial port parameters I should set on minicom for successful data exchange?
3. What is connection between /dev/rfcomm0 and hci0
1. Not sure what you mean. Yes, you will want to keep the rfcomm watch command running.
2. Yes, tell minicom to use the /dev/rfcomm0 port.

Code: Select all

minicom -D /dev/rfcomm0 
You may need to set the baud rate with the -b flag.
3. hci0 is the Bluetooth adapter. /dev/rfcomm0 is the virtual serial device you told rfcomm to create using that adapter. Since it is the first one, it got named with a zero.

baruchli
Posts: 5
Joined: Thu Dec 15, 2016 3:51 pm

Re: Use app to connect to pi via bluetooth.

Sat Dec 17, 2016 8:55 pm

1. Not sure what you mean.
I speak about this GUI option:
Image
Yes, you will want to keep the rfcomm watch command running.
So I should add command

Code: Select all

sudo rfcomm watch hci0
to startup script?
2. Yes, tell minicom to use the /dev/rfcomm0 port.

Code: Select all

minicom -D /dev/rfcomm0 
You may need to set the baud rate with the -b flag.
3. hci0 is the Bluetooth adapter. /dev/rfcomm0 is the virtual serial device you told rfcomm to create using that adapter. Since it is the first one, it got named with a zero.
Thank you! Meantime I managed to send bytes back and forward :!:

User avatar
Douglas6
Posts: 4558
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Use app to connect to pi via bluetooth.

Sat Dec 17, 2016 9:05 pm

Ah, that 'serial interface' refers to the tty serial, no connection with rfcomm0. Yes, it will probably be convenient to add the rfcomm watch command to start at boot time. Glad you got it working!

Return to “General discussion”