julien.launay
Posts: 51
Joined: Wed Mar 30, 2016 5:22 am

Bluetooth programming

Fri Apr 28, 2017 11:28 am

Hello,

I' am looking for the API to use and make a Bluetooth server and client.
I want to use appinventor on my smartphone.
But when I use the Socket I have to fixe a port number. But under Appinventor, I can't fixe any port number.
So do you have a solution to make a server on raspberry and use a bluetooth client on android.
I know how to program on appinventor, but do you have a program in Python to make the bluetooth server.
Thanks.

Julien

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

Re: Bluetooth programming

Fri Apr 28, 2017 12:35 pm

It first depends on what profile you want to use, probably serial port or BLE. For Serial Port Profile, you'll need to add that profile to the Pi, and create a virtual serial port with rfcomm. Then you can use a terminal program or any programming language on the Pi to read from and write to the serial port.
If you want to use BLE, the best way is probably to use node.js; there are libraries 'bleno' and 'nobel' to help with creating a central or peripheral on the Pi.

User avatar
LetHopeItsSnowing
Posts: 357
Joined: Sat May 26, 2012 6:40 am
Location: UK
Contact: Website

Re: Bluetooth programming

Fri Apr 28, 2017 2:10 pm

You might be interested in a project of mine. Its called Blue Dot.

"Blue Dot allows you to control your Raspberry Pi projects wirelessly - its a bluetooth remote and zero boiler plate (super simple to use :) Python library."

It might give you some pointers.

You can see the documentation here http://bluedot.readthedocs.io/en/latest/, there is also a blog post http://www.stuffaboutcode.com/2017/04/b ... berry.html and the code is on github https://github.com/martinohanlon/BlueDot.

The bluedot python library also contains a simple to use Bluetooth Client and Server http://bluedot.readthedocs.io/en/latest/btcommapi.html which might also be useful if you want to roll your own.

I cant answer your question about ports and appinventor as I have never used it. I built the Blue Dot android app using Android Studio.
"am I getting slower, or is stuff more complicated; either way I now have to write it down - stuffaboutcode.com"

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

Re: Bluetooth programming

Fri Apr 28, 2017 2:51 pm

Nice work, Martin. Glad to see you got it working.

User avatar
LetHopeItsSnowing
Posts: 357
Joined: Sat May 26, 2012 6:40 am
Location: UK
Contact: Website

Re: Bluetooth programming

Fri Apr 28, 2017 2:53 pm

Douglas6 wrote:Nice work, Martin. Glad to see you got it working.
I did thank you. I now know way more than I ever wanted to about Bluetooth sockets, bluez and dbus!
"am I getting slower, or is stuff more complicated; either way I now have to write it down - stuffaboutcode.com"

julien.launay
Posts: 51
Joined: Wed Mar 30, 2016 5:22 am

Re: Bluetooth programming

Fri Apr 28, 2017 5:51 pm

Hello, very thanks for your help.
Very good works with your libraries!

In fact I found with the first solution you told me with rfcomm0.
So I start
sudo rfcomm watch hci0
and then I can use the serial under python.
But is there another solution with socket without starting Rfcomm watching?
do you have a program sample on pyhton with Bluetooth socket? :?:

thanks
Julien

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

Re: Bluetooth programming

Fri Apr 28, 2017 6:21 pm

julien.launay wrote:But is there another solution with socket without starting Rfcomm watching?
Not practically. You could go very low-level and use L2CAP, but you really don't want to go there.

User avatar
LetHopeItsSnowing
Posts: 357
Joined: Sat May 26, 2012 6:40 am
Location: UK
Contact: Website

Re: Bluetooth programming

Sat Apr 29, 2017 2:28 am

There is an example of how to use the bluedot Python Bluetooth Server class in the link I posted.

http://bluedot.readthedocs.io/en/latest/btcommapi.html
"am I getting slower, or is stuff more complicated; either way I now have to write it down - stuffaboutcode.com"

SunayK
Posts: 12
Joined: Fri Apr 28, 2017 7:01 pm
Contact: Website

Re: Bluetooth programming

Thu May 04, 2017 3:39 pm

julien.launay wrote:Hello,

I' am looking for the API to use and make a Bluetooth server and client.
I want to use appinventor on my smartphone.
But when I use the Socket I have to fixe a port number. But under Appinventor, I can't fixe any port number.
So do you have a solution to make a server on raspberry and use a bluetooth client on android.
I know how to program on appinventor, but do you have a program in Python to make the bluetooth server.
Thanks.

Julien
This page gives you simple Bluetooth client and server code, if anyone intrested.
http://www.leenabot.com/en/Blog/
Build your own Robot! visit www.LeenaBOT.com for more detail

Return to “Python”