Skip to content
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

Unable to receive micro: bit uartWriteString with startNotifications #192

Open
marron9999 opened this issue Mar 19, 2021 · 4 comments
Open
Labels
question Further information is requested

Comments

@marron9999
Copy link

Expected Behavior

Hope to be able to receive with _onMessage (base64)

Actual Behavior

_onMessage (base64) is not called

Steps to Reproduce

const BLEUUID = {
service: '6e400001-b5a3-f393-e0a9-e50e24dcca9e', // UART_SERVICE
rxChar: '6e400002-b5a3-f393-e0a9-e50e24dcca9e', // TX_Characteristic
txChar: '6e400003-b5a3-f393-e0a9-e50e24dcca9e' // RX_Characteristic
};

this._ble.read(BLEUUID.service, BLEUUID.rxChar, true, this._onMessage);

Operating System and Browser

Windows 10 Home 20H2 (19042.867)
Google Chrome 89.0.4389.90(Official Build)(64 bit)

NOTE:

Bluetooth Developer Studio Level 3 Profile Report
TX Characteristic
Notify Excluded
Indicate Mandatory

scratch-link/Windows/scratch-link/BLESession.cs
private async Task StartNotifications(GattCharacteristic endpoint, string encoding)

            var notificationRequestResult = await endpoint.WriteClientCharacteristicConfigurationDescriptorAsync(
                    GattClientCharacteristicConfigurationDescriptorValue.Notify);

Can be received by changing "Notify" to "Indicate"

@BryceLTaylor BryceLTaylor added the question Further information is requested label Mar 25, 2021
@BryceLTaylor
Copy link

Can a user only experience this with a custom extension?

@marron9999
Copy link
Author

marron9999 commented Mar 25, 2021

Yes. I made another extension. It is scratch-microbit extension with the UUID changed to UART.
OK: this._ble.write(BLEUUID.service, BLEUUID.txChar, data, "base64", true)
NG: this._ble.read(BLEUUID.service, BLEUUID.rxChar, true, this._onMessage)
   => this._onMessage is not called.
I want you to be able to with "Notify" and "Indicate".

@eqot
Copy link

eqot commented Apr 6, 2021

rxChar and txChar are different from the comments.

rxChar: '6e400002-b5a3-f393-e0a9-e50e24dcca9e', // TX_Characteristic
txChar: '6e400003-b5a3-f393-e0a9-e50e24dcca9e' // RX_Characteristic

Are these correct?

@marron9999
Copy link
Author

marron9999 commented Apr 6, 2021

Yes, please see code of scratch extension

https://github.com/marron9999/sc3-mbitlink/blob/master/scratch-vm/src/extensions/scratch3_mbitlink/index.js

const BLEUUID = {
service: '6e400001-b5a3-f393-e0a9-e50e24dcca9e', // UART_SERVICE
rxChar: '6e400002-b5a3-f393-e0a9-e50e24dcca9e', // TX_Characteristic
txChar: '6e400003-b5a3-f393-e0a9-e50e24dcca9e' // RX_Characteristic
};

this._ble.read(BLEUUID.service, BLEUUID.rxChar, true, this._onMessage)
this._ble.write(BLEUUID.service, BLEUUID.txChar, data, "base64", true)

scratch-vm/src/io/BLE.js

read (serviceId, characteristicId, optStartNotifications = false, onCharacteristicChanged = null) {
const params = {
serviceId,
characteristicId
};
if (optStartNotifications) {
params.startNotifications = true;
}
if (onCharacteristicChanged) {
this._characteristicDidChangeCallback = onCharacteristicChanged;
}
return this.sendRemoteRequest('read', params)
.catch(e => {
this.handleDisconnectError(e);
});
}

write (serviceId, characteristicId, message, encoding = null, withResponse = null) {
const params = {serviceId, characteristicId, message};
if (encoding) {
params.encoding = encoding;
}
if (withResponse !== null) {
params.withResponse = withResponse;
}
return this.sendRemoteRequest('write', params)
.catch(e => {
this.handleDisconnectError(e);
});
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants