Bluetooth: blesensor

Overview

Zephyr application demonstrating the BLE role via sensor data process.

Requirements

  • A Board with BLE support (stm32wb55rg)
  • X-NUCLEO-IKS01A1 Shield
  • ST BLE Sensor Application (Playstore/AppleStore)

Building and Running

  • Download the Project
  • Go into the "app" directory
  • Build it like this: $ west build -b nucleo_wb55rg
  • Set the shield on your board
  • Run the generated build in your board (drag and drop zephyr.bin generated or use pyocd)
  • Now, download ST BLE Sensor and open it
  • Select "CONNECT TO A DEVICE"
  • Select the device node that appears
  • Feel free to use the application services

List of services Available

  • Environmental service
  • Quaternions service: works with random values
  • E-Compass service: works with random values

Development Guideline

--------------------------------Some ST BLE Sensor Services UUID: --------------------------------

  • Bases service UUID
static struct bt_uuid_128 feature_service_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0xb4, 0x9a, 0xe1, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00);

  • Base feature UUIDs
static struct bt_uuid_128 environmental_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00);

static struct bt_uuid_128 acc_gyro_mag_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x00, 0x00, 0xE0, 0x00);

static struct bt_uuid_128 audio_ADPCM_Sync_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x40);

static struct bt_uuid_128 switch_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x20);

static struct bt_uuid_128 audio_source_localization_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x10);

static struct bt_uuid_128 audio_ADPCM_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x08);

static struct bt_uuid_128 mic_level_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04);

static struct bt_uuid_128 proximity_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02);

static struct bt_uuid_128 luminosity_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01);

static struct bt_uuid_128 acceleration_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x00, 0x00, 0x80, 0x00);

static struct bt_uuid_128 gyroscope_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x00, 0x00, 0x40, 0x00);

static struct bt_uuid_128 magnetometer_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00);

static struct bt_uuid_128 pressure_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00);

static struct bt_uuid_128 humidity_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00);

static struct bt_uuid_128 temperature_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00);

static struct bt_uuid_128 battery_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00);

static struct bt_uuid_128 temperature_bis_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00);

static struct bt_uuid_128 co_sensor_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00);

static struct bt_uuid_128 sd_logging_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00);

static struct bt_uuid_128 beam_forming_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x00, 0x08, 0x00, 0x00);

static struct bt_uuid_128 acceleration_event_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00);

static struct bt_uuid_128 free_fall_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00);

static struct bt_uuid_128 quaternions_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00);

static struct bt_uuid_128 mems_sensor_fusion_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x80, 0x00, 0x00, 0x00);

static struct bt_uuid_128 compass_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x40, 0x00, 0x00, 0x00);

static struct bt_uuid_128 motion_intensity_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00);

static struct bt_uuid_128 activity_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00);

static struct bt_uuid_128 carry_position_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00);

static struct bt_uuid_128 proximity_gesture_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00);

static struct bt_uuid_128 mems_gesture_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00);

static struct bt_uuid_128 pedometer_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00);

  • Debug service UUID
static struct bt_uuid_128 debug_service_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0xb4, 0x9a, 0xe1, 0x11, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00);

  • Debug feature UUIDs
static struct bt_uuid_128 debug_term_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x0e, 0x00, 0x01, 0x00, 0x00, 0x00);

* Error message characteristic static struct bt_uuid_128 debug_stderr_uuid = BT_UUID_INIT_128( 0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x0e, 0x00, 0x02, 0x00, 0x00, 0x00);

  • Config control service UUID
static struct bt_uuid_128 config_control_service_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0xb4, 0x9a, 0xe1, 0x11, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00);

  • Config control feature UUIDs
static struct bt_uuid_128 register_access_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x0f, 0x00, 0x01, 0x00, 0x00, 0x00);

static struct bt_uuid_128 feature_command_uuid = BT_UUID_INIT_128(

0x1b, 0xc5, 0xd5, 0xa5, 0x02, 0x00, 0x36, 0xac, 0xe1, 0x11, 0x0f, 0x00, 0x02, 0x00, 0x00, 0x00);

Adding new services

  • Copy an existing service file (environmental.c for example)
  • Make the appropriate change (You can compare two implemented services and see what changes):
    • replace the services uuid
    • replace BT Characteristics:
      • env_ccc_cfg_changed (by newServiceName_ccc_cfg_changed)
      • env_svc
      • feature_service_uuid
      • env_uuid.uuid
      • ...
    • replace indicate_env
    • ...
  • Implement your service update function
  • Set your service update function indicate (thread) function
  • Set the the thread time

Note

The update function of most services is extremely heavy. So it is easier to import the services libraries by linking them in Zephyr, and use the functions they offer than to re-implement them.

You can find the service libraries in ST FP-SNS-ALLMEMS1 application: https://www.st.com/en/embedded-software/fp-sns-allmems1.html It is also on this application that we base ourselves to implement our functions.

You can also get the ST BLE Application Code Source here: https://github.com/STMicroelectronics/BlueSTSDK_Android/tree/40fdcbf46955a025191589c6cff0e189bb17a2c9/BlueSTSDK