Skip to main content

multirole example send data

2 months ago

multirole example send data

Posted byBenjaminDu135 points 12 replies
0 upvotes

Hi Dialog,

In short, my question is how to send data to slaves inMultiroleexample.

Let me explain my question:

I useDA14531-DA14585 586_Multirole_Example to connect with multi slaves (I useble_app_profileexample), I can connect more than one slaves,and the master(Multirole) can receive data from slaves,but I don't know how to send data to slave, I use iPad to connect the slave(ble_app_profileexample), and slave can receive data.

I tested the following inuser_catch_rest_hndlCallback, I hope if there is data received, then I will send data to slave, but I can received data from slave, while slave can not receive data.

struct gattc_write_cmd *wr_char = KE_MSG_ALLOC_DYN(GATTC_WRITE_CMD,
dest_id, src_id,
gattc_write_cmd, sizeof(struct gattc_write_cmd));

// Offset
wr_char->offset = 0x0000;
// cursor always 0
wr_char->cursor = 0x0000;
// Write Type
wr_char->operation = GATTC_WRITE;
// Characteristic Value attribute handle
wr_char->handle = 1;
// Value Length
wr_char->length = 3;
/ /自动执行
wr_char->auto_execute = true;
// Value


int8_t AA[2];
AA[0]=9;
AA[1]=5;

memcpy(&wr_char->value[0],AA, 2);

// Send the message
ke_msg_send(wr_char);

Thanks

Benjamin

2 months ago

PM_Dialog

Hi BenjaminDu,

Thanks for your question. You can use the BLE notifications. Please check theDA14585/DA14586/DA14531 Central Implementationthat demonstrates how to perform GATT reads/writes as a Central.

In the user_ble_gatt.c source file, you will find the user_ble_gatt_write(). That function performs a gatt write. You should send a GATTC_WRITE_CMD command to the stack.

Thanks, PM_Dialog

2 months ago

BenjaminDu 135 points

Hi dialog,

非常感谢你的快速回答。

I finduser_ble_gatt_write()is similar with my function used in the above, anyhow, I tested the function with different parameters, but still can not receive data in the slave.

Can you help to give an example with parameters on how to use this function? the slave can receive data from LightBlue as the picture shows , if the function can send same data as the picture shows, I believe it can be a very good starting point and I will be able to use this function.

Thanks again.

Benjamin

Attachment Size
1.jpg 157.96 KB
2.jpg 159.6 KB
3.jpg 168.29 KB

2 months ago

BenjaminDu 135 points

Hi Dialog,

Can you give me a reply?

Thanks a lot

Benjamin

2 months ago

PM_Dialog

Hi Benjamin,

Let me check this and I'll get back to you.

Thanks, PM_Dialog

2 months ago

BenjaminDu 135 points

Hi Dialog,

Thanks a lot for your reply, I also tried many parameters these days but still can not get a good result,

so I hope there could be an answer from you.

Thanks again

Benjamin

2 months ago

BenjaminDu 135 points

Hi Dialog,

Even an example will be very help, hope you can help.

Thanks a lot

Benjamin

2 months ago

PM_Dialog

Hi Benjamin,

Apologies for the delay. Quick question : in which service would you like to write from the GAP Central device? Is it the custom service?

Can you please share how the user_ble_gatt_write() is called?

Thanks, PM_Dialog

2 months ago

BenjaminDu 135 points

Hi dialog,

Thanks a lot for your reply.

I calleduser_ble_gatt_write()in functionuser_catch_rest_hndl().

following is part of the code I used to do the calling.

570
571 case GATTC_EVENT_IND:
572 {
573
574 / /添加由便雅悯
575 int8_t AA[2];
576 AA[0]=9;
577 AA[1]=5;
578
579 user_ble_gatt_write(GATTC_WRITE_CMD,conn_idx,SVC1_IDX_LED_STATE_VAL,AA,sizeof(AA));
580
581
582 //following two lines output received data.
583 struct gattc_event_ind const *msg_param = (struct gattc_event_ind const *)(param);
584 arch_printf("<%d>\t",msg_param->value[0]);
585 //above added by Benjamin
586
587 }break;
588
589 case GAPM_CMP_EVT:
590 {

Thanks

Benjamin

2 months ago

BenjaminDu 135 points

Hi Dialog,

What's the difference between different services? do you mean in custom service I can not do the calling?

My question is if I can do the right calling and the slave can receive, anywhere is OK.

Thanks

Benjamin

1 month ago

BenjaminDu 135 points

Hi Dialog,

Any more information need me to add?

Thanks

Benjamin.

accepted answer!

1 month ago

PM_Dialog

Hi BenjaminDu,

Please check handle_svc_ind() from Central Implementation SW Example. When a GATTC_SDP_SVC_IND is received the handle_svc_ind(con_idx, disc_svc); is called in the user_catch_rest_hndl(). The GATTC_SDP_SVC_IND means that the Service Discovery indicates that a service has been found, so handle_svc_ind() is getting triggered once a new service has been found. If you check the code in handle_svc_ind(), you will see that it discovers for the BAS(ENABLE_BAS) and IAS services (ENABLE_IAS). After the service discovery, you can press the button on the central device. This will write to the alert service and start blinking the LED on the proximity reporter. You should also see the write over the terminal if sent properly.

So, when the button is pressed, then the user_ble_gatt_write() is called in order to write to the IAS.

In the case of the custom service (SVC1_IDX_LED_STATE_VAL), you should follow the same procedure. Discover the custom service in the handle_svc_ind() and then perform a GATT write to the correct attribute handle.

Thanks, PM_Dialog

1 month ago

BenjaminDu 135 points

Hi Dialog,

Thanks a lot for your answer and this is very helpful.

Benjamin