Skip to content

Commit 39a20a3

Browse files
author
Catalin Ioana
authored
[pymesh-ble] Changed in Pymesh BLE name pages, modified the OnOff exa… (#264)
* [pymesh-ble] Changed in Pymesh BLE name pages, modified the OnOff example
1 parent 1900e5f commit 39a20a3

File tree

3 files changed

+105
-47
lines changed

3 files changed

+105
-47
lines changed

config.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ theme = "doc-theme"
381381
weight = 30
382382

383383
[[menu.main]]
384-
name = "BLE Mesh"
384+
name = "Pymesh BLE"
385385
url = "/tutorials/all/ble_mesh/"
386386
identifier = "tutorials@all@ble_mesh"
387387
parent = "tutorials@all"
@@ -829,7 +829,7 @@ theme = "doc-theme"
829829
weight = 60
830830

831831
[[menu.main]]
832-
name = "BLE Mesh"
832+
name = "Pymesh BLE"
833833
url = "/firmwareapi/pycom/network/bluetooth/BLE_Mesh/"
834834
identifier = "firmwareapi@pycom@network@bluetooth@BLE_Mesh"
835835
parent = "firmwareapi@pycom@network@bluetooth"

content/firmwareapi/pycom/network/bluetooth/BLE_Mesh.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
---
2-
title: "BLE_Mesh"
2+
title: "Pymesh BLE"
33
aliases:
44
- firmwareapi/pycom/network/bluetooth/BLE_Mesh.html
55
- firmwareapi/pycom/network/bluetooth/BLE_Mesh.md
66
---
77

8-
The BLE_Mesh library provides support for connecting to a BLE Mesh Network with various Server and Client models. Currently, Node cannot be configured as Provisioner.
9-
The library is under development, its current limitations:
10-
11-
- Only one Element (primary) can be added to the Node.
12-
- Supported Models:
13-
* Configuration Server Model (automatically generated together with primary Element)
14-
* Generic OnOff Server Model
15-
* Generic OnOff Client Model
16-
* Generic Level Server Model
17-
* Generic Level Client Model
18-
* Sensor Server Model
19-
* Sensor Client Model
20-
21-
- Supported OOB authentication types:
22-
* No OOB
23-
* Output OOB
24-
25-
- Supported Node Features:
26-
* GATT Proxy
27-
* Relay
28-
29-
- Recommended Mobile Applications:
30-
* nRF Mesh (iOS and Android)
31-
* Silicon Labs Bluetoth Mesh (iOS)
32-
* ST BLE Mesh (Android)
33-
* EspBLEMesh (Android)
8+
The Pymesh BLE library provides support for connecting to a BLE Mesh Network with various Server and Client models.
9+
10+
For examples, please check the section [Pymesh BLE Examples](/tutorials/all/ble_mesh).
11+
12+
Pymesh BLE features:
13+
14+
* Supported Models:
15+
* Configuration Server Model (automatically generated together with primary Element)
16+
* Generic OnOff Server Model
17+
* Generic OnOff Client Model
18+
* Generic Level Server Model
19+
* Generic Level Client Model
20+
* Sensor Server Model
21+
* Sensor Client Model
22+
* Supported OOB authentication types:
23+
* No OOB
24+
* Output OOB
25+
* Supported Node Features:
26+
* GATT Proxy
27+
* Relay
28+
* Only one Element (primary) can be added to the Node.
29+
* Node cannot be configured as Provisioner and a mobile application should be used for Provisioning process
30+
* nRF Mesh (iOS and Android)
31+
* Silicon Labs Bluetoth Mesh (iOS)
32+
* ST BLE Mesh (Android)
33+
* EspBLEMesh (Android)
3434

3535

3636
## Methods of BLE_Mesh class
@@ -42,7 +42,7 @@ Initializes the BLE Mesh module with the pre-configured Elements and Models.
4242
* `name` is the name which will be used to identify the device during Provisioning
4343
* `auth` is the Out-Of-Band (OOB) method. Currently `BLE_Mesh.OOB_OUTPUT` is supported. Without specifying this argument, `NO_OOB` will be used during provisioning.
4444
* `callback` is the callback to be registered. It must have the following arguments:
45-
* `event` returns current event of provisioning.
45+
* `event` returns current event of provisioning.
4646
* `oob_pass` returns the generated pass in case of `BLE_Mesh.OOB_OUTPUT`.
4747

4848
#### BLE_Mesh.set_node_prov(bearer=BLE_Mesh.PROV_NONE, *)
@@ -85,7 +85,7 @@ Gets the State of the Sensor Model. If called from Server Model, returnes with S
8585

8686
* `addr` is the address of the remote Node to send the update message.
8787
* `app_idx` is the index of one of the registered Application IDs to use when sending out the message.
88-
* `state_type` is the type of Get State.
88+
* `state_type` is the type of Get State.
8989

9090
#### BLE_Mesh_Model.set_state(state, addr=BLE_Mesh.ADDR_ALL_NODES, app_idx=0, state_type=None)
9191

@@ -94,15 +94,15 @@ Sets the State of the Sensor Model. If called from Server Model, sets State dire
9494
* `state` is the new value to update the current value with.
9595
* `addr` is the address of the remote Node to send the update message.
9696
* `app_idx` is the index of one of the registered Application IDs to use when sending out the message.
97-
* `state_type` is the type of Set State.
97+
* `state_type` is the type of Set State.
9898

9999
#### BLE_Mesh_Model.status_state(addr=BLE_Mesh.ADDR_ALL_NODES, app_idx=0, state_type=None)
100100

101101
Calling this function only makes sense when the BLE_Mesh_Model is a Server Model. It sends a Status message with the State to the Client Model(s).
102102

103103
* `addr` is the address of the remote Node to send the update message.
104104
* `app_idx` is the index of one of the registered Application IDs to use when sending out the message.
105-
* `state_type` is the type of Status State.
105+
* `state_type` is the type of Status State.
106106

107107
## Constants
108108

content/tutorials/all/ble_mesh.md

Lines changed: 72 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,35 @@
11
---
2-
title: "BLE Mesh"
2+
title: "Pymesh BLE Examples"
33
aliases:
44
- tutorials/all/ble_mesh.html
55
- tutorials/all/ble_mesh.md
66
- chapter/tutorials/all/ble_mesh
77
---
88

9-
BLE Mesh module enables many-to-many device connections, based on Bluetooth module.
9+
Pymesh BLE module enables many-to-many device connections, based on the Bluetooth module.
10+
11+
For the API, please check the section [Pymesh BLE API](/firmwareapi/pycom/network/bluetooth/ble_mesh/).
12+
13+
## Generic OnOff Example
14+
Generic OnOff model is one of the simplest model in BLE Mesh.
15+
16+
This model illustrates the light-switches (OnOff Client) and light-bulbs (OnOff Server). In other words, the Client can send on/off commands to one/all nodes, and the Server is records state changes based on these commands.
17+
18+
### OnOff Server
19+
20+
OnOff Server has one boolean State. Server can Get, Set or send Status about this State to Client(s).
21+
22+
In the example below, during Provisioning, `Output OOB` can be selected. LED is yellow in case of Not-provisioned, and green in case of Provisioned state.
23+
24+
Changing the State of Server, LED's light is green or red.
1025

11-
# Generic OnOff Example
12-
Generic OnOff model is simplest model in BLE Mesh, makes it possible for one device to switch other devices on or off.
13-
## OnOff Server
14-
OnOff Server has one bool State. Server can Get, Set or send Status abour this State to Client(s). In the example below, during Provisioning, `Output OOB` can be selected, LED is yellow in case of Unprovisioned, and green in case of Provisioned state. Changing the State of Server, LED's light is green or red.
1526
```python
1627
from network import Bluetooth
1728
import pycom
1829
import time
1930

31+
BLE_Name = "OnOff Server 18"
32+
2033
def blink_led(n):
2134
for x in range(n):
2235
pycom.rgbled(0xffff00) # yellow on
@@ -41,6 +54,7 @@ def prov_callback(event, oob_pass):
4154
# Green if Provisioned
4255
pycom.rgbled(0x007f00)
4356
if(event == BLE_Mesh.PROV_OUTPUT_OOB_REQ_EVT):
57+
print("Privisioning blink LED num:", oob_pass)
4458
blink_led(oob_pass)
4559

4660
# BLE Mesh module
@@ -57,19 +71,39 @@ element = BLE_Mesh.create_element(primary=True, feature=BLE_Mesh.GATT_PROXY)
5771
model_server = element.add_model(BLE_Mesh.GEN_ONOFF, BLE_Mesh.SERVER, callback=server_cb)
5872

5973
# Initialize BLE_Mesh
60-
BLE_Mesh.init("Pycom OnOff Server", auth=BLE_Mesh.OOB_OUTPUT, callback=prov_callback)
74+
BLE_Mesh.init(BLE_Name, auth=BLE_Mesh.OOB_OUTPUT, callback=prov_callback)
6175

6276
# Turn on Provisioning Advertisement
6377
BLE_Mesh.set_node_prov(BLE_Mesh.PROV_ADV|BLE_Mesh.PROV_GATT)
78+
79+
print("\nBLE Mesh started")
80+
print(BLE_Name, "waits to be provisioned\n")
81+
82+
"""
83+
# After this node was provisioned
84+
# Current state can be read using
85+
model_server.get_state()
86+
"""
6487
```
6588

66-
## OnOff Client
67-
Client can Get or Set State of Server. In case of Get, or Server Status call, Client Gets the Status through the Model's callback.
89+
### OnOff Client
90+
91+
Client can Get or Set State of Server. In case of Get, or Server Status, Client Gets the Status through the Model's callback.
92+
6893
```python
6994
from network import Bluetooth
7095
import pycom
7196
import time
7297

98+
BLE_Name = "OnOff Client 17"
99+
100+
def blink_led(n):
101+
for x in range(n):
102+
pycom.rgbled(0xffff00) # yellow on
103+
time.sleep(0.3)
104+
pycom.rgbled(0x000000) # off
105+
time.sleep(0.3)
106+
73107
def client_cb(new_state, event, recv_op):
74108
print("CLIENT | State: ", new_state)
75109

@@ -80,6 +114,9 @@ def prov_callback(event, oob_pass):
80114
if(event == BLE_Mesh.PROV_COMPLETE_EVT):
81115
# Green if Provisioned
82116
pycom.rgbled(0x007f00)
117+
if(event == BLE_Mesh.PROV_OUTPUT_OOB_REQ_EVT):
118+
print("Privisioning blink LED num:", oob_pass)
119+
blink_led(oob_pass)
83120

84121
# BLE Mesh module
85122
BLE_Mesh = Bluetooth.BLE_Mesh
@@ -95,15 +132,34 @@ element = BLE_Mesh.create_element(primary=True, feature=BLE_Mesh.GATT_PROXY)
95132
model_client = element.add_model(BLE_Mesh.GEN_ONOFF, BLE_Mesh.CLIENT, callback=client_cb)
96133

97134
# Initialize BLE_Mesh
98-
BLE_Mesh.init("Pycom OnOff Client", callback=prov_callback)
135+
BLE_Mesh.init(BLE_Name, auth=BLE_Mesh.OOB_OUTPUT, callback=prov_callback)
99136

100137
# Turn on Provisioning Advertisement
101138
BLE_Mesh.set_node_prov(BLE_Mesh.PROV_ADV|BLE_Mesh.PROV_GATT)
139+
140+
print("\nBLE Mesh started")
141+
print(BLE_Name, "waits to be provisioned\n")
142+
143+
"""
144+
# After this node was provisioned
145+
# transmit the change of state broadcasting in the Mesh
146+
147+
model_client.set_state(False, 0xFFFF)
148+
model_client.set_state(True, 0xFFFF)
149+
150+
# or to a unique server
151+
model_client.set_state(False, 3)
152+
model_client.set_state(True, 5)
153+
154+
"""
102155
```
103-
# Sensor Example
156+
157+
## Sensor Example
104158
In case of Sensor Models, State of Server can be modified only by Server itself, Client can only Get the State by calling Client's Get, or by Servers Status call, but cannot modify the Server's State.
105-
## Sensor Server
106-
In this example Server takes a time measurement every 1 seconds, and send a Status message every 5 seconds, after became Provisioned.
159+
160+
### Sensor Server
161+
In this example Server takes a time measurement every 1 seconds, and send a Status message every 5 seconds, after it was provisioned.
162+
107163
```python
108164
from network import Bluetooth
109165
import pycom
@@ -157,8 +213,10 @@ Timer.Alarm(read_sensor, 1, periodic=True)
157213
Timer.Alarm(status_sensor, 5, periodic=True)
158214
```
159215

160-
## Sensor Client
216+
### Sensor Client
217+
161218
Sensor Client is looking for measurements, as Server sends Status every 5 seconds. Between these calls, Client can Get message any time.
219+
162220
```python
163221
from network import Bluetooth
164222
import pycom

0 commit comments

Comments
 (0)