Reputation: 86
I am trying to connect to a Buwizz V2 hub (and start a motor) via BLE on a windows machine via WebBluetooth in Google Chrome Browser. Tried it on Linux too, same results.
The API for the Buwizz is https://buwizz.com/BuWizz_2.0_API_1.3_web.pdf
The result of my code is
ble.html:21 discoverDevicesOrDisconnect
ble.html:31 discoverDevices
ble.html:40 > Name: BuWizz
ble.html:41 > Id: NtY+vKj4GR1vb/VowbQdJw==
ble.html:42 > Connected: false
ble.html:44 BluetoothDevice {id: 'NtY+vKj4GR1vb/VowbQdJw==', name: 'BuWizz', gatt: BluetoothRemoteGATTServer, ongattserverdisconnected: null, watchingAdvertisements: false, …}
ble.html:74 connecting
ble.html:77 Connected to NtY+vKj4GR1vb/VowbQdJw==
ble.html:78 connected=true
ble.html:96 discoverSvcsAndChars server=[object BluetoothRemoteGATTServer]
ble.html:102 Got 1 services
ble.html:109 Getting Characteristics for service 4e050000-74fb-4481-88b3-9919b1676e93
ble.html:111 > Service: 4e050000-74fb-4481-88b3-9919b1676e93
ble.html:117 >> Characteristic: 000092d1-0000-1000-8000-00805f9b34fb
ble.html:125 FINISHED DISCOVERY
ble.html:54 Try to startMotor
ble.html:55 Will send command to Characteristic:000092d1-0000-1000-8000-00805f9b34fb
ble.html:56 Characteristic has writeWithoutResponse ability:true
ble.html:60 Motor command ->16,127,127,127,127,0
ble.html:85 Try to set Powerlevel
ble.html:86 Will send command to Characteristic:000092d1-0000-1000-8000-00805f9b34fb
ble.html:87 Characteristic has writeWithoutResponse ability:true
ble.html:97 Power command ->17,4
So I can discover and connect to the device, find the Service 4e050000-74fb-4481-88b3-9919b1676e93
, find the characteristic 000092d1-0000-1000-8000-00805f9b34fb
and check that is has writeWithoutResponse
.
Since the motor is not running after sending the command, I have obviously made something wrong.
And I guess that it is somewhere around here:
console.log("Try to startMotor");
console.log("Will send command to Characteristic:" + motor_characteristic.uuid);
console.log("Characteristic has writeWithoutResponse ability:" + motor_characteristic.properties.writeWithoutResponse);
let full_ahead_command_data = new Uint8Array;
full_ahead_command_data = Uint8Array.of(0x10, 0x7F, 0x7F, 0x7F, 0x7F, 0x00);
console.log('Motor command ->' + full_ahead_command_data);
motor_characteristic.writeValueWithoutResponse(full_ahead_command_data.buffer)
.then(_ => { })
.catch(error => {
console.log('Error: ' + error);
alert('Error: ' + error);
return;
});
I checked the hub and motor with the official app. Both are working fine, so i would appreciate hints where I made something wrong or made a wrong assumption.
Upvotes: 2
Views: 319
Reputation: 176
I was in the same situation (BuWizz v2, no error message but no movement), and it took me a fair bit of trial and error, but I got mine to work.
The key for me was to use "write with response", aka simply "write". Even though the API docs say "No response is generated", and indeed there's nothing to be communicated back from the BuWizz, using "write without response" doesn't work.
I used the same connection parameters as you did:
50:FA:AB:5C:48:1F
4e050000-74fb-4481-88b3-9919b1676e93
000092d1-0000-1000-8000-00805f9b34fb
Then issue two write comments, one after the other:
0x10 0x7F 0x7F 0x7F 0x7F 0x00
0x11 0x02
And it goes brrrrr.
References:
In addition to the API PDF you linked to above, I've found it insightful to search for "BuWizz" on GitHub. The results include a number of projects, using different programming languages. This one for instance if fairly straightforward to read:
And here is a document written by someone who reverse-engineered the Bluetooth protocol, it mostly includes the same info as the official API PDF you linked to, but also gives some details about differences between different minor versions of the BuWizz 2:
https://github.com/imurvai/brickcontroller2/blob/master/BuWizz_protocol.md
Upvotes: 0