Xiao Sense BLE ISSUE - ZephyrOS

Hi Everyone,

I am trying to develop a simple application with the XIAO BLE Sense device, the idea is to send a BLE message when something hits the device. To achieve this, I wanted to configure the BLE to notify the event after connecting with the master. I problem I have is very simple but I cant figure out how to solve it, the problem is that I always have to Enable notifications on my phone in order to receive the notification, How can I change that to receive the message without the need to enable anything on the phone?? Thanks!!

First of all, let me summarize what I am using and what program I have uploaded to the device:

  • Hardware:
    • Xiao BLE Sense.
  • Software:
    • Visual Studio Code.
    • nRF Connect for VS Code Extension Pack (latest version).
    • nRF Connect SDK Toolchain v2.5.2
    • nRF Connect SDK v2.5.2
    • Zephyr OS.

I have used the Zephyr Example for BLE and I have the following piece of code:

/* Accel readings Service Declaration and Registration */
BT_GATT_SERVICE_DEFINE(accel_service,
BT_GATT_PRIMARY_SERVICE(BT_UUID_ACCELSERVICE),
BT_GATT_CHARACTERISTIC(BT_UUID_ACCELSERVICE_RX,
			       BT_GATT_CHRC_WRITE | BT_GATT_CHRC_WRITE_WITHOUT_RESP,
			       BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, 
                   NULL, on_receive, NULL),
BT_GATT_CHARACTERISTIC(BT_UUID_ACCELSERVICE_TX,
			       BT_GATT_CHRC_NOTIFY,
			       BT_GATT_PERM_READ ,//BT_GATT_PERM_READ,
                   NULL, NULL, NULL),
BT_GATT_CCC(on_cccd_changed,
        BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
);

int bt_ready(void) {
    return perform_bt_ready();
}

int my_service_init(void)
{
    int err = 0;
   
    memset(&data_rx, 0, MAX_TRANSMIT_SIZE);
    memset(&data_tx, 0, MAX_TRANSMIT_SIZE);
    
    return err;
}

void my_service_send(const uint8_t *data, uint16_t len)
{
    /* 
    The attribute for the TX characteristic is used with bt_gatt_is_subscribed 
    to check whether notification has been enabled by the peer or not.
    Attribute table: 0 = Service, 1 = Primary service, 2 = RX, 3 = TX, 4 = CCC.
    */
    const struct bt_gatt_attr *attr = &accel_service.attrs[3]; 

    struct bt_gatt_notify_params params = 
    {
        .uuid   = BT_UUID_ACCELSERVICE_TX,
        .attr   = attr,
        .data   = data,
        .len    = len,
        .func   = on_sent
    };

    // Check whether notifications are enabled or not
    if(bt_gatt_is_subscribed(my_connection, attr, BT_GATT_CCC_NOTIFY)) 
    {
        // Send the notification
	    if(bt_gatt_notify_cb(my_connection, &params))
        {
            printk("Error, unable to send notification\n");
        }
    }
    else
    {
        printk("Warning, notification not enabled on the selected attribute\n");
    }
}  

Thanks beforehand, sorry for the inconveniences and looking forward to hearing from you.

Kind regards.

Parents
  • Hi vgarcive,

    There is an old DevZone case on this topic and the answer is still valid now:
    RE: How to enable notification on the peripheral side?

    If you really need the notification working without having to be re-enabled from the client, you can use bonding. Note that when you have a dedicated phone app for your application, enabling notification is just one line of code, and a moment in real time, not user-recognizable at all.

    A more convoluted solution is to have the Server on the Central, and the Client on the Peripheral. That way, the data from the Peripheral is sent with a Write instead, not requiring Notification enabling. This approach is very rarely used and doesn't bring any big benefit though.

    Hieu

  • Hi Hieu,

    Thank you for the information given. I know that probably enabling the notifications on an app should be easy but I am kind of using a low code platform for the app so I do not have much control of the BLE, that was the reason behind asking this questions.

    Do you have a link where I can check how to properly do the bonding? I think I am going to explore that solution.

    Thank you!

  • Hi vgarcive,

    We have generic information about bonding here: Lesson 5 - Security in Bluetooth LE communication. This is part of our free online courses on DevAcademy.

    As for how to implement bonding on your platform, that is outside of my expertise, more so without knowing what platform it is. However, I am almost certain that implementing bonding is more complicated than adding a notification enabling.

  • Hi there,

    How low?

    You can use MIT app inventor and the notify on the BLE service and Alerts are almost Immediate.

    I have the Xiao nRF52840 Sense with the IMU onboard, Both notifications are sent to the MIT app instantaneously for Motion (if the device is moved or picked up) and FALL detection (tracks a free-fall ) and in the app indicates it's been dropped. I use the read and writes to set the sensitivity of each service and the read to verify. But it also could  be used to read the actual DATA from the IMU btw.

    HTH

    GL :-) PJ

    I use custom wav files also to indicate which event has occurred so If I'm not in the room I know.

Reply
  • Hi there,

    How low?

    You can use MIT app inventor and the notify on the BLE service and Alerts are almost Immediate.

    I have the Xiao nRF52840 Sense with the IMU onboard, Both notifications are sent to the MIT app instantaneously for Motion (if the device is moved or picked up) and FALL detection (tracks a free-fall ) and in the app indicates it's been dropped. I use the read and writes to set the sensitivity of each service and the read to verify. But it also could  be used to read the actual DATA from the IMU btw.

    HTH

    GL :-) PJ

    I use custom wav files also to indicate which event has occurred so If I'm not in the room I know.

Children
No Data
Related