nRF5 SDK for Mesh v4.2.0
Sensor example
You can test this example on the following devices: nRF52840, nRF52833, and nRF52832.
This example is not compatible with the nRF52810 device.

This example demonstrates how to use the Sensor model. It implements an emulated Motion Sensed sensor and shows how such a sensor can be used and controlled.

The example is composed of the following minor examples:

Note
The Sensor server example can also be used together with the Light LC example.

Table of contents

Hardware requirements

You need at least two compatible development kits for this example:

Additionally, you need one of the following for provisioning:

See Compatibility for information about the compatible development kits.


Software requirements

Depending on the provisioning method:

Note
Setting the Publish Period on the Sensor server when interacting with the boards is only possible if you use the mobile app for provisioning the examples.

Setup

You can find the source code of this example in the following folder: <InstallFolder>/examples/sensor

Button assignments


Testing the example

To test the sensor example, build the examples by following the instructions in Building the mesh stack.

After building is complete, use one of the following methods, depending on the preferred provisioning approach:

Evaluating using the static provisioner

See provisioner example testing section for detailed steps required to provision and configure the boards using the static provisioner.

Note
Using this provisioning method limits the amount of actions you can take when interacting with the boards.

Evaluating using the nRF Mesh mobile app

See Evaluating examples using the nRF Mesh mobile application 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:

The following model instances must be configured in the app for this example:

Once the provisioning with the mobile app is complete, you can start interacting with the boards.

Note
You can also configure the publish address of the second Sensor client model instance. To do this, repeat step 3 from binding nodes and all steps from setting publication.

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 start interacting with the examples using buttons or RTT, or both.

The publication behavior of the Sensor server depends on the following parameters:

Standard behavior when no Publish Period is set

Depending on your provisioning method:

Regardless of the provisioning method, when no Publish Period is set, all button presses on the server will result in sensor publications. The client will print the incoming sensor status messages to RTT, where you can monitor them using the RTT Viewer on the RTT output of the server. They will also be visible as received Sensor status messages on the client.

Custom publication behavior

You can change the publication parameters to see how this will affect the publication behavior.

Note
The steps in this section require you to set the Publish Period on the Sensor server. As of now, this is only possible if you choose to provision and configure the example using the nRF Mesh mobile app.
Step 1: Set periodic publication to 10 seconds (default cadence)
Set a Publish Period of 10 seconds on the server. Because a Publish Period is set, changing the sensor value does not result in sensor publications. Instead, the server publishes all sensor statuses on its periodic publication callback. The client receives publications every 10 seconds according to the Publish Period set.
Note
In this step, the cadence for the Motion Sensed property is using the default initial values. Next steps use custom cadence values.
Step 2: Set periodic publication to 60 seconds (custom cadence)
Set a Publish Period of 60 seconds on the server. Then, press Button 4 on the client. This sets the following custom cadence for the sensor:
Field Value
fast_period_exponent 7 (representing 2^7)
trigger_type 0
trigger_delta_down 1
trigger_delta_up 1
min_interval_exponent 1
fast_cadence_low 0
fast_cadence_high 49
The fast_cadence_high value exceeds the fast_cadence_low value, so Motion Sensed values in the closed interval [fast_cadence_low (0), fast_cadence_high (49)] will cause the server's sensor publication period to be the server's Publish Period divided by 2^n, where n is the fast_period_exponent (that is, 7). This fast period is constrained to a minimum interval by min_interval.
Step 3: Set a sensor value within fast cadence region (custom cadence)
Set the sensor value to 20. At the next periodic publication time, the server will find a Motion Sensed value of 20. As 20 is between 0 and 49, the server will begin to publish on a period of 60sec / 2^7 = 0.4687 sec. The client receives information about two messages per second while the motion sensor value remains between 0 and 49.
Step 4: Set a sensor value outside fast cadence region (custom cadence)
Set the sensor value to 50 or higher. When this value is first published by the periodic publication on the server, the periodic publication period will be set to 60 seconds (the configured Publish Period for the server). As long as the server's publications find Motion Sensed values of at least 50, the client receives one message per minute.
Note
The client's cadence message targets the sensor identified by property_id = 0x0042 (the Motion Sensed device property). When interacting with a multi-sensor server, the client can program each sensor to a unique cadence.

Documentation feedback | Developer Zone | Subscribe | Updated