xref: /nrf52832-nimble/packages/NimBLE-latest/apps/blemesh_models_example_1/README.md (revision 042d53a763ad75cb1465103098bb88c245d95138)
1*042d53a7SEvalZero### Bluetooth: Mesh OnOff Model
2*042d53a7SEvalZero
3*042d53a7SEvalZero
4*042d53a7SEvalZero#### Overview
5*042d53a7SEvalZero
6*042d53a7SEvalZeroThis is a simple application demonstrating a Bluetooth mesh multi-element node.
7*042d53a7SEvalZeroEach element has a mesh onoff client and server
8*042d53a7SEvalZeromodel which controls one of the 4 sets of buttons and LEDs .
9*042d53a7SEvalZero
10*042d53a7SEvalZeroPrior to provisioning, an unprovisioned beacon is broadcast that contains
11*042d53a7SEvalZeroa UUID. Each button controls the state of its
12*042d53a7SEvalZerocorresponding LED and does not initiate any mesh activity.
13*042d53a7SEvalZero
14*042d53a7SEvalZeroThe models for button 1 and LED 1 are in the node's root element.
15*042d53a7SEvalZeroThe 3 remaining button/LED pairs are in elements 1 through 3.
16*042d53a7SEvalZeroAssuming the provisioner assigns 0x100 to the root element,
17*042d53a7SEvalZerothe secondary elements will appear at 0x101, 0x102 and 0x103.
18*042d53a7SEvalZero
19*042d53a7SEvalZeroAfter provisioning, the button clients must
20*042d53a7SEvalZerobe configured to publish and the LED servers to subscribe.
21*042d53a7SEvalZero
22*042d53a7SEvalZeroIf a LED server is provided with a publish address, it will
23*042d53a7SEvalZeroalso publish its status on an onoff state change.
24*042d53a7SEvalZero
25*042d53a7SEvalZeroIf a button is pressed only once within a 1 second interval, it sends an
26*042d53a7SEvalZero"on" message. If it is pressed more than once, it
27*042d53a7SEvalZerosends an "off" message. The buttons are quite noisy and are debounced in
28*042d53a7SEvalZerothe button_pressed() interrupt handler. An interrupt within 250ms of the
29*042d53a7SEvalZeroprevious is discarded. This might seem a little clumsy, but the alternative of
30*042d53a7SEvalZerousing one button for "on" and another for "off" would reduce the number
31*042d53a7SEvalZeroof onoff clients from 4 to 2.
32*042d53a7SEvalZero
33*042d53a7SEvalZero#### Requirements
34*042d53a7SEvalZero************
35*042d53a7SEvalZero
36*042d53a7SEvalZeroThis sample has been tested on the Nordic nRF52840-PDK board, but would
37*042d53a7SEvalZerolikely also run on the nrf52_pca10040 board.
38*042d53a7SEvalZero
39*042d53a7SEvalZero#### Building and Running
40*042d53a7SEvalZero********************
41*042d53a7SEvalZero
42*042d53a7SEvalZeroPrior to provisioning, each button controls its corresponding LED as one
43*042d53a7SEvalZerowould expect with an actual switch.
44*042d53a7SEvalZero
45*042d53a7SEvalZeroProvisioning is done using the BlueZ meshctl utility. Below is an example that
46*042d53a7SEvalZerobinds button 2 and LED 1 to application key 1. It then configures button 2
47*042d53a7SEvalZeroto publish to group 0xc000 and LED 1 to subscribe to that group.
48*042d53a7SEvalZero
49*042d53a7SEvalZero```
50*042d53a7SEvalZerodiscover-unprovisioned on
51*042d53a7SEvalZeroprovision <discovered UUID>
52*042d53a7SEvalZeromenu config
53*042d53a7SEvalZerotarget 0100
54*042d53a7SEvalZeroappkey-add 1
55*042d53a7SEvalZerobind 0 1 1000                # bind appkey 1 to LED server on element 0 (unicast 0100)
56*042d53a7SEvalZerosub-add 0100 c000 1000       # add subscription to group address c000 to the LED server
57*042d53a7SEvalZerobind 1 1 1001                # bind appkey 1 to button 2 on element 1 (unicast 0101)
58*042d53a7SEvalZeropub-set 0101 c000 1 0 0 1001 # publish button 2 to group address c000
59*042d53a7SEvalZero```
60*042d53a7SEvalZero
61*042d53a7SEvalZeroThe meshctl utility maintains a persistent JSON database containing
62*042d53a7SEvalZerothe mesh configuration. As additional nodes (boards) are provisioned, it
63*042d53a7SEvalZeroassigns sequential unicast addresses based on the number of elements
64*042d53a7SEvalZerosupported by the node. This example supports 4 elements per node.
65*042d53a7SEvalZero
66*042d53a7SEvalZeroThe first or root element of the node contains models for configuration,
67*042d53a7SEvalZerohealth, and onoff. The secondary elements only
68*042d53a7SEvalZerohave models for onoff. The meshctl target for configuration must be the
69*042d53a7SEvalZeroroot element's unicast address as it is the only one that has a
70*042d53a7SEvalZeroconfiguration server model.
71*042d53a7SEvalZero
72*042d53a7SEvalZeroIf meshctl is gracefully exited, it can be restarted and reconnected to
73*042d53a7SEvalZeronetwork 0x0.
74*042d53a7SEvalZero
75*042d53a7SEvalZeroThe meshctl utility also supports a onoff model client that can be used to
76*042d53a7SEvalZerochange the state of any LED that is bound to application key 0x1.
77*042d53a7SEvalZeroThis is done by setting the target to the unicast address of the element
78*042d53a7SEvalZerothat has that LED's model and issuing the onoff command.
79*042d53a7SEvalZeroGroup addresses are not supported.
80