Bluetooth Mesh is incredibly hard to program in C. Can we create simpler bindings in Rust? Maybe even a Domain-Specific Language?
Read this article first to understand Bluetooth Mesh basics:
Here's the Bluetooth Mesh Code from the open-source Apache NimBLE project that needs to be simplified. NimBLE is the open-source Bluetooth Stack for Mynewt, Zephyr and RIOT OSes.
-
BT Mesh runs on Models. A Model is a global schema that defines what kind of data the nodes will send and receive...
-
On-Off Model: Switch a light on or off, or query its state, for example
-
Level Model: Set or get the brightness of a light, for example
-
You can see the On-Off and Level Models defined here (yes this example has so many Models): https://github.com/apache/mynewt-nimble/blob/master/apps/blemesh_models_example_2/src/device_composition.c#L2691-L2749
-
Within On-Off and Level Models, there are Server Models and Client Models. Bluetooth Mesh supports Publish and Subscribe, so that the Servers can push data updates to the Clients
-
The Message Handlers for the Models are mapped here, so that a light knows how to switch itself on or off when it receives a message: https://github.com/apache/mynewt-nimble/blob/master/apps/blemesh_models_example_2/src/device_composition.c#L2546-L2689
-
Here's the Message Handler code that switches the light on/off: https://github.com/apache/mynewt-nimble/blob/master/apps/blemesh_models_example_2/src/device_composition.c#L289-L356
-
Here's the Message Handler code that queries the on/off status of the light: https://github.com/apache/mynewt-nimble/blob/master/apps/blemesh_models_example_2/src/device_composition.c#L174-L196
-
There seem to be Acknowledgement vs No Acknowledgement versions off the Message Handlers. Don't really think both are necessary. We should just support one type for now.
-
The code uses "Transitions" because real devices have some delay when changing on/off states. Again let's ignore this.
-
If you understand everything I've said so far... Now read the really terse official ReadMe from the NimBLE source :-) https://github.com/apache/mynewt-nimble/blob/master/apps/blemesh_models_example_2/README.md