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
- BLE Software Specification
- Getting Started with WME Bluetooth Low Energy Applications
Hardware Requirement
Tool | Quantity |
---|---|
Curiosity Board | 3 |
Micro USB cable | 2 |
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
- ANPS: Import and program
the precompiled
.hex
file located in “<Harmony Content Path>wireless_apps_ble\apps\ble_anps_app\hex\
” - ANPC: Import and program
the precompiled
.hex
file located in “<Harmony Content Path>wireless_apps_ble\apps\ble_anpc_app\hex\
” - 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
- Follow the steps mentioned in Running a Precompiled Example
- 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. - 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
- Refer BLE ANPS Demo Description.Note: The BLE connection status will be indicated by the green color of the RGB LED.
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
- Create a new MCC Harmony Project by selecting the device. For more details, refer to Creating a New MCC Harmony Project.
- Launch the MPLAB Code
Configurator from the toolbar as illustrated below. The project graph will open
with the default components.
Figure 3-252. MCC - 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 - All BLE ANPS related components will be added into the project graph. Accept dependencies or satisfiers by selecting Yes.
- 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.
- Change the SERCOM0
component settings as illustrated in the following figure.
Figure 3-254. SERCOM0 Configuration - 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 - For WBZ451
- Verify if the project
graph window has all the expected components, as illustrated in the
following figure:
Figure 3-256. Project Graph - Verify the
WBZ451-CURIOSITY Configuration for LED initialization as
illustrated in the following figure.
Figure 3-257. WBZ451-CURIOSITY Configuration
- Verify if the project
graph window has all the expected components, as illustrated in the
following figure:
- For WBZ351
- Verify if the project
graph window has all the expected components, as illustrated in the
following figure:
Figure 3-258. Project Graph - Verify the
WBZ351-CURIOSITY Configuration for LED initialization as
illustrated in the following figure
Figure 3-259. WBZ351-CURIOSITY Configuration
- Verify if the project
graph window has all the expected components, as illustrated in the
following figure:
-
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 - 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
Generating a Code
For more details on code generation, refer to the MPLAB Code Configurator (MCC) Code Generation.
Files Containing User Application Code
Source Files | Usage |
---|---|
app.c | Application State machine, includes calls for Initialization of all BLE stack (GAP,GATT, SMP, L2CAP) related component configurations |
app_ble_callbacks.c | All the event functions related to GAP, GATT, SMP and L2CAP events that user can use or modify . |
app_anps_callbacks.c | All the event functions related to ANPS event handles that user can use or modify. |
app_utility.c | Contains generic utility functions that serve the purpose of providing reusable, common functionalities that can be applied across various parts of a program. |
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.app.c
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 withintimeout_scan
seconds.APP_ANPS_STATE_WITH_BOND_SCAN
: application is prepared to reconnect withintimeout_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.
Variable |
Value |
Description |
---|---|---|
|
60 seconds |
The timeout of scanning without bond |
|
30 seconds |
The timeout of scanning with bond |
Firmware State |
LED behavior |
---|---|
|
All LEDs are OFF |
|
Blue LED Flashes once every 3 seconds. (ON: 50 ms, OFF: 2950 ms) |
|
Blue LED Flashes twice every 3 seconds. (ON: 50 ms, OFF: 50 ms) |
|
Blue LED Flashes twice every 1.5 seconds. (ON: 50 ms, OFF: 150 ms) |