Use 20737 as client only, read/write via GATT

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello,

I want to use an Anaren A20737 module to wait for a button press, and then connect to a BLE peripheral (Service and characteristics are known); and send / read some byte, and return back to sleep.

I took the anaren_hello_client project as an example, however I end up with a few problems, and I am not able to find the documentation on how to get this working.

  1. How should I disable the peripheral function in hello_client? I suppose I could use the bleprofile_Discoverable(NO_DISCOVERABLE, NULL) function to do this, but I suppose it should also be possible to remove a lot of code, making the example more understandable.
  2. I am trying to make my board connect to my peripheral device. This peripheral device shows up in the function "hello_client_advertisement_report()" function with an UUID advertising flag of "ADV_SERVICE_UUID128_MORE" instead of "ADV_SERVICE_UUID128_COMP". What should I do with this? Can I just accept this and continue connecting? I assume that this means that there are more functions than advertised in the service UUID.
  3. I tried to accept it, however then there is encryption required for this connection (it seems). When the program continues and reaches "hello_client_connection_up()", bleprofile_p_cfg->encr_required = 3. This is not a valid number when I look into the definition of encr_required in the BLE_PROFILE_CFG struct. From here on I loose the possibillity to find what is going on. Connection fails (trace: "Pairing failed<\r>". Source of this trace is somewhere in objectcode I guess).

Can someone help me with this? Maybe there is a better example to start working from?

I am able to connect using lightblue, or hcitool on commandline linux, and I can also write and read the required values

0 Likes
1 Solution
Anonymous
Not applicable

Hello.

I'm pretty sure you can't connect if you are not scanning.

You have blecen_Scan( NO_SCAN ); in the code snippet above,

but your client/master (hello_client) probably starts scanning somewhere else, perhaps in the connection_down callback.

Have you tried checking the connection_down callback?

Try making sure you are not scanning after disconnection.

James

View solution in original post

6 Replies
Anonymous
Not applicable

Hello.

1. How should I disable the peripheral function in hello_client? I suppose I could use the bleprofile_Discoverable(NO_DISCOVERABLE, NULL) function to do this, but I suppose it should also be possible to remove a lot of code, making the example more understandable.

Yes you can this. Either you don't call bleprofile_Discoverable at all or you make the device not discoverable.

2. I am trying to make my board connect to my peripheral device. This peripheral device shows up in the function "hello_client_advertisement_report()" function with an UUID advertising flag of "ADV_SERVICE_UUID128_MORE" instead of "ADV_SERVICE_UUID128_COMP". What should I do with this? Can I just accept this and continue connecting? I assume that this means that there are more functions than advertised in the service UUID.

Yes your assumption is correct. It just means that the the device that is sending out the advertisement has more service UUIDs. This should not cause any problems for connecting.

3. I tried to accept it, however then there is encryption required for this connection (it seems). When the program continues and reaches "hello_client_connection_up()", bleprofile_p_cfg->encr_required = 3. This is not a valid number when I look into the definition of encr_required in the BLE_PROFILE_CFG struct. From here on I loose the possibillity to find what is going on. Connection fails (trace: "Pairing failed<\r>". Source of this trace is somewhere in objectcode I guess).

bleprofile_p_cfg->encr_required = 3 should not cause any problems either. It just means both SECURITY_ENABLED and SECURITY_REQUEST are enabled.

"Pairing failed" is logged by lesmpapi message handler. So let's look at two sides of the problems.


Slave/server:

Since you are able to connect to the slave using your iphone, the slave probably isn't the problem.

However, just to be thorough, what kind of slave are you trying to connect? Is it hello_sensor? Or your own application? third party?

Master/client

Did you make any changes to hello_client code? If so, can you tell me what you did or if you can send us your source code and I can take a look at it.

Also, have you tried connecting your client device to hello_sensor or any application from our SDK to see if it works?

James

0 Likes
Anonymous
Not applicable

Hi James,

While gathering all changes I made, and looking for another time through the code I found that the profile configuration BLE_PROFILE_CFG hello_client_cfg.encr_required was set to "(SECURITY_ENABLED | SECURITY_REQUEST)". So that this client was the part requesting security. My peripheral doesnt understand this. I removed these two, and now I can connect to my peripheral.

These were my changes to the "anaren_hello_client" project, so that others can use this information in their route to produce a client BLE application on an A20737:

Changes between anaren_hello_client and anaren_motion_client (which is my application).

I took "anaren_hello_client" as a starting point for my project, and made the followinf changes to the project:

1. Copied and renamed c, h and makefiles to another folder for my app, and changed all references

