I'm trying to set up notify so that my BLE with sensor can send data to my android phone. My embedded code is based off of the example for Custom HRM on Adafruit's site (https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide/custom-hrm ) and the code for flutter is based off flutter blue's example
for (final BluetoothService service in services) {
if(service.uuid == widget.serviceID){
for (final BluetoothCharacteristic characteristic in service.characteristics) {
if(characteristic.uuid == widget.charID) {
await characteristic.setNotifyValue(true);
characteristic.value.listen((value) {
print(value);
});
}
}
I keep getting this error:
Unhandled Exception: PlatformException(set_notification_error, could not locate CCCD descriptor for characteristic: 00002a24-0000-1000-8000-00805f9b34fb, null, null)
I tested my flutter code for every available characteristic in case my ID is wrong (it's not though). I also tried printing out all descriptors for that characteristic and found out there's none.
In the example adafruit code, we don't need to add any descriptors, we only need to do
characteristic.setProperties(CHR_PROPS_NOTIFY);
characteristic.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
Am I missing something? How can I fix this?
Solved: It was a hardware issue. Service and characteristic UUIDs weren't setting correctly. Tested on a new Feather nRF52 and everything is good.
Related
_scanStream = flutterReactiveBle
.scanForDevices(withServices: <Uuid>[]).listen((device) {
_foundBleUARTDevices.add(device);
for (var element in _foundBleUARTDevices) {
print(
"${element.serviceUuids}---${element.name}---${element.id}---${element.serviceData}---${element.rssi}");
}
I am using the above code snippet to scan for BLE devices and on discovering and printing them out, the UUID is an empty list, and when I try to scan with a specific UUID no device is found. I am using ESP32 as the BLE device and android as the platform to run/debug the app
after waiting for hours, I got no answer from anyone and I had to keep trying, and what I find out is that I can actually connect to the BLE device without the Service UUID but just the id which is the BLE device mac address I think.
I used the below snippet to establish the connection:
void _connectToDevice() {
// We're done scanning, we can cancel it
// _scanStream.cancel();
// Let's listen to our connection so we can make updates on a state change
Stream<ConnectionStateUpdate> _currentConnectionStream = flutterReactiveBle
.connectToAdvertisingDevice(
id: _ubiqueDevice.id,
prescanDuration: const Duration(seconds: 3),
withServices: <Uuid>[]);
_currentConnectionStream.listen((event) {
print(":::::::: ${event.connectionState.name}");
});
}
so I will now proceed to see how I can read and write to the characteristics, i hope someone find this helpful
I try to implement a flutter code that will control NIR Spectrometer via BLE.
I have a very long protocol of service and characteristic uuid pair, and I actually did the same in ionic by just using the uuid pairs and it worked fine...
Is there a way in flutter to call read/write/notify with out do all the:
List<BluetoothService> services = await device.discoverServices();
services.forEach((service) {
// do something with service
for(BluetoothCharacteristic c in characteristics) {
// save the characteristic for latter usage if needed
}
});
something like:
c = BluetoothCharacteristic(device, service_uuid, characteristic_uuid); // why there is no constructor!!
It's going to make life more easy for me!
I finally gave up, also some services that I need don't do advertisement.. So I started to use the plugin flutter_reactive_ble which gives me this option
I am trying to publish our flutter application to the google play store and Im getting what appears to be a show stopper error...
Error
This release is not compliant with the Google Play 64-bit requirement
The following APKs or App Bundles are available to 64-bit devices, but they only have 32-bit native code: 3.
Include 64-bit and 32-bit native code in your app. Use the Android App Bundle publishing format to automatically ensure that each device architecture receives only the native code it needs. This avoids increasing the overall size of your app. Learn More
Does anyone know how to fix this? Im not seeing anything when I google this error. We are just trying to get a Closed Alpha test out there.
I was able to finally fix this by adding this to build.gradle
ndk {
abiFilters "armeabi-v7a", "arm64-v8a"
}
}
splits {
abi {
include "armeabi-v7a", "arm64-v8a"
}
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "arm64-v8a":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
I have a project that scans a iBeacon, and i had also learned this plugin
I have also googled so many projects for that but can't get expected result.
Here i had some code that I write for scan a beacon
listenToBeaconEvents() {
this.events.subscribe("didRangeBeaconsInRegion", data => {
// update the UI with the beacon list
this.zone.run(() => {
let json = data.region;
console.log("-------Beacons-------" + JSON.stringify(json));
this.beacons.push({
uuid: JSON.stringify(json.uuid),
identifier: JSON.stringify(json.identifier),
typename: JSON.stringify(json.typeName)
});
});
}
But my question is if i don't have an UUID of particular beacon then how i can search the beacon?
Please Help me. Thanks.
On iOS you cannot find beacons without a particular UUID -- the platform simply does not allow you to do this. Android has no such restriction.
See this related question for a more detailed explanation:
iOS iBeacon: How to get all of proximityUUID programmatically?
I'm working on QR Code scanning on Google glass. I've used ZXing in android and was happy to find a google glass port has been released recently.
I've downloaded and installed the APK on glass and it works great. However I am having trouble incorporating the project into my own project. There is no maven resource and I've tried importing it as a module without success.
I've also tried incorporating the code into my project, however I get a range of compilation errors such as:
Error:(109, 43) type parameter com.google.zxing.DecodeHintType is not within its bound
Error:(163, 44) cannot find symbol method decode(com.google.zxing.BinaryBitmap,java.util.Map).
Here is a link to the provided release - https://github.com/zxing/zxing/releases/tag/BSGlass-0.2.1 - does anyone have any suggestions on how to make an app like the sample one using the provided code?
Thanks in advance.
Use this "Intent" in your activity to start the QR scanner (ZXing) on your Google Glass:
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
You have to then handle the results returned by the scan.
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
Card card = new Card(this);
card.setText(contents);
View cardView = card.getView();
setContentView(cardView);
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
You also need to make changes to your AndroidManifest.xml
This blog does a good job at explaining what you need to do -> http://damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcode-scanner-into-your-android-app-natively-using-eclipse/does