Bluetooth Mesh Stack Event Handling#

The Bluetooth Mesh Stack for the Wireless Geckos is an event-driven architecture, where events are handled in the main while loop. The Bluetooth Mesh Stack runs on top of the Silicon Labs Bluetooth Stack.

Bluetooth LE versus Bluetooth Mesh Event#

The Bluetooth Mesh protocol is built on top of Bluetooth Low Energy. This means that a device running a Bluetooth LE Stack will be able to receive a Bluetooth Mesh PDU but will not be able to interpret the data that it contains. Nevertheless, a node or device can run both. In effect, it is possible to have Bluetooth LE and Bluetooth Mesh events treated separately in an application.

In this particular case, Bluetooth LE and Bluetooth Mesh event application state machines need to be separate. In other words, the Bluetooth LE and Bluetooth Mesh events cannot be treated in a unique switch-case statement.

At the application level, the Silicon Labs Bluetooth Mesh API provides a way to differentiate Bluetooth Mesh events from Bluetooth LE events. This is done through the Bluetooth Mesh listener.

The Bluetooth Mesh events in the stack are handled similarly to the regular Bluetooth LE events. In a freshly created project, the Bluetooth Mesh switch case statement is performed by the routine sl_btmesh_step() and the sl_btmesh_pop_event(&evt) - sl_btmesh_process_event(&evt) combo within it.

  • Application level event-handler for the Bluetooth LE Stack

void sl_bt_on_event(struct sl_bt_msg *evt)
{
  switch (SL_BT_MSG_ID(evt->header)) {
    ///////////////////////////////////////////////////////////////////////////
    // Add additional event handlers here as your application requires!      //
    ///////////////////////////////////////////////////////////////////////////

    // -------------------------------
    // Default event handler.
    default:
      break;
  }
}
  • Application level event-handler for the Bluetooth Mesh Stack

void sl_btmesh_on_event(sl_btmesh_msg_t *evt)
{
  switch (SL_BT_MSG_ID(evt->header)) {
    ///////////////////////////////////////////////////////////////////////////
    // Add additional event handlers here as your application requires!      //
    ///////////////////////////////////////////////////////////////////////////

    // -------------------------------
    // Default event handler.
    default:
      break;
  }
}

For more information on how events are processed in the Bluetooth LE Stack, refer to the Bluetooth Stack Event Handling.