Open luigi7up opened 1 month ago
@luigi7up you need to discover services first. This is not done automatically (or can using a connect parameter). Without this services cant be used
@farfromrefug hi, thank you for your reply... I¡m sorry for not providing the whole code where you can see that I'm calling the bluetooth.startScanning({})
method
I'll update my question above
@luigi7up i am.not talking about scanning. I am talking about discovering services and characteristics. It is mandatory. Look at the typings for how to do it either manually or through the connect method
@farfromrefug Hi! Thanks a lot for your help. It wasn’t immediately clear to me that even though I knew my SERVICE UUID
, I couldn’t send commands to it without first discovering it during the connect()
. Following your guidance, I was able to solve the issue by adding theautoDiscoverAll: true
parameter to the bluetooth.connect({})
call.
One thing I found a bit confusing is the lack of mention of service discovery in the README. If it’s necessary to discover services before interacting with them, shouldn’t the documentation include this process?
I’d be happy to contribute by opening a PR to improve this, but I want to fully understand it before doing so.
await bluetooth.connect({
UUID: peripheral.UUID,
autoDiscoverAll: true, // this is the line I added
onConnected: (peripheral) => {
peripheral.services.forEach(function (service) {
console.log("service found: " + JSON.stringify(service));
});
},
onDisconnected: () => {
//console.log("Disconnected successfuly to "+ peripheral.name);
//...
}
});
Now, the peripheral object holds services object and now you can use bluetooth.write({})
await bluetooth.write({
peripheralUUID: connectedPeripheral.UUID, // Use peripheralUUID instead of UUID
serviceUUID: MY_SERVICE_UUID,
characteristicUUID: CHARACTERISTIC_SERVO_COMMANDS_UUID,
value: [command]
});
@luigi7up you are right not everything is in the README. Please open A PR if you want to update it. This is the file to modify https://github.com/nativescript-community/ble/blob/master/packages/ble/blueprint.md. Keep in mind that i want users to actually read platform native docs. BLE is very specific to platforms and i dont think you can really start working with it using the N plugin if you dont know how it works on the native side. Thanks!
Hey! Sure. Would you mind pointing me in the direction of the platform native docs you had in mind. I assume you mean, for example, the docs for Android/BLE https://developer.android.com/develop/connectivity/bluetooth/ble/ble-overview and the same for iOS ?
Hey! Sure, I’ll definitely take a look at the file and work on a PR to update the README. I agree that having a solid understanding of the platform-native BLE docs is important. Just to clarify, are you referring to docs like Android BLE and the iOS equivalents? If so, I can see how they’re essential for learning the core concepts, but the code differs quite a bit from working with this plugin.
I think adding some references or context in the README would still be valuable to bridge that gap for users who might not have much experience with native BLE development. Thanks for the guidance!
@luigi7up maybe this one is better https://developer.android.com/develop/connectivity/bluetooth/ble/connect-gatt-server But yes those are the docs i am referring too
I’m currently building a NativeScript app that uses BLE to connect to an ESP32 microcontroller. The microcontroller initializes a BLE server with a name, a service UUID, and characteristic UUIDs, as shown in the code snippet below. My NativeScript app successfully connects to the BLE service, but when I attempt to write commands to the characteristic, I consistently receive a
service_not_found
error.Error I receive:
Additional Notes:
I would greatly appreciate any help or suggestions on how to resolve this issue. Thank you in advance!