scratchfoundation / scratch-link

Device interoperability layer for Windows and MacOS
BSD 3-Clause "New" or "Revised" License
102 stars 83 forks source link

Unable to receive micro: bit uartWriteString with startNotifications #192

Open marron9999 opened 3 years ago

marron9999 commented 3 years ago

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 commented 3 years ago

Can a user only experience this with a custom extension?

marron9999 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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); }); }