-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
206 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Connecting to mesh network | ||
|
||
How to connect to the network via GATT Proxy node. | ||
|
||
## Overview | ||
|
||
The ``MeshNetworkManager`` is transport agnostic. In order to send messages, the ``MeshNetworkManager/transmitter`` | ||
property needs to be set to a ``Bearer`` instance. The bearer is responsible for sending the messages | ||
to the mesh network. Messages received from the bearer must be delivered to the manager using | ||
``MeshNetworkManager/bearerDidDeliverData(_:ofType:)``. | ||
|
||
> Tip: To make the integration with ``Bearer`` easier, the manager instance can be set as Bearer's | ||
``Bearer/dataDelegate``. The nRF Mesh library includes ``GattBearer`` class, which implements | ||
the ``Bearer`` protocol. | ||
|
||
```swift | ||
let bearer = GattBearer(target: peripheral) | ||
bearer.delegate = ... | ||
|
||
// Cross set the delegates. | ||
bearer.dataDelegate = meshNetworkManager | ||
meshNetworkManager.transmitter = bearer | ||
|
||
// To get the logs from the bearer, set the logger delegate to the bearer as well. | ||
bearer.logger = ... | ||
``` | ||
|
||
Before the bearer can be used it needs to be open. For GATT Proxy bearer this means connecting | ||
over to the node over GATT. All mesh messages will be sent to the proxy using a GATT *Mesh Proxy Service* | ||
and will be relayed over ADV bearer to the network. | ||
```swift | ||
// Open the bearer. The GATT Bearer will initiate Bluetooth LE connection. | ||
bearer.open() | ||
``` | ||
|
||
## What's next | ||
|
||
With the bearer open it's finally time to send mesh messages: <doc:SendingMessages>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Creating and loading a network configuration | ||
|
||
How to load or create a network. | ||
|
||
## Overview | ||
|
||
The mesh configuration may be loaded from the ``Storage``, provided in the manager's initializer. | ||
```swift | ||
let loaded = try meshNetworkManager.load() | ||
``` | ||
If no configuration exists, this method will return `false`. In that case either create | ||
a new configuration, as shown below, or import an existing one from a file. | ||
```swift | ||
_ = meshNetworkManager.createNewMeshNetwork( | ||
withName: "My Network", | ||
by: "My Provisioner" | ||
) | ||
// Make sure to save the network in the Storage. | ||
_ = meshNetworkManager.save() | ||
``` | ||
|
||
Each time the network is modified, for example a new key is added, the configuration has to be saved | ||
using ``MeshNetworkManager/save()``. When a Configuration message is received, either a Status message | ||
sent as a response to a request, or a request sent from another node, the configuration is saved | ||
automatically. | ||
|
||
## What's next | ||
|
||
Now, with the mesh network manager and network set up we can provision a device: <doc:Provisioning>, | ||
or connect to the network using a GATT Proxy node: <doc:Connecting>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,41 @@ | ||
# Sending messages | ||
|
||
Bluetooth mesh is built on publish-subscribe paradigm. Each node can publish messages and receive messages | ||
sent by other nodes. | ||
How to send mesh messages using the manager. | ||
|
||
## Overview | ||
|
||
Bluetooth mesh is built on publish-subscribe paradigm. Each node can publish messages and receive messages | ||
sent by other nodes. | ||
|
||
The nRF Mesh library supports sending messages in two ways: | ||
1. From models on the local node, that are configured for publishing. | ||
2. Directly. | ||
|
||
The first method closely follows Bluetooth Mesh Profile specification, but is quite complex. | ||
The first method closely follows Bluetooth Mesh Protocol specification, but is quite complex. | ||
A model needs to be bound to an Application Key using ``ConfigModelAppBind`` message | ||
and have a publication set using ``ConfigModelPublicationSet`` or | ||
``ConfigModelPublicationVirtualAddressSet``. With that set, calling | ||
``ConfigModelPublicationVirtualAddressSet``. With that, calling | ||
``ModelDelegate/publish(using:)`` or ``ModelDelegate/publish(_:using:)`` will trigger a publication | ||
from the model to a destination specified in the ``Publish`` object. Responses will be delivered | ||
to ``ModelDelegate/model(_:didReceiveResponse:toAcknowledgedMessage:from:)`` of the model delegate. | ||
|
||
> Note: The above is demonstrated in the nRF Mesh app on the **Local Node** tab. To set up the components | ||
configure the models on the Primary and Secondary Element of the *local node* using **Network** tab. | ||
|
||
The second method does not require setting up local models. | ||
Use ``MeshNetworkManager/send(_:from:to:withTtl:using:)-48vjl`` or other variants of this method to send | ||
a message to the desired destination. | ||
|
||
> All methods used for sending messages in the ``MeshNetworkManager`` are asynchronous. | ||
> Note: The second method can be shown using nRF Mesh app either by sending messages directly | ||
from desired node's models' views in **Network** tab, or from **Groups** tab. | ||
|
||
Starting from nRF Mesh library version 4.0 all methods for sending messages come in 2 favors. | ||
One is using `async` functions, which block execution until either the message was sent (for | ||
``UnacknowledgedMeshMessage``), or the response was received (for ``AcknowledgedMeshMessage``). | ||
Those have to be called from a [`Task`](https://developer.apple.com/documentation/swift/task). | ||
The second favor is using completion handers instead, which are called in the same situations. | ||
Both types can be used interchangeably. | ||
|
||
## What's next | ||
|
||
Knowing basics learn how to configure nodes, including the local one: <doc:Configuration>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Usage | ||
|
||
How to start. | ||
|
||
## Overview | ||
|
||
The ``MeshNetworkManager`` is the main entry point for interacting with the mesh network. | ||
It can be used to create, load or import a Bluetooth mesh network configuration and send | ||
and receive messages. | ||
|
||
The snippet below demonstrates how to start. | ||
|
||
```swift | ||
// Create the Mesh Network Manager instance. | ||
meshNetworkManager = MeshNetworkManager() | ||
|
||
// If needed, customize network parameters using basic: | ||
meshNetworkManager.networkParameters = .basic { parameters in | ||
parameters.setDefaultTtl(...) | ||
// Configure SAR Receiver properties | ||
parameters.discardIncompleteSegmentedMessages(after: ...) | ||
parameters.transmitSegmentAcknowledgmentMessage( | ||
usingSegmentReceptionInterval: ..., | ||
multipliedByMinimumDelayIncrement: ...) | ||
parameters.retransmitSegmentAcknowledgmentMessages( | ||
exactly: ..., timesWhenNumberOfSegmentsIsGreaterThan: ...) | ||
// Configure SAR Transmitter properties | ||
parameters.transmitSegments(withInterval: ...) | ||
parameters.retransmitUnacknowledgedSegmentsToUnicastAddress( | ||
atMost: ..., timesAndWithoutProgress: ..., | ||
timesWithRetransmissionInterval: ..., andIncrement: ...) | ||
parameters.retransmitAllSegmentsToGroupAddress(exactly: ..., timesWithInterval: ...) | ||
// Configure message configuration | ||
parameters.retransmitAcknowledgedMessage(after: ...) | ||
parameters.discardAcknowledgedMessages(after: ...) | ||
} | ||
// ...or advanced configurator: | ||
meshNetworkManager.networkParameters = .advanced { parameters in | ||
parameters.defaultTtl = ... | ||
// Configure SAR Receiver properties | ||
parameters.sarDiscardTimeout = ... | ||
parameters.sarAcknowledgmentDelayIncrement = ... | ||
parameters.sarReceiverSegmentIntervalStep = ... | ||
parameters.sarSegmentsThreshold = ... | ||
parameters.sarAcknowledgmentRetransmissionsCount = ... | ||
// Configure SAR Transmitter properties | ||
parameters.sarSegmentIntervalStep = ... | ||
parameters.sarUnicastRetransmissionsCount = ... | ||
parameters.sarUnicastRetransmissionsWithoutProgressCount = ... | ||
parameters.sarUnicastRetransmissionsIntervalStep = ... | ||
parameters.sarUnicastRetransmissionsIntervalIncrement = ... | ||
parameters.sarMulticastRetransmissionsCount = ... | ||
parameters.sarMulticastRetransmissionsIntervalStep = ... | ||
// Configure acknowledged message timeouts | ||
parameters.acknowledgmentMessageInterval = ... | ||
parameters.acknowledgmentMessageTimeout = ... | ||
// And if you really know what you're doing... | ||
builder.allowIvIndexRecoveryOver42 = ... | ||
builder.ivUpdateTestMode = ... | ||
} | ||
// You may also modify a parameter using this syntax: | ||
meshNetworkManager.networkParameters.defaultTtl = ... | ||
|
||
// For debugging, set the logger delegate. | ||
meshNetworkManager.logger = ... | ||
``` | ||
|
||
## What's next | ||
|
||
The next step is to define the behavior of the manager determined by the set | ||
of models on the local node: <doc:LocalNode>. |
Oops, something went wrong.