vanbike-lib icon indicating copy to clipboard operation
vanbike-lib copied to clipboard

[Question] Usage

Open djfanatix opened this issue 3 years ago • 18 comments

Hi,

I like the idea. Could you give a bit more detailed info how to run the code? I tried the example in chrome and all the requested configs, but without succes

djfanatix avatar Nov 11 '20 18:11 djfanatix

First you have to get the encryption key from Vanmoof. The WebService is used for this (https://github.com/Poket-Jony/vanbike-lib/blob/main/example/index.html#L33). This only works in the browser if the CORS Policy is deactivated, see https://github.com/Poket-Jony/vanbike-lib#cors-policy (alternatively you can also execute this in NodeJS or manually with e.g. Postman). Now you can enter the encryption key in the example, connect to the bike (over WebBluetooth in Chrome) and unlock it. Note: Currently only the Electrified S / X 1 works perfectly. The S / X 2 or 3 should work partially, but I cannot test it.

Poket-Jony avatar Nov 12 '20 10:11 Poket-Jony

hi, i got my encryption key but the bluetooth does not seem to work i get:

Uncaught (in promise) Error: Bluetooth driver not available at _default._callee2$ (BluetoothService.js:33) at tryCatch (runtime.js:63) at Generator.invoke [as _invoke] (runtime.js:293) at Generator.next (runtime.js:118) at asyncGeneratorStep (asyncToGenerator.js:3) at _next (asyncToGenerator.js:25) _callee2$ @ BluetoothService.js:33 tryCatch @ runtime.js:63 invoke @ runtime.js:293 (anonymous) @ runtime.js:118 asyncGeneratorStep @ asyncToGenerator.js:3 _next @ asyncToGenerator.js:25 async function (async) (anonymous) @ (index):46

the WebBluetooth samples from the google site workt though! any tipps?

retroactive avatar Nov 14 '20 03:11 retroactive

okay the problem was that SSL HAS to be activated otherwise web bluetooth will not work o_O but now i get a window that chrome searches for the device and cannot find it. its an s3.

retroactive avatar Nov 14 '20 04:11 retroactive

Thanks for testing. The S3 has different service IDs and was therefore not displayed. I've already started expanding the S3 profile, but there is still a lot of work to be done. See https://github.com/Poket-Jony/vanbike-lib/commit/eb93d61c2875aea52f985f4557f500aef255b587

Poket-Jony avatar Nov 14 '20 12:11 Poket-Jony

ok let me know if you need a s3 to test, i live in berlin and i am a coder as well :)

retroactive avatar Nov 14 '20 14:11 retroactive

i tried your change.

  1. all service ids have to be lowercase it seems, with your change i just get an exception!
  2. i changed them all to lower case but sill cannot find the bike, where did u get those hex codes from=

retroactive avatar Nov 14 '20 23:11 retroactive

The service IDs and characteristics are from the Vanmoof app. I guess that some primary services have to be specified as optional services. The best thing is to simply specify the security service in the "createBluetoothConfigEntity()" method (https://github.com/Poket-Jony/vanbike-lib/commit/eb93d61c2875aea52f985f4557f500aef255b587#diff-c7f977ef208700181a5281c121bad51434fd86db96f26c6a6045e646c40e09aaR69) and see whether it is then displayed. The primary services act as filters for the Bluetooth devices.

Poket-Jony avatar Nov 15 '20 17:11 Poket-Jony

ok i read a little bit how things work ( i never did anything with bluetooth before) interestingly using only the SERVICE_SECURITY as filter does not work! but it works if i use just the SERVICE_BIKE_INFO service, then i find the bike. i see a bluetooth connect icon and then i get:

BluetoothService.js:123 Uncaught (in promise) Error: Characteristic "6acc5502-e631-4069-944d-b8ca7598ad50" not found!

this is part of the security service. my conclusion is the security service uuid must be wrong. sounds like CHARACTERISTIC_KEY_INDEX is used for authorization?

retroactive avatar Nov 15 '20 21:11 retroactive

ok i found one problem, u try to discover all services and swallow all errors, so i put in some more logging while discovering and id get this:

BluetoothService.js:52 try service 6acc5500-e631-4069-944d-b8ca7598ad50 BluetoothService.js:66 SecurityError: Origin is not allowed to access the service. Tip: Add the service UUID to 'optionalServices' in requestDevice() options. https://goo.gl/HxfxSQ

thats why its does not end up in _servicesAndCharacteristics[]

retroactive avatar Nov 15 '20 22:11 retroactive

ok now i defined everything as optional except the bike info service and apparently u have to do this in the beginng even though the method that fetches it later is called "getPrimaryService" o_O

now i get

BluetoothService.js:131 Uncaught (in promise) TypeError: Cannot convert undefined or null to object at Uint8Array.set () at _default._callee6$ (BluetoothService.js:131)

because the command is undefined in profile

createAuthenticateCommandEntity(passcode) { return (new BluetoothWriteCommandEntity(undefined, passcode))

retroactive avatar Nov 15 '20 23:11 retroactive

With the S1, some services also had to be defined as optional. In commit https://github.com/Poket-Jony/vanbike-lib/commit/cf7981fef3aa6e5a677fc50a17b03c85e763e601 I think that the problem with the undefined command should be fixed. If you want, you can create a pull request with your changes in GitHub.

Poket-Jony avatar Nov 16 '20 15:11 Poket-Jony

Great project. Very interested. I have S3 and also can help with testing or contributing. Let me know if I can help.

DmitriyNoa avatar Nov 21 '20 12:11 DmitriyNoa

ok i created a pull request, but even with your changes authentication does not seem to work, it does no throw any error but eventually the bikes disconnectes me and i cannot send any commands - btw i also never see a "connected" dot in the bike

hmmm i can see that he reads the challenge key correctly (2 bytes) and sets no command but sets the data and encrypts it, after writing that bike disconnects... any idea what wrong with authentication? i do not have the source code of the offical app ;)

retroactive avatar Nov 29 '20 02:11 retroactive

Thanks retroactive, I also got an S3 I merged your pull request in my repository, no errors now, but also no connect. :-(

TFreudi1 avatar Dec 27 '20 12:12 TFreudi1

unfortunately i only fixed the obvious errors, why the connect does not work only poket-joney can answer, or someone finds the source code? im not used to disassemble ios/android apps.

retroactive avatar Dec 27 '20 17:12 retroactive

I have it decompiled it's easy with apktool but the Service ID's in it are the same that you use.

TFreudi1 avatar Dec 28 '20 09:12 TFreudi1

I made my email adress visible, write me a note if you want to have a look by your self

TFreudi1 avatar Dec 28 '20 09:12 TFreudi1

are u still looking into it? did u find how to authenticate? you can send me the code or contact me at ********

retroactive avatar Jan 13 '21 17:01 retroactive