Skip to content

BLECharacteristic::setValue always echoes writes from Central back to Central #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mlu opened this issue Aug 10, 2017 · 4 comments
Open

Comments

@mlu
Copy link
Contributor

mlu commented Aug 10, 2017

When playing around with MIDI characteristic I found that every note sent from a Central (iMac MIDI) was echoed back, that is not always what is wanted.

The reason is that the function setValue(const unsigned char value[], unsigned char length) that actually makes the change always invokes the listener callback. So when receiving a characteristic write from Central and we have writes without response the listener should not be invoked.

One possible way, that so far works for me is:

void BLECharacteristic::setValue(BLECentral& central, const unsigned char value[], unsigned char length) {
-- this->setValue(value, length);
++ if ( _properties & BLEWriteWithoutResponse ) {
++ this->_valueLength = min(length, this->_valueSize);
++ memcpy(this->_value, value, this->_valueLength);
++ }
++ else {
++ this->setValue(value, length);
++ }

this->_written = true;

BLECharacteristicEventHandler eventHandler = this->_eventHandlers[BLEWritten];
if (eventHandler) {
eventHandler(central, *this);
}
}

@sandeepmistry
Copy link
Owner

@mlu could you please provide a minimal sketch that demonstrates the issues, along with a step by step procedure to reproduce it. Thanks.

@mlu
Copy link
Contributor Author

mlu commented Aug 14, 2017

Link to the sketch:

https://drive.google.com/open?id=0BwkzMBFZwrYtc1NKZ1ppTFRtUjQ

midiCharacteristic is configured BLEWriteWithoutResponse.
The sketch does not send any midi data, it only receives. So there should be no output.

  1. Compiled and loaded to a Micro:Bit board.

  2. Connect to a BLE MIDI enabled computer
    On a Mac computer, open Tools : Sound/MIDI settings
    Double click Bluetooth Tool icon
    Connect to the MICRO:Midi ble unit

  3. Use some midi generator to send MIDI notes to the board and monitor the traffic
    Use MIDI Keys , a minimal virtual MIDI keyboard and route output to the MICRO:Midi
    Use MIDI Monitor to record output from MICRO:Midi and also spy in traffic to the board.

Now every MIDI message sent to to board will be echoed back to the computer, this is not done by the application code in the sketch but by the BLE transport layer.

@kargeor
Copy link

kargeor commented Dec 29, 2020

I have the same problem, please merge #174.

@kargeor
Copy link

kargeor commented Dec 29, 2020

I have confirmed it works with BLE MIDI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants