nRF51 SDK - S210 SoftDevice
|
The ANT Relay Example demonstrates how to create a simple relay network. It uses ANT's multi-endpoint and proximity pairing capabilities to achieve this goal.
In this example, the state of an LED is relayed to all boards in a network. The boards are connected in a daisy chain to form the nodes of the network. There is no limitation on the number of nodes.
If the state of the LED on one board changes, this change is relayed to all other nodes in the network, so that the state of the LEDs on all boards change. The change can be initiated by pressing a button on one of the boards or by connecting to one of the nodes wirelessly, by using a mobile or computer application.
This example can be extended to fixed topologies that report status or accept commands, and require range extension through relay. This network configuration is appropriate for coin-cell operated networks and applications that require a mobile interface.
After startup or reset, each ANT node opens two master channels: one that is used for the relay network and one that allows for connections to a mobile or computer application, for example ANTware II.
The following table lists the channel parameters for the two master channels (numbers in parentheses denote the parameters that should be used to set the values):
Parameter | Relay channel | Mobile channel |
---|---|---|
Channel type | Master (0x10) | Master (0x10) |
Network | Public [E8, E4, 21, 3B, 55, 7A, 67, C1] | Public [E8, E4, 21, 3B, 55, 7A, 67, C1] |
Frequency | 2472 MHz | 2477 MHz |
Period | 4 Hz (8192) | 4 Hz (8192) |
Device number | Serial number | Serial number |
Device type | 1 | 2 |
Transmission type | 5 | 5 |
This example uses proximity pairing to establish a connection between the boards. Boards can be paired by pressing a button or by sending a pairing command over the mobile channel (see Message format for computer or mobile applications). Boards must be brought very close (< 10 centimeters) to each other to pair because the proximity bin setting is 1. After a connection to a node in the network is made, the state of the LED on the added board is relayed to all boards in the network.
If a slave channel loses connection with the master to which it is connected for longer than 30 seconds, it will close its channel and re-initialize the search proximity bin setting. To re-initialize the connection, press the appropriate button or send a pairing command over the mobile channel.
The relay channel is bi-directional, which means that the slave endpoint sends a status message back to the master for every message that it receives.
The following table lists the message format of the 8-byte message that is used to relay information between devices, both from master to slave and from slave to master:
Byte | Description |
---|---|
0 | Page number = 1 (ANT_RELAY_MAIN_PAGE) |
1 | LED status (1 = ON, 0 = OFF) |
2-5 | Counter (4 bytes, unsigned, little endian) that increases every time when the state of a LED changes. When the counter changes, the node changes the state of its LED to reflect the change. |
6 | Reserved = 0xFF |
7 | State of the slave channel (0 = unassigned, 1 = assigned, 2 = searching, 3 = tracking) |
Whenever the state of the LED changes, the counter will increase. All boards will then update the state of their LED to reflect the new state. The state of the LED can be changed by pressing a button on any of the boards or by sending the appropriate command over the mobile channel.
Instead of pressing buttons on a board to pair devices or change the state of a LED, you can also send commands from the computer or mobile application. The following table lists the message format that must be used to send commands to the boards:
Byte | Description |
---|---|
0 | Page number = 2 (ANT_MOBILE_COMMAND_PAGE) |
1 | Reserved = 0xFF |
2 | Command (1 = pair, 2 = LED on, 3 = LED off) |
3-7 | Reserved = 0xFF |
Commands can be sent using broadcast messages or acknowledged messages. If possible, you should always use acknowledged messages because this message type returns a notification stating if the command was received successfully or not.
The status message that is sent on the mobile channel to the computer or mobile application is almost identical to the status message that is sent on the relay channel. However, it does not use a counter.
The following table lists the message format of the status message that is sent on the mobile channel:
Byte | Description |
---|---|
0 | Page number = 1 (ANT_MOBILE_MAIN_PAGE) |
1 | LED status (1 = ON, 0 = OFF) |
2-6 | Reserved = 0xFF |
7 | State of the slave channel (0 = unassigned, 1 = assigned, 2 = searching, 3 = tracking) |
The name of the example is ant_relay_demo_pca10028. If you are not using the Keil Pack Installer, you can find the source code and project file of the example in the following folder: <InstallFolder>\Nordic\nrf51\examples\ant\experimental\ant_relay_demo
At least two development boards are required to use the ANT relay example. Optionally, if you want to use a mobile channel, an ANT USB dongle and ANTware II are required.
The following table lists the function of the buttons and LEDs on the development board:
Hardware | Function |
---|---|
Button 1 | Toggle the state of LED 1 |
Button 2 | Start pairing mode |
LED 1 | Toggled by button 1 |
LED 2 | Default: off. Is turned on when the slave endpoint receives a message. |
Test the ANT Relay Example application by performing the following steps:
Optionally, test the relay network by using a mobile channel by performing the following steps:
To turn the LED on, issue the following command as described in Message format for computer or mobile applications:
02-FF-02-FF-FF-FF-FF-FF
Use acknowledged messages to send commands.
To turn the LED off, issue the following command:
02-FF-03-FF-FF-FF-FF-FF
To initiate pairing, issue the following command:
02-FF-01-FF-FF-FF-FF-FF