This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Unique Characteristics for each peripheral using Multiperipheral SD

I am developing an application in which my device will have multiple android phones connected to it. Currently I have it working with one peripheral and after having upgraded to SDK13, I am looking at adding more peripherals.

My device has a service which contains 6 characteristics, 3 of these I would like the value to be shared between all devices, and 3 need to have unique values for each connection.

Having the shared characteristics is no problem, and it works just as shown in the multiperipheral example but, how can I get the values of the other 3 to be unique to each connection?

EDIT 29/06/17

image description

Above is an image to try and show what I'd like to achieve. The two peripheral devices are connected to my relay device. The 2 smart phones are connected to my relay device as centrals and they discover the relay device has an active_device characteristic and an active_device_data characteristic.

Each smart phone is able to set and read their own unique value of active_device, which tells the Relay device which peripheral that smart phone wants the data for. So, Smart phone one has set active_device to 1, to get the device_data from Peripheral devce 1 forwarded to it via the active_device_data characteristic, and the same for Smart phone 2 and peripheral device 2.

Currently I have not figured out how to allow smart phone one and two to choose different active devices. If I write a one to active_device using smart phone 1, then do a read with smart phone 2, it reads active_device as 1. Is there a way I can have different values of active_device for each connection?

Parents
  • FormerMember
    0 FormerMember

    The example "Experimental: BLE Relay Example" show the behavior you want, I would recommend you to take a look at it.

    Update 30.06.2017: As far as I can see the are two challenges.

    1) Relate the correct devices together, for instance "Peripheral_1" with "Smart phone 1": Different ways to identify peripherals: advertised device name, device_address, have a custom characteristic with an ID. But that will be application dependent.

    2) Direct data between the correct devices: For simplicity, let's assume that the relations between the devices are set up the following way:

    Peripheral_1 <---> Smart Phone 1: PERIPHERAL_CONN_HANDLE_1 <--> CENTRAL_CONN_HANDLE_1

    Peripheral_2 <---> Smart Phone 2: PERIPHERAL_CONN_HANDLE_2 <--> CENTRAL_CONN_HANDLE_2

    Incoming data from a peripheral can then be directed to the correct central the following way:

    static void on_ble_central_evt(const ble_evt_t * const p_ble_evt)
    {
        ble_gatts_hvx_params_t hvx_params;
        ...
        case BLE_GATTC_EVT_HVX: 
    	
             // 1) Find out which peripheral that transmitted the data, redirect the data
             //    to the correct central.				
    		peripheral_conn_handle = p_gap_evt->conn_handle;
    	        if(peripheral_conn_handle == PERIPHERAL_CONN_HANDLE_1)
    			{
    				central_conn_handle == CENTRAL_CONN_HANDLE_1;
    			} else if (peripheral_conn_handle == PERIPHERAL_CONN_HANDLE_2) 
    			{ 
    				central_conn_handle == CENTRAL_CONN_HANDLE_2;
    			}
    			
                // 2) Transmit the received data to the correct central:
               
               // set  hvx_params
    	
    			err_code = sd_ble_gatts_hvx(central_conn_handle, &hvx_params);
                ...
    }
    

    The same analogy can be used for writing/reading of values. In my opinion, the key is that the relay device knows which central and peripheral devices that communicate with each other.

  • FormerMember
    0 FormerMember in reply to FormerMember

    I got a little confused on this last one, could you draw an image so that it is easier to understand the "concept"?

Reply Children
No Data
Related