4.3 Bluetooth® Low Energy Custom Protocol Application

This section assists users in generating a demo application using the BLE custom protocol application service component and also helps them verify the generated demo application. This example demonstrates the implementation of a BLE custom protocol server application.

Users have the option to either run the precompiled application example .hex file on the WBZ451 or WBZ351 Curiosity Board to experience the demo, or to follow the steps required to develop this application from the beginning.

These examples are designed to build upon each other incrementally. It is recommended to follow the examples in sequence, starting with the basic concepts and gradually advancing to more complex topics.

Recommended Reading

  1. BLE Software Specification
  2. Getting Started with WME Bluetooth Low Energy Applications
  3. Bluetooth® Low Energy Custom Protocol Application Service Component
  4. Project Generation with Bluetooth® Low Energy Custom Protocol App Service Component
Note: Refer to these sections from Related Links

Hardware Required

Table 4-9. Hardware Required
ToolQty
WBZ451 or WBZ351 Curiosity Board1
Micro USB cable1
Android/iOS Smartphone1

Software Requirement

  • MPLAB X IPE: For programming the precompiled hex file.

  • MPLAB X IDE: For programming the application example.
  • Teraterm: Terminal Emulator for displaying UART output.

Programming the Precompiled Hex File or Application Example

Programming the .hex File using MPLAB X IPE

  1. Precompiled .hex file is located in “<Harmony Content Path>\apps\ble_cps_app\hex” folder.
  2. For more information on the programming steps, refer to the Programming a Device in MPLAB IPE section.
    Note: Users must choose the correct device and tool information.

Programming the Application using MPLAB X IDE

  1. Follow the steps mentioned in Running a Precompiled Example
  2. Open and program the application example “ble_cps_app_xxxx.X” where xxxx refer to device (for example: WBZ451, project file: ble_cps_app_wbz451.X) located in “<Harmony Content Path>\wireless_apps_ble\apps\ble_cps_app\firmware” using MPLAB X IDE

For more details on finding the Harmony content path, refer to Installing the MCC Plugin.

Demonstration

This application illustrates the implementation of a BLE custom protocol on the Curiosity board. The on-board RGB LEDs and UART serve as the user interface during the demonstration.

UART Settings

  • Baud Rate/Speed: 921600 bps
  • Parity: None
  • Data Bits: 8
  • Stop Bits: 1
  • Flow Control: None
  • Character Encoding: UTF-8

LED Behavior: The user can turn ON/OFF the Red, Green, and Blue LEDs in the RGB LED of the WBZ451 Curiosity Development Board through a packet that has a start delimiter, opcode, length, and end delimiter using BLE GATT client app

Testing

  1. Connect the WBZ451/WBZ351 Curiosity Board to the PC and program it with the precompiled .hex file or the specified application example.
  2. Open TeraTerm and configure as mentioned below:

    Terminal Settings

    • Baud Rate/Speed: 921600 bps
    • Parity: None
    • Data Bits: 8
    • Stop Bits: 1
    • Flow Control: None
  3. Reset the board. After reset, the device will be advertising device name “ble_cps_app".
  4. Launch the Microchip Bluetooth Data (MBD) application on the mobile device.
    1. Open the BLE Connect sub-application and initiate a scan for devices by selecting START SCAN.
    2. Look for the device labeled as “ble_cps_app” in the scan results.
    3. Establish a connection with the device, refer to the following figure for guidance on the demonstration.
    Figure 4-16. Scan and Connect
  5. Once the BLE connection is established, select Generic Information from the service list and navigate through the app as illustrated in the following figure to compose and send a hex packet to the device.
    Figure 4-17. Select Characteristic
  6. To enable notifications, click on the notification icon. Users can send a hex packet by entering the hex value in the hex tab, as illustrated in the figure below. There are two commands available:
    • One to turn the Red, Green, and Blue LEDs in the RGB LED ON/OFF
    • Another to retrieve the LED status.
    The response will be sent as a notification. In the demo application, the delimiter is 7E. Command A1 is used to set the LED state, while command A2 is used to retrieve the LED state. The end delimiter is EF. To set the Red, Green, and Blue LEDs ON/OFF, a 3-byte payload is used with the hex value 0x01 to turn ON and 0x00 to turn OFF. When retrieving the LED status, no specific payload is required, so the payload length can be set to zero.
    1. To set the LED state and turn the Red, Green, and Blue LEDs ON/OFF, use the hex packet (For example, 7EA103010000EF to turn ON Red LED). There is no specific response for this command.
    2. To retrieve the LED state and check the status of the Red, Green, and Blue LEDs, use the hex packet (For example, 7EA200EF). The response will be sent as a notification for this command (For example, 010000 indicates Red LED is ON), as illustrated in the following figure.
    Note: On the WBZ351 Curiosity board, users can control only the GREEN LED by sending the command 7EA103000100EF. Commands intended to control the RED or BLUE LEDs, such as 7EA103010000EF for the RED RGB LED, will not affect the RGB LED status on the WBZ351 Curiosity board. These commands will only change the state of the GPIO pins (PB0/PB5). Similarly, a status response of 010000 indicates the state of GPIO Pin PB0.
    Figure 4-18. Send Packet
  7. The user can view the received payload in the TeraTerm console, as illustrated in the following figure.
    Figure 4-19. Console

Developing the Application from Scratch using MCC

Refer to the steps outlined in the Project Generation with Bluetooth® Low Energy Custom Protocol App Service Component from Related Links section for application creation. To develop an RGB LED ON/OFF demonstration application using a custom protocol, proceed as follows:
  1. Configure the customized service and custom protocol app service as illustrated in the following figure. For byte selection, choose OPCODE and set the number of commands to 2.
    Figure 4-20. Configure Customized Service
    Figure 4-21. Configure Custom Protocol App Service
  2. Set up the LEDs in the System Hardware Definition as illustrated in the image below. For instructions on configuring the debug console, refer to the section Enabling Digital Input/Output and Communication Interfaces Through System Hardware Definition (SHD) component in Getting Started with WME Bluetooth Low Energy Applications from Related Links.
    Figure 4-22. Configure LEDs