Ble Kw41z multiple peripheral device at the same time

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Ble Kw41z multiple peripheral device at the same time

4,337 Views
mangramarco
Contributor III

Hello everyone,

i'm trying to modify a device with Ble stack inside a kw41z that use wireless uart nxp demo. My fw is ok and it "speaks" with a smartphone app without problems.

Now i need to program more of one device (currently only two devices) at the same times with two different smartphone that use the same app.

In the first step i changed the "shortened local name" in the gapAdStructure_t inside app_config.c file. I also changed the "public device address"in gBDAddress_c[6] array (BD_ADDR macro).

With this mods the app is able to view the different devices with the same firmware but it works bad. For example, if i switch on both devices and if i connect a device with app, when i switchoff the other, the first does a disconnection from the app.

i'm trying to change the uuid128 of the uuid_service_wireless_uart but i'm not shure if this a correct procedure.

How can i do?

Thank youMarco

Labels (2)
Tags (2)
15 Replies

3,944 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi Marco,

Just to confirm, For example, if i switch on both devices and if i connect a device with app, when i switchoff the other, the first does a disconnection from the app.

Are you connecting with 2 Phones? 

The example creates a random bd address with the same OUI. If you are connecting a 2 KW41 with 2 Phones, both connections are independent one of the other. Also, you could look at the disconnect reason in your code.

Regards,

Mario

0 Kudos

3,944 Views
mangramarco
Contributor III

Hello Mario,

thank you for response.

To be honest, i did an error. Now i explain better the issue:

i wrote an assignment of one flag for my code in callback function BleApp_ConnectionCallback  to be able to recognize when the device is or not connected. Maybe this is not a good solution because now i'm watching that this function is triggered even if i switch on/off other device but BEFORE a connection with a smartphone. I don't know if this is correct because the two devices are with different BD_ADDR and shortened name.

Moreover when i switch on the second device, the first stop his advertising so i can't see it in the app, i can see only the second device.

In the last post i wrote that it cause a disconnection from the smartphone but it was only an impression for my inattention because this mechanism occur only when the devices are disconnected from any smartphone.

When connection with smartphone is established the callback function is only executed when really occur a disconnection from the phone.

However now i need to use other flags or mechanism to recognize when my peripheral is or not connected/disconnected. Can you suggest me a way?

How can i see more devices into my app?

Thank you

Marco

0 Kudos

3,944 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi Marco,

I am not sure about your issue.

However now i need to use other flags or mechanism to recognize when my peripheral is or not connected/disconnected?

The BleApp_ConnectionCallback is generating an event depending on the connection status. gConnEvtConnected_c or gConnEvtDisconnected_c

You are trying to connect more devices to a specific Phone, the APP is not capable to connect with more devices at the same time, but you could create a second instance and try to connect to another device.

Regards,

Mario

0 Kudos

3,944 Views
mangramarco
Contributor III

Hello Mario,

thanks for the support.

i don't know if i correctly explained my issue.

However in this days i've observed with more attention the code with debugger.

I want to switch-on two of my devices and see them in a smarphone app. After i want to connect to only one of them.

The problem is that when i  switch-on the second device (with different BD_ADDR and shortened name) it would like to connect with the first! for this reason the BleApp_ConnectionCallback generate a gConnEvtConnected_c event and the first device disappear from the app view.

how can i see both devices in advertising status?


Marco

0 Kudos

3,944 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi Marco,

I am not following you. Is it possible that you could provide a diagram about what do you want to achieve?

how can i see both devices in advertising status? Depending on if you are entering in the BleApp_AdvertisingCallback, you could look at the adv status of your device.

Regards,

Mario

0 Kudos

3,940 Views
mangramarco
Contributor III

Hello Mario,

here an image that describe my situation. I hope it's clear.

Relatively to my issue, how can i do for avoid that  the second device activate an gConnEvtConnected_c event to the first device?

to give an additional information, if i switch-off the second device after gConnEvtConnected_c event in the first, it activate an gConnEvtDisconnected_c event and the first device is now visible in the app.

Thank you


Marco

Untitled Diagram (1).png

0 Kudos

3,940 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi Marco,

I think I am getting your issue.

The wireless example starts in scanning mode, and if you have one device in adv mode, the device will get connected.

I recommend starting in slave mode.

static void BleApp_Config()
{
.    
    mGapRole = gGapPeripheral_c;
.
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

You could also try to avoid entering the scan mode.

void BleApp_Start (gapRole_t mGapRole)
{
    switch (mGapRole)
    {
        //case gGapCentral_c:
        //{
         //   gPairingParameters.localIoCapabilities = gIoKeyboardDisplay_c;
         //   App_StartScanning(&gScanParams, BleApp_ScanningCallback, TRUE);
         //   break;
        //}
        case gGapPeripheral_c:
        {
            gPairingParameters.localIoCapabilities = gIoDisplayOnly_c;
            BleApp_Advertise();
            break;
        }
        default:
            break;
    }
}

After pressing the SW3, it will start in peripheral mode. As the MCU supports multiple connections that is the reason why you are only seeing DEV 2.

 Please be sure that both devices are in adv mode.

Regards,

Mario

3,940 Views
mangramarco
Contributor III

Hello Mario, thank you for the support.

I not solved with your suggestion but it was useful to find a solution.

In my code BleApp_Config is executed after BleApp_Start so changing the mGapRole inside it not makes any benefit.

So i changed mGapRole before BleApp_Start. In this manner the smarphone can see both devices but no one display the name and it can't connect to any device.

The smartphone can not see any device by removing App_StartScanning() function.

Anyway i had an idea to solve this issue. I changed the gScanParams filter policy from gScanAll to gScanWithWhiteList_c. My white list is empty so it can't see any advertising data.

Thank you

Marco

0 Kudos

3,940 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi Marco,

Are you sure that both devices are in ADV mode? Is the Red LED flashing?

What is the app that you are using in your phone? 

The App_StartScanning is for the Central Rol, so if you are not setting this role, this function will never be called.

 

You can save the bd_address of the phone, but it uses a random address, so you have to enable the privacy feature, and it should be after the first connection or you could do it manually.

Regards,

Mario

0 Kudos

3,940 Views
mangramarco
Contributor III

Hello Mario,

i'm not using a frdm board but a custom board with kw41z inside. The app used is also a custom app developed with android studio. thank you for your suggestion but for me is a good way to use an empty whitelist. I tried the penultimate suggestion but for me not work. Moreover i prefer to not save the bd_address of the phone in order to be able of use any smarphone.

Now i've a new questions: can i connect two device with only one smartphone? i'm reading a guide for kw36 but i found the follow line:

#if (gAppMaxConnections_c > 1)
#error "The application does not support more than 1 connection"
#endif

0 Kudos

3,940 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi Marco,

I hope you are doing great.

can I connect two devices with only one smartphone?

 

It will depend on your smartphone, it should support multiple connections. For example, your phone app could provide an option for scan new devices or create a second instance.

Regards,

Mario

3,940 Views
mangramarco
Contributor III

Thank you Mario. This was very useful. Now my app is able to communicate with two of my ble devices.

Speaking of this capability: can a central device send a broadcast message to all connected peripheral device ad the same time? Now i can only send a single message to a device one at time.

Thank you. 

0 Kudos

3,940 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi Marco,

I am thinking that you are looking for the BLE Mesh, unfortunately, our current stack doesn't support that feature.

In this case, the central device that is supporting the multiple connections must be switching between both devices.

Regards,

Mario

0 Kudos

3,862 Views
mangramarco
Contributor III

Hello,

i'm still looking for a real-time system with multiple ble devices connection. I need to use a tablet/smarphone as central. Since i can't use the ble mesh network, can you suggest me a way to do this task? I need a system that ensure me that the data received by ble peripheral devices are related by the same time.

Thank you
 

0 Kudos

3,940 Views
mangramarco
Contributor III

Thank you Mario for the reason

0 Kudos