strawberry-8
Posts: 4
Joined: Thu Jun 13, 2019 2:54 pm

BLE connection with an android

Thu Jun 13, 2019 3:06 pm

Hello everybody,

I am a student and I have a project to do on a Raspberry Pi zero W. I need to create an android application to connect to Bluetooth Low Energy (if possible otherwise normal bluetooth) in order to exchange data. But the Rpi must be a device (when the product is finished, there will be no access to the Rpi). The link must therefore be from the application. I’ve already made the app, but when it displays all the devices captured, there’s not my address's card.
I should mention that I installed bluez on my Rpi but I don’t know what else to do at all, I totally start on Raspberry. I have been looking for documentation but none of the solutions I have found work (I have only found one or two).
If anyone has any clues, I’ll take it.

Thank you

Strawberry-8

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

Re: BLE connection with an android

Thu Jun 13, 2019 4:06 pm

I just posted some Python code on Github to make a Raspberry Pi GATT server (peripheral).

Clone the repo, read the README, and try the code.

https://github.com/Douglas6/cputemp.git
Last edited by Douglas6 on Fri Jun 14, 2019 3:06 pm, edited 1 time in total.

strawberry-8
Posts: 4
Joined: Thu Jun 13, 2019 2:54 pm

Re: BLE connection with an android

Fri Jun 14, 2019 8:25 am

Thank you Douglas

I'll try that and tell you if it work.

strawberry-8
Posts: 4
Joined: Thu Jun 13, 2019 2:54 pm

Re: BLE connection with an android

Fri Jun 14, 2019 1:12 pm

It works. You're the best douglas.

I just have to use the code in 'cputemp.py' for my project or the others are useful too?

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

Re: BLE connection with an android

Fri Jun 14, 2019 7:34 pm

You'll need to import from advertisement.py and service.py (which import bletools.py), but you should only need to make modifications to cputemp.py.

strawberry-8
Posts: 4
Joined: Thu Jun 13, 2019 2:54 pm

Re: BLE connection with an android

Mon Jun 17, 2019 1:02 pm

Yes, I had not seen that the code "cputemp" used the other functions.
I have an other question :
Is there a predefined uuid address for all data or do I need to create a new address ?

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

Re: BLE connection with an android

Mon Jun 17, 2019 2:40 pm

You can use one of a number of predefined UUIDs for services (https://www.bluetooth.com/specifications/gatt/services/) or characteristics (https://www.bluetooth.com/specification ... teristics/). Or you can use your own random 128-bit UUID. I got mine from https://www.uuidgenerator.net/ and then just zeroed out the first few bytes and numbered them sequentially. Not required but good form.

Return to “Networking and servers”