BLE read/write "dynamic" characteristics problem.

16 Apr 2017

Hi all, I started play with BLE API. I have analyzed some examples and I have a general problem to solve.

In all examples, characteristics are static (mapped to some memory area; integer, boolean, strings variables). And what about a more complicated case? Let's assume that a standard example with LED control is a bit more complicated. We do not want to store current LED status in variable, we want to read LED state at the moment when the read characteristic request arrive. This is general problem with fully “virtual” (dynamic) characteristics. Suppose that my characteristic is state of complicate machine controlled by BLE commands and its state is reported by dynamically created reports. I know that we have “onDataWritten” callback function and its easy to start special process to change state of my “engine”. But what about using 'onDataRead' callback function? In this (callback) function I can run some procedure to create report, but I can't put result into the callback function parameters because it is of type "const". How to send the newly created report in response to read characteristic request? Some ideas (or examples:)?

TIA

18 Apr 2017

I found a solution but not simple. I copied the BLE_LoopbackUART example program and developed a simple BLE_Console service. The program works like a typical UART console (or telnet / RPC server). Receive text command, processes, produces a result that returns as a series of NOTIFY packets. This way, you can execute a command and receive a result in the same way as during a typical telnet session. Commands and results can be "any length" (a few KB). Unfortunately, the BLE_LoopbackUART example program compiled for NRF52_DK with online compiler does not work well with my smartphone (Galaxy S5). Discovery process ended with internal error. BUT the same example downloaded independently and compiled (mbed 5, GCC on Linux) with some feature ignored is OK. My .mbedignore file content:

mbed-os/features/net/*
mbed-os/uvisor-mbed-lib/*
mbed-os/frameworks/*
mbed-os/features/mbedtls/*
mbed-os/rtos/*
mbed-os/features/netsocket/*
mbed-os/features/frameworks/greentea-client/source/*
mbed-os/features/frameworks/greentea-client/*
mbed-os/features/frameworks/utest/*
mbed-os/features/frameworks/unity/source/*
mbed-os/features/frameworks/unity/*