This page outlines a step-by-step procedure which demonstrates how the RN4020 module can interface with a smartphone or tablet device using the standard Battery Service.
|Tool|| About|| Purchase|
This lab requires the following software tools:
A host is required to enter commands that configure the module to be a Peripheral device, enable the standard Device Information and Battery Services and begin advertising for connections. The following connections are required at a minimum:
Detailed Steps – RN4020 Device Under Test (DUT) – RN-4020-PICTail Card
Ensure that the minimum signal connections as shown in the diagram above are connected. If you are using the RN4020 PICTail, they are already connected.
After the RN4020 module has powered up and “CMD” is displayed on the terminal emulator, issue the “LS” command to display the current services that the RN4020 module enumerates and supports in the server role. The output of the LS command will be as follows:
In Tera Term, enter the “A” command to start advertisement.
The module will respond with "AOK" when advertising has begun.
Detailed Steps – iOS Device
Return to the terminal emulator to control the RN4020 directly to set the Battery Level to 99% using either of the following two commands:
The first command sets the value of characteristic Battery Level to be 99 (0x63) by addressing its UUID 0x2A19. The second command sets the value of characteristic Battery Level to be 99 (0x63) by addressing its handle 0x0018. The match between handle and UUID can be found by command “LS”. The handle value for each characteristic stays the same for the same set of server service settings. As long as the supported server services are not changed by command “SS”, the handles of the characteristics stay the same.
The app can also start notification on the Battery Level characteristic by moving the slider switch to the right as shown.
On the RN4020 side, a notification will output to the terminal application display as follows:
This output means the application tried to write the two byte value, 0x0001 (little endian over air makes it 0100), to the configuration handle of the Battery Level characteristic with the UUID 0x2A19 in the Battery Service with the UUID 0x180F, effectively enabling notification for this characteristic. Refer to Table 3.11: “Client Characteristic Configuration bit field definition” in Volume 3, Part G, Section 22.214.171.124 “Client Characteristic Configuration” of “Bluetooth Core Specification v4.1”, for details.
Return to the terminal emulator and Update the battery level to 50% on the RN4020 module by entering either of the following two commands:
After issuing either of the two commands, you will see that the battery level characteristic value in the app automatically updates to 0x32 (50 decimal) as shown:
This is because with an active notification, any update to the value of a characteristic on the server side will be notified to the client side.
On the module, when a server characteristic value is set, if notification/indication has been supported and started on such characteristic, in addition to the “AOK” message returned after issuing the “SHW” or “SUW” command, a second “AOK” message will be returned by the module if the transmission of notification/indication is successful; otherwise, message “NFail” will be sent.