3.19 Bluetooth® Low Energy ANPS Applications

This section helps users enable the BLE Alert Notification Profile Server (ANPS) on the Curiosity board using the MCC. In this application example, BLE ANPS functions in the Central role and is paired with the BLE ANPC application which functions in the Peripheral role.

Users can either choose to run the precompiled application example .hex file on the Curiosity Board and experience the demo or go through the steps involved in developing this application from scratch.

These examples are incrementally structured upon one another. Recommendation is to follow the examples in order,by learning the basic concepts first and then progressing to the more advanced topics.

Recommended Reading

  1. BLE Software Specification
  2. Getting Started with WME Bluetooth Low Energy Applications
Note: Refer to the Getting Started with WME Bluetooth Low Energy Applications from Related Links

Hardware Requirement

Table 3-48. Hardware Requirement
ToolQuantity
 Curiosity Board3
Micro USB cable2

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. ANPS: Import and program the precompiled .hex file located in “<Harmony Content Path>wireless_apps_ble\apps\ble_anps_app\hex\
  2. ANPC: Import and program the precompiled .hex file located in “<Harmony Content Path>wireless_apps_ble\apps\ble_anpc_app\hex\
  3. For more information on the programming steps, refer to the Programming a Device in MPLAB IPE.
    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. ANPS: Open and program the application example “ble_anps_app_xxxx.X” where xxxx refer to device (for example: WBZ451, project file: ble_anpc_app_wbz451.X) located in “<Harmony Content Path>\wireless_apps_ble\apps\ble_anps_app\firmware” using MPLAB X IDE.
  3. ANPC: Open and program the application example “ble_anpc_app_xxxx.X” where xxxx refer to device (for example: WBZ451, project file: ble_anpc_app_wbz451.X) located in “<Harmony Content Path>\wireless_apps_ble\apps\ble_anpc_app\firmware” using MPLAB X IDE.

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

Demo Description

Developing this Application from Scratch using MCC

This section explains the steps required by a user to develop this application example from scratch using MCC

Note: It is recommended that new users of MCC to go through the MPLAB® Code Configurator (MCC) User's Guide.
  1. Create a new MCC Harmony Project by selecting the device. For more details, refer to Creating a New MCC Harmony Project.
  2. Launch the MPLAB Code Configurator from the toolbar as illustrated below. The project graph will open with the default components.
    Figure 3-252. MCC
  3. In the Device Resources window, expand Libraries > Harmony > Wireless > Application Services. Then, click the Plus Symbol to add the Alert Notification App Service Component to the project graph.
    Figure 3-253. Alert Notification App Service
  4. All BLE ANPS related components will be added into the project graph. Accept dependencies or satisfiers by selecting Yes.
  5. To enable digital and communication interfaces, refer to 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.
  6. Change the SERCOM0 component settings as illustrated in the following figure.
    Figure 3-254. SERCOM0 Configuration
  7. Change FreeRTOS component settings as illustrated in the following figure. For more details, refer to the link Configuring FreeRTOS from Getting Started with WME Bluetooth Low Energy Applications from Related Links.
    Figure 3-255. FreeRTOS Configuration
  8. For WBZ451
    1. Verify if the project graph window has all the expected components, as illustrated in the following figure:
      Figure 3-256. Project Graph
    2. Verify the WBZ451-CURIOSITY Configuration for LED initialization as illustrated in the following figure.
      Figure 3-257. WBZ451-CURIOSITY Configuration
  9. For WBZ351
    1. Verify if the project graph window has all the expected components, as illustrated in the following figure:
      Figure 3-258. Project Graph
    2. Verify the WBZ351-CURIOSITY Configuration for LED initialization as illustrated in the following figure
      Figure 3-259. WBZ351-CURIOSITY Configuration
  10. Select the Apple Notification App Service component. In the Configuration Options, the Enable Client Role option will be enabled by default. If it is not enabled, please enable the option. Additionally, ensure that the "Enable app code generation" option is enabled.
    Figure 3-260. Apple Notification App Service Component
    Figure 3-261. Apple Notification App Service Configuration
  11. Enabling the client role option in Alert Notification App Service component will configure BLE Stack component . Additionally, selecting the Enable App Code Generation option will generate the necessary application files related to the service during the code generation process. Verify the BLE Stack configuration.
    Figure 3-262. BLE Stack Configuration
    Figure 3-263. BLE Stack Configuration

Files Containing User Application Code

Source code for the application will be generated from the MCC interface by clicking Generate Code. User can add or edit the code in the highlighted files as shown below.
Figure 3-264. Files
Details on files that user can modify
Table 3-49. Source Files
Source FilesUsage
app.cApplication State machine, includes calls for Initialization of all BLE stack (GAP,GATT, SMP, L2CAP) related component configurations
app_ble_callbacks.cAll the event functions related to GAP, GATT, SMP and L2CAP events that user can use or modify .
app_anps_callbacks.cAll the event functions related to ANPS event handles that user can use or modify.
app_utility.cContains generic utility functions that serve the purpose of providing reusable, common functionalities that can be applied across various parts of a program.
Note: app.c is auto generated and has a state machine based application code sample. Users can use this template to develop their application. Main application logic is implemented in void APP_Tasks() function.
Figure 3-265. app.c
Figure 3-266. app.c

Firmware FSM (Finite State Machine)

This application firmware implements an ANP server on the Curiosity Board.

  • APP_ANPS_STATE_IDLE: application remains in the Idle mode.
  • APP_ANPS_STATE_SCAN: application is prepared to establish a new connection within timeout_scan seconds.
  • APP_ANPS_STATE_WITH_BOND_SCAN: application is prepared to reconnect within timeout_with_bond_scan seconds.
  • APP_ANPS_STATE_CONNECTING: application is currently in the process of establishing a connection.
  • APP_ANPS_STATE_CONNECTED: application is prepared to send commands notifications.
Figure 3-267. Finite State Machine
Table 3-50. Time Out Parameters

Variable

Value

Description

timeout_scan

60 seconds

The timeout of scanning without bond

timeout_with_bond_scan

30 seconds

The timeout of scanning with bond

Table 3-51. LED vs. State

Firmware State

LED behavior

APP_ANPS_STATE_IDLE

All LEDs are OFF

APP_ANPS_STATE_SCAN

Blue LED Flashes once every 3 seconds. (ON: 50 ms, OFF: 2950 ms)

APP_ANPS_STATE_WITH_BOND_SCAN

Blue LED Flashes twice every 3 seconds. (ON: 50 ms, OFF: 50 ms)

APP_ANPS_STATE_CONNECTED

Blue LED Flashes twice every 1.5 seconds. (ON: 50 ms, OFF: 150 ms)

References

  • Bluetooth Low Energy ANPS Application for: WBZ451
  • Bluetooth Low Energy ANPS Application for: WBZ351