You are here

PyGatt and Cypress BLE dongle | Cypress Semiconductor

PyGatt and Cypress BLE dongle

Summary: 11 Replies, Latest post by PRKU on 25 Oct 2017 09:56 PM PDT
Verified Answers: 0
Last post
Log in to post new comments.
Itamar Davidesco's picture
User
6 posts

Hi, 

I'm trying to connect  Cypress BLE dongle with Python pygatt package, on windows 10.

My program get to failure when the 'start' function try to 'disable advertising'.

This is my simply code:

import pygatt
adapter = pygatt.BGAPIBackend(serial_port='COM4')
adapter.start()

and i get to this message:

pygatt.backends.bgapi.exceptions.ExpectedResponseTimeout: Timed out after 1.000000s waiting for [<ResponsePacketType.gap_set_mode: 58>]

 

Any help will be appreciated.

Thanks

 

 

jrow's picture
Cypress Employee
164 posts

Hello Itamar,

The BGAPI backend for PyGatt is designed to work with Bluegiga's products (hence the "BG" in "BGAPI"), but this is not unfortunately compatible with the Cypress dongle, which uses a very different binary protocol. I don't believe PyGatt has any backend support for the Cypress dongle at this time, based on the documentation on its Github repo.

Thanks,

Jeff

Itamar Davidesco's picture
User
6 posts

Thank you very much!

Itamar

Itamar Davidesco's picture
User
6 posts

Hi Jeff,

Following your answer above, I purchased a BLED112 dongle.

I want to communicate with some board via HF-BL100-CU (a BLE module which included a CYBL-10162-56l , cypress chip).

I Just want to send strings to UUID 2B11, and read from UUID 2B10.

With the following code i succeed only to connect and read from UUID 2A00 (device name). 

When I try to write to 2B11 or read from 2B10 i get an error:

pygatt.exceptions.BLEError: No characteristic found matching 00002b11-0000-1000-8000-00805f9b34fb

This is my code:

import pygatt
import logging
import time

adapter = pygatt.BGAPIBackend(serial_port='COM3')
adapter.start()

device = adapter.connect('BB:A0:50:00:3f:36')
time.sleep(1)
print device.char_read("00002a00-0000-1000-8000-00805f9b34fb")
time.sleep(1)
device.char_write('00002b11-0000-1000-8000-00805f9b34fb', bytearray([0x61, 0x70, 0x70, 0x72, 0x01, 0x01, 0x0d, 0x0a]))

 

What i have to do in order to send a string to UUID 2B11 correctly?

Thank you

Itamar

jrow's picture
Cypress Employee
164 posts

Hello Itamar,

Are you certain that characteristics 2B10 and 2B11 exist on the peripheral device? Can you verify this with a separate tool, such as LightBlue on iOS, or nRF Connect on Android, or (since you have the BLED112) BLE GUI on Windows?

I would recommend enabling debug log output in PyGatt using the code described in the Github repo readme file:

import pygatt
import logging
logging.basicConfig()
logging.getLogger("pygatt").setLevel(logging.DEBUG)

Hopefully this helps illuminate the problem.

Jeff

Itamar Davidesco's picture
User
6 posts

Hi Jeff,

Thanks for your response.

1. UUID 2b11  is indeed exist, , and when I use BLE GUI, I success to write a command to my device.
The following is the log from BLE GUI:

2017.08.13 16:48:52.669 ble_cmd_attclient_write_command connection: 0 (0x00) atthandle: 17 (0x0011) data: 61 70 70 63 02 64 0d 0a
2017.08.13 16:48:52.673 TX: 000c0406001100086170706302640d0a

2017.08.13 16:48:52.676 ble_rsp_attclient_write_command connection: 0 (0x00) result:0x0000 ['No Error']
2017.08.13 16:48:52.678 RX: 00030406000000

2. When I run my code from the post above , with the log output, I find the following warning:

WARNING:pygatt.backends.bgapi.bgapi:UUID 2b11 is of unknown type

So, why this characteristic is recognize as 'unknown type'?

Thank you very much for your assistance

Itamar

jrow's picture
Cypress Employee
164 posts

Hi Itamar,

I haven't used PyGatt before, but looking at the code suggests that it does not cleanly handle a 16-bit UUID that is not an officially adopted value. The type check function returns None instead of a useful value, and the code that uses this value doesn't interpret it as a characteristic to be used. See these parts of the code:

https://github.com/peplin/pygatt/blob/master/pygatt/backends/bgapi/bgapi...

https://github.com/peplin/pygatt/blob/master/pygatt/backends/bgapi/bgapi...

This could be called either a feature or a bug, because it's actually preventing the use of characteristic UUIDs that might be invalid. Officially, all 16-bit UUIDs are reserved for entities defined by the Bluetooth SIG. All proprietary/custom entities should use 128-bit UUIDs. This list has all current adopted 16-bit UUIDs for characteristics, for example:

https://www.bluetooth.com/specifications/gatt/characteristics

I would recommend either (1) changing the UUIDs on the peripheral device to 128-bit instead of 16-bit if this is possible, or else (2) contacting the PyGatt developer by raising an issue on Github.

Jeff

Itamar Davidesco's picture
User
6 posts

Hi Jeff,

I'll try your suggestions.

But , one more question, 
I'm think to try using BGLIB instead of PyGatt, and simply imitate the commands which i see in the BLE GUI log.
but, i've missing the commands (in BGlib) which equivalents to the following commands from PyGatt:

adapter = pygatt.BGAPIBackend(serial_port='COM3')
adapter.start()
device = adapter.connect('BB:A0:50:00:3f:36')

So, do you know what is the commands to connecting to the dongle and the device via BGLib?

Thanks
Itamar

jrow's picture
Cypress Employee
164 posts

Hi Itamar,

The BGAPI command to initiate an outgoing connection to a known MAC address is simply gap_connect_direct. This command takes the target address and address type, as well as the connection parameters. Refer to the official API reference guide for details on the arguments, but make sure that you specify the correct type (0=public, 1=private/random). If the address matches but the type doesn't, the connection will not succeed.

Jeff

Itamar Davidesco's picture
User
6 posts

Hi Jeff,

I trying the gap_connect_direct command, like in the following code (the parameters are just like i see in the BLE GUI log):

a=bglib.BGLib()
time.sleep(1)
a.ble_cmd_gap_connect_direct((0xbb,0xa0,0x50,0x00,0x3f,0x92),0,60,76,100,0)

But nothing happens. i don't see an connection indication on my BLE device (what did succeed with PyGatt)

I wonder, should I initiate the communication with the BLED112 (COM number etc.). if i need to, what command should be used for that?

 

Thanks

Itamar

jrow's picture
Cypress Employee
164 posts

Hello Itamar,

I would recommend referring to one of the "collector" example projects on the original BGLib repository for a demonstration of master/central functionality, including outgoing connection establishment and all required initialization.

https://github.com/jrowberg/bglib/blob/master/Python/Examples/bglib_test_htm_collector.py

This should help.

Jeff

Log in to post new comments.