This example demonstrates how the light controller uses the data coming from sensors and switches to control the lightness level of lights. After configuring and running this example, triggering Light On, Light Off, and occupancy events will change the brightness of the LED on your board.
This examples uses the Light LC Setup Server model. For more information about the Light LC Setup 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.
Table of contents
The example instantiates the following models:
The model instance uses the Light On and Light Off events and the data coming from occupancy and ambient sensors to adjust the lightness output, which is used to control the brightness of the LED using the APP_PWM library of the nRF5 SDK.
This example has the provisionee role in the network. It supports provisioning over Advertising bearer (PB-ADV) and GATT bearer (PB-GATT), and the Mesh Proxy Service (Server).
The Light LC Server model collects the data from occupancy and ambient sensors. When the light controller is enabled (see LIGHT_LC_DEFAULT_MODE), this model controls the lightness output. The Light Lightness Setup Server model is used to reflect the changes in the lightness output on the lightness level of lights through the binding between the Light LC Linear Output and Light Lightness Linear states of these two models.
The Light Lightness Setup Server model can be still controlled with the Light Lightness Client. However, the light controller is switched off automatically by the Light LC Server as soon any mesh message to change the lightness value is received (for example, the Light Lightness Set or any other message that can change the bound lightness state value). Use a Light LC Client model to turn the light controller on again.
For more information about the Light Lightness Setup Server model, see the light lightness example.
The Light LC Setup Server supports BLE Mesh Occupancy and Ambient Lux Level sensors – whose values are received through the Sensor Status messages. Sensors use the Sensor Server model to publish Sensor Status messages.
For demonstration purposes, this example includes a prebuilt HEX file with the occupancy sensor example.
The Light LC Setup Server model uses the Proportional Integral (PI) Feedback Regulator to control the lightness output. The PI Feedback Regulator reads the ambient light sensors' data at regular intervals.
For more information about the Light LC models, see Light LC models 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.
To test this example, you need to use the following additional software:
<InstallFolder>/examples/light_switch/client
<InstallFolder>/examples/light_lc/server/bin
.<InstallFolder>/examples/provisioner
You can find the source code of this example in the following folder: <InstallFolder>/examples/light_lc/server
The following LED and button assignments are defined for this example:
simple_hal
module.Instead of the buttons on the server boards, use the following RTT input:
RTT input | DK Buttons | Effect |
---|---|---|
1 | - | Toggles the values of the properties between 0 and the default values. |
4 | - | All mesh data is erased and the device is reset. |
- When sending the 1
RTT command, the following properties are toggled between 0 and the default values:
See Section 4.1.3 of the Mesh Device Properties v1.1, Mesh Device Properties XML, and Mesh Characteristics XML for more information about the properties.
RTT input | DK buttons | Effect |
---|---|---|
1 | 1 | Toggles the value of the emulated Presence Detect state. |
4 | 4 | All mesh data is erased and the device is reset. |
To test the light LC server example, first build this example and the light switch client example by following the instructions in Building the mesh stack.
MAX_PROVISIONEE_NUMBER
(in example_network_config.h
) to the number of boards available.MAX_AVAILABLE_SERVER_NODE_NUMBER
in nrf_mesh_config_app.h
of the client example to the value set for MAX_PROVISIONEE_NUMBER
.(0x0)
. This means that the light controller is turned off by default. To enable the light controller, the Light LC Client model is used. However, this example does not provide the Light LC Client example. For this reason, in this example the light controller is switched on by default. This has been done by changing the default value of the LIGHT_LC_DEFAULT_MODE in nrf_mesh_config_app.h
to (0x1)
.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 Light LC Setup Server
.nRF5x Mesh Switch
.nRF5x Mesh Occupancy Sensor
.The following model instances must be configured in the app for this example:
nRF5x Mesh Light LC Setup Server
server boards: Light LC Setup Server, Light LC Server, Generic OnOff Server instantiated on the second element.nRF5x Mesh Switch
client board: Generic OnOff Client.nRF Mesh Sensor Server
server board(s): Sensor Server.When setting publication with nRF Mesh mobile app:
Once the provisioning is complete, you can start Interacting with the boards.
Once the Light LC server board is started after provisioning, the light controller will be turned on. The example starts in the Standby state, and the LED 1 is driven to the lowest light level (either determined by the LIGHT_LC_SERVER_LIGHTNESS_STANDBY_PID propety or a higher level, because of the light feedback from the ambient light sensor that attempts to keep the light at a minimum illuminance determined by the LIGHT_LC_SERVER_AMBIENT_LUXLEVEL_STANDBY_PID property).
At this stage, you can interact with the Light LC server example by using the following options:
Light On
event.Occupancy On
event.Issuing the Occupancy On
event or the Light On
event triggers the following chain of events, as shown on the Figure 6.4 of the Mesh Model Specification:
You can issue new events at any time. This includes pressing Button 2 (or 4) on the Light switch client board to send a Light Off
event. In such case, the state machine will start transition depending on its current state machine state and will set the brightness of the LED 1 according to the lightness level defined for the current state.
The properties' values are controlled through the Light LC Client model.
The minimum lightness value at any state is determined by the following properties:
The illuminance value at any state is determined by the following properties:
If the values for these properties are not being detected by the PI Feedback Regulator, it will attempt to drive the LED 1 to a higher brightness.
If there were no reports from an ambient light sensor, the PI Feedback Regulator will not attempt to drive the LED 1, and the LED 1 will be driven by the state machine to the lightness values defined by the properties values specified for each state.
The factory default values of the lightness and illuminance properties are controlled through the corresponding defines:
The transition time is determined by the following properties:
You can make the state machine to transition instantly between the Standby and Run states. To do that, use RTT command 1
to toggle the properties of the state machine. After setting the corresponding properties to 0
you should notice the immediate transition between these states, when Occupancy On
or Light On
event is reported.
The factory default values of the time properties are controlled through the corresponding defines:
If you want to edit the factory default values, do this in nrf_mesh_config_app.h
of the Light LC server example. Follow instructions in Testing the example to re-build and re-provision the example.
By default, when occupancy has been reported by the Sensor Server model through Sensor Status messages, the transition will start immediately. You can postpone the transition by setting a delay time in LIGHT_LC_DEFAULT_PR_TIME_OCCUPANCY_DELAY_MS in nrf_mesh_config_app.h
of the LC server example.