I gave the mesh networking several tries but at the moment it is simply not workable.
Mesh network is not workable.
At least not now.
IMHO the STSW-BNRG-Mesh is not workable for the maker community. There exists this library and there are also examples included. But these examples work only with Keil uVision or IAR Embedded Workbench and both of them are proprietary and require a licence. Both of them have also a free version where the code size is limited to 32 kB. But the example has a code size of about 70 kB. So could either buy a licence for about 3000 Euro or use the evaluation licence which is limited to a few days of usage. Both option are not usable for a reasonable development. The use of the library with an open source compiler like arm-gcc is prohibited because its a closed source library and only delivered as object file. And this object file only works with Keil uVision or IAR Embedded Workbench.
So at the moment this library is not usable for the maker community. There remains only the hope that in future releases of the library a version for the arm-gcc is also included.
Switch to X-CUBE-BLE1
Since the mesh networking was a dead end I decided to use the regular Bluetooth low energy library which is called X-CUBE-BLE1 (https://www.st.com/en/embedded-software/x-cube-ble1.html This is included in the CubeMX software and there are also examples included which work with the System Workbench for STM32 which uses arm-gcc Furthermore there is also a example included which works with the board which was one of the featured boards of this design challenge So the premises are now much better
BLE GATT profile
GATT is an acronym for the Generic Attribute Profile und this profile is used in BLE to exchange little peaces of data. They are called handles. One could also see it as the bluetooth way to read and write registers like it is implemented in many protocols in the automation world. For my application this seems to be perfect since I only want to read the status of several sensors via Bluetooth. Write access is not even necessary.
There is also a SensorDemo application example included in the library. This uses the GATT profile and simulates an accelerometer and an environmet sensor. After pushing the button on the evaluation board the sensor values or manipulated. So i started with this demo and examined the output via bluetooth.
BLE on Linux using BlueZ
For further testing I used a computer with Ubuntu 16.04 and Bluetooth 4.2 USB stick which is capable of Bluetooth low energy. The Bluetooth function comes with the BlueZ package. First you can scan for available Bluetooth devices with hcitool:
This shows the following output on my computer (one bluetooth device connected):
Devices: hci0 00:1A:7D:DA:71:14
Next scan for BLE devices within range:
sudo hcitool lescan
LE Scan ... 02:80:E1:00:34:12 BlueNRG
So 02:80:E1:00:34:12 is our device (the NUCLEO board).
You can display more information on this device with
sudo hcitool leinfo 02:80:E1:00:34:12
Requesting information ... Handle: 71 (0x0047) LMP Version: 4.1 (0x7) LMP Subversion: 0x3107 Manufacturer: ST Microelectronics (48) Features: 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
So now we are definitely sure that this is our device!
For further analysation we use gatttool and we use it in the interactive mode where we can send one command after one another to the same device. To setup the tool we use the command:
sudo gatttool -b 02:80:E1:00:34:12 -I
Then you have to connect with "connect". After successful connction the MAC address turns blue.
Then you can list the primary handles with "primary" or all handles with "char-desc". These handles are defined in the source code.
You can show the value of one handle (for example handle 0x001b) with "char-read-hnd 0x001b". This is the handle for the simulated humidity sensor and its value changes with every read.
You can see the output of all the commands in the following screenshot.
Next time I am going to change the values of the handles and connect real sensors.