2. Removed inclusion of "anaren_hello_sensor.h", and added the following defines to my .c file, to let the application know which UUID to connect to.

    // static const GUID UUID_HELLO_SERVICE               = { 0x3e6fe65d, 0xed78, 0x11e4, { 0x89, 0x5e, 0x00, 0x02, 0x6f, 0xd5, 0xc5, 0x2c } };

    #define UUID_MOTION_SERVICE                  0x2c, 0xc5, 0xd5, 0x6f, 0x02, 0x00, 0x5e, 0x89, 0xe4, 0x11, 0x78, 0xed, 0x5d, 0xe6, 0x6f, 0x3e

    //#define HANDLE_HELLO_SENSOR_SERVICE_UUID                        0x28

    //#define HANDLE_HELLO_SENSOR_VALUE_NOTIFY                        0x2a

    #define HANDLE_HELLO_SENSOR_CLIENT_CONFIGURATION_DESCRIPTOR        0x2b

    //#define HANDLE_HELLO_SENSOR_CONFIGURATION                        0x2d

3. Renamed hello_service to motion_service

    const UINT8 motion_service[16] = { UUID_MOTION_SERVICE};

4. Added a few traces

5. Added:

            //EJE

            ble_trace0( "Send value EJE!" );

            UINT16 u16 = 100;

            bleprofile_sendWriteReq( 0xFA00, (UINT8 *) &u16, 2 );

    when encr == 0 in con_up

6. In "hello_client_advertisement_report()"

    Added: ADV_SERVICE_UUID128_MORE instead of only ADV_SERVICE_UUID128_COMP to valid UUID.

   

7. In the initialization of the BLE_PROFILE_CFG struct I changed ".encr_required" to 0, to make sure I did not need encryption for this device.

Now I have a few more questions, on how to nicely use the Broadcom WICED example:

1. How should I (officially) know where to write to? For example, I know that I should write to the short characteristics UUID 0xFA00. Using hcitool (characteristics command) one of the returned lines was this:

"handle: 0x0011, char properties: 0x1a, char value handle: 0x0012, uuid: c005fa00-0651-4800-b000-000000000000".

How can my application relate this 0xFA00 UUID to the value handle 0x0012?

When I perform this line:

"bleprofile_sendWriteReq( 0x12, (UINT8 *) &u16, 2 );"

it works as I want to. However, I would like to use the UUID 0xFA00 (because this is according to the documentation of the peripheral device).

2. I want my application to perform the following things:

- Once enabled by a button, connect to the peripheral;

- Once connected, write a value to a certain UUID;

- Read another UUID until it reaches a certain value;

- Write another UUID with a value, etc etc.

...

- Disconnect

How can I implement a state machine like this best? Should I put it in some timed-routine, requesting reads and subscribing to these?

Thank you for your help James

0 Likes
Anonymous
Not applicable

Hello.

1.

I think you have to use the char value handle to write to the characteristic on the server.

The handles are what you have to use to access the database.

The handles are associated with the UUID's, so you'll need to know UUID's that you are going to use to find out which handles to use.

If you already know everything about the GATT database that you are connecting to, like in the case of hello_client and hello_sensor, then you can just use the handles.

However if you don't know(you'll at least have to know the UUID's), you have to find the handles used in the GATT database and use those handles to access the database.

There is an example of this latter case in automation_io_client in the SDK.

2.

If you can change the server side device, you can send a notification from the server to the client when it reaches a certain value.

However if you can't change the server side, then you probably will have to continuously read the characteristic value every once in awhile to achieve what you are doing.

My suggestion is to use timer callbacks (there's regular timer and fine timer) to read characteristic value at some intervals and you can do something in the readrsp callback.

So you'll probably want to some combination of hello_client and automation_io_client.

Does this help?

James

Anonymous
Not applicable

Hi Jamesle1,

My application is coming together now. I am able to send / read values, I will make a state machine in the timeout handlers that performs steps to automate what I need.

The last thing on the BLE part is disconnecting gracefully.

My peripheral device has a certain register I need to write in order to disconnect. However this doesnt seem to work.

This is my part of the disconnection code:

u8 = 1;

//Disconnect

bleprofile_sendWriteReq( 0x5d, &u8, 1 );

blecm_disconnect(BT_ERROR_CODE_CONNECTION_TERMINATED_BY_LOCAL_HOST);

blecen_Scan( NO_SCAN );

ble_trace0("Disconnect!");

(called in button interrupt routine).

I need to write to handle 0x5d in order to disconnect.

My device disconnects, for a while: after ~3 - 5sec it is bringing the connection up again. That is not what I expect.

Any idea?

0 Likes
Anonymous
Not applicable

Hello.

I'm pretty sure you can't connect if you are not scanning.

You have blecen_Scan( NO_SCAN ); in the code snippet above,

but your client/master (hello_client) probably starts scanning somewhere else, perhaps in the connection_down callback.

Have you tried checking the connection_down callback?

Try making sure you are not scanning after disconnection.

James

Anonymous
Not applicable

That was indeed the issue.

Now I will focus on bringing down my power consumption, but I will open a new thread for that. Thank you for your help!

0 Likes