This example demonstrates how you can use mesh messages and events from the Light Lightness model API to control the brightness of the LED on your board.
The example is composed of two minor examples that use the Light Lightness Client/Setup Server model:
For more information about the Light Lightness Client/Server model, see also the Bluetooth SIG's Mesh Model Overview.
For provisioning purposes, the example requires either the provisioner example that is provided in the Provisioner example or the nRF Mesh mobile app.
Both the Light Lightness Setup Server and Light Lightness Client examples have the provisionee role in the network. They support provisioning over Advertising bearer (PB-ADV) and GATT bearer (PB-GATT) and also support Mesh Proxy Service (Server). Read more about the Proxy feature in GATT provisioning and Proxy.
Table of contents
The Light Lightness Client example has a provisionee role in the network. It implements two instances of the Light Lightness Client model. These instances are used to control the brightness of the LED 1 on the servers, the range of supported lightness levels, and the default lightness value after the servers' boot-up.
The Light Lightness Setup Server example has a provisionee role in the network. It implements one instance of the Light Lightness Setup Server model.
This model instance is used to receive the lightness level and change the brightness of the LED 1 on the server board, whenever the Light Lightness Actual or Light Lightness Linear state is changed. A change in the Light Lightness Actual state is reflected in the Light Lightness Linear state, and the other way around.
The model instance uses the APP_PWM library of the nRF5 SDK to control the brightness of the LED. To map the lightness level to the allowed range of the PWM ticks, the value of the Light Lightness Actual state is converted to the value of the Generic Level state.
The Light Lightness Client model is used for manipulating the following states associated with the peer Light Lightness Setup Server model:
More information about the Light Lightness models can be found in the Light Lightness model documentation.
You need at least two supported development kits for this example:
Additionally, you need one development kit for the provisioner if you decide to use the static provisioner example. For details, see software requirements.
See Compatibility for the supported development kits.
Depending on your choice of the provisioning method:
<InstallFolder>/examples/provisioner
You can find the source code of this example in the following folder: <InstallFolder>/examples/light_lightness
simple_hal
module.RTT input | DK Button | Effect |
---|---|---|
1 | - | The brightness of the LED 1 is decreased in large step. |
2 | - | The brightness of the LED 1 is increased in large step. |
4 | - | All mesh data is erased and the device is reset. |
RTT input | DK Button | Effect |
---|---|---|
1 | Button 1 | The actual lightness value is increased in large steps and the Light Lightness Set Unacknowledged message is sent. |
2 | Button 2 | The actual lightness value is decreased in large steps and the Light Lightness Set Unacknowledged message is sent. |
3 | Button 3 | The actual lightness value in a linear scale is increased in large steps and Light Lightness Linear Set Unacknowledged message is sent. |
4 | Button 4 | The actual lightness value in a linear scale is decreased in large steps and Light Lightness Linear Set Unacknowledged message is sent. |
5 | - | The Light Lightness Last Get message is sent to request the last lightness value. |
6 | - | The Light Lightness Default Get message is sent to request the default lightness value. |
7 | - | The Light Lightness Range Get message is sent to request the range of supported lightness levels. |
8 | - | The Light Lightness Get message is sent to request the actual lightness value. |
9 | - | The Light Lightness Linear Get message is sent to request the actual lightness value in linear scale. |
a | - | The default light lightness value is increased and the Light Lightness Default Set Unacknowledged message is sent. |
b | - | The internal default light lightness value is decreased and the Light Lightness Default Set Unacknowledged message is sent. |
c | - | The internal minimum value of lightness levels range is increased and the Light Lightness Range Set Unacknowledged message is sent. |
d | - | The internal minimum value of lightness levels range is decreased and the Light Lightness Range Set Unacknowledged message is sent. |
e | - | The internal maximum value of lightness levels range is increased and the Light Lightness Range Set Unacknowledged message is sent. |
f | - | The internal maximum value of lightness levels range is decreased and the Light Lightness Range Set Unacknowledged message is sent. |
g | - | The internal actual lightness value in a linear scale is set to 0 and the Light Lightness Linear Set message is sent. |
h | - | Switches the client instance to be used for sending messages. |
To test the light lightness example, build the examples by following the instructions in Building the mesh stack.
MAX_PROVISIONEE_NUMBER
(in example_network_config.h
) to the number of boards available and rebuild the provisioner example.After building is complete, use one of the following methods, depending on the preferred provisioning approach:
Complete the following steps:
If the provisioner encounters an error during the provisioning or configuration process for a certain node, you can reset the provisioner to restart this process for that node.
See the information on the main Examples page for detailed steps required to provision and configure the boards using the nRF Mesh mobile app.
The following naming convention is used in the app:
nRF5x Mesh Lightness Setup Server
.nRF5x Mesh Lightness Client
.The following model instances must be configured in the app for this example:
nRF5x Mesh Lightness Setup Server
server boards: Light Lightness Setup Server, Light Lightness Server.nRF5x Mesh Lightness Client
client board: Light Lightness Client.Once the provisioning is complete, you can start interacting with the boards.
Once the provisioning and the configuration of the client node and of at least one of the server nodes are complete, you can press buttons on the client or send command numbers using the RTT Viewer to observe the changes in the brightness of the LED 1 on the corresponding server boards.
There is a set of message types available for this demonstration:
See LED and button assignments section for the full list of available commands.
If any of the devices is powered off and then back on, it will remember its flash configuration and rejoin the network. It will also restore values of the Light Lightness states. For more information about the flash manager, see Flash manager.
You can control the lightness value of the LED 1 using the RTT commands 1
- 4
or the buttons 1 - 4 on the board. Use the RTT commands 7
and 8
to retrieve the current lightness value in the perceived (Actual) lightness or the measured (Linear) lightness value accordingly.
To set the lightness value to 0
, use the RTT command g
.
For more information about the difference between the Actual and the Linear lightness values, see Mesh Model Specification appendix A.2.
You can change how the lightness value will be restored during a power-up sequence. This can be done by controlling the Generic OnPowerUp state instantiated by the Light Lightness Setup Server model.
The following table describes how the lightness value will be restored:
On PowerUp value | Lightness value |
---|---|
0 | 0 |
1 | The value of the Light Lightness Default state is used if it is not a zero. Otherwise, the Light Lightness Last state will be used. |
2 | Last known value for the Light Lightness Actual before power down. |
Use the RTT commands 9
and a
to change the Light Lightness Default state, and the RTT commands 4
and 5
to retrieve the current last and default values. See LED and button assignments for additional commands.
The factory default values for these states are controlled through the following defines:
If you want to edit the factory default values, do this in nrf_mesh_config_app.h
of the Light Lightness Setup Server example. Follow instructions in Testing the example to re-build and re-provision the example.
You can restrict the range of the lightness value by changing the Light Lightness Range state. The new value of the Light Lightness Range state will be reflected in the Light Lightness Actual state at the next lightness value change.
Use RTT commands c
, d
, e
, and f
to change the Light Lightness Range state, and the RTT command 6
to retrieve the current range. See LED and button assignments for additional commands.
The factory default values for the minimum and maximum possible range values are controlled through LIGHT_LIGHTNESS_DEFAULT_RANGE_MIN and LIGHT_LIGHTNESS_DEFAULT_RANGE_MAX values in the nrf_mesh_config_app.h
file of the Light Lightness Setup Server example.
In addition to the parameters described in the previous sections, you can also set the factory default transition time in milliseconds when changing the lightness levels. To do this, redefine the LIGHT_LIGHTNESS_DEFAULT_DTT value of the Generic Default Transition Time state in the nrf_mesh_config_app.h
file of the Light Lightness Setup Server example.