_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
Related
I want to simply monitor manufacturer data from a TPMS ble (the type is 0x600 IRobot i suppose) and i tried with flutter in android studio starting with flutter_reactive_ble library and the example source they provide in
https://github.com/wolfc01/flutter_reactive_ble_uart_example .
I am able to scan and discover the devices i have using a UUID (same also for RX and TX)
Uuid _UART_UUID = Uuid.parse("0000fbb0-0000-1000-8000-00805f9b34fb");
Uuid _UART_RX = Uuid.parse("0000fbb0-0000-1000-8000-00805f9b34fb");
Uuid _UART_TX = Uuid.parse("0000fbb0-0000-1000-8000-00805f9b34fb");
i also can read manufacturedata but to do this i have to repeat scanning because the "connection" to ble did not happens ( the error message i get in android studio is
"A scan for a different service is running"
So my question is: HOW CAN I READ MANUFACTURER DATA EACH SECOND or EACH time they change/update??
Thanks a lot
Lorenzo from Italy
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.
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've been trying to create a car head using the raspberry pi and android things. In order to power the car audio I bought this amp Suptronics X400 but I haven't been able to use it as the default output for audio and I'm trying to integrate the Spotify SDK. I tried to create the drive but most of the Documentation here has been removed from the libraries. I'm a bit lost
The audio driver user driver is no longer available in Android Things. The right way is to use the AudioTrack class and set the preferred device type, as is done in this sample project.
You may need to specify the audio bus you want to send sounds to:
private AudioDeviceInfo findAudioDevice(int deviceFlag, int deviceType) {
AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
AudioDeviceInfo[] adis = manager.getDevices(deviceFlag);
for (AudioDeviceInfo adi : adis) {
if (adi.getType() == deviceType) {
return adi;
}
}
return null;
}
Then find the I2S bus:
mAudioInputDevice = findAudioDevice(AudioManager.GET_DEVICES_INPUTS, AudioDeviceInfo.TYPE_BUS);
mAudioOutputDevice = findAudioDevice(AudioManager.GET_DEVICES_OUTPUTS, AudioDeviceInfo.TYPE_BUS);
Then you can run audioTrack.setPreferredDevice(mAudioOutputDevice);
I can't get data by I2C bus in Android Things on Raspberry Pi 3.
I connect Android Things on RPi and DS18B20(Temperature Sensor).
Connect to RPi
and run the I2C address scan App (https://github.com/dennisg/i2c-address-scanner), but can't find available address.
for (int address = 0; address < 256; address++) {
//auto-close the devices
try (final I2cDevice device = peripheralManagerService.openI2cDevice(BoardDefaults.getI2cBus(), address)) {
try {
device.readRegByte(TEST_REGISTER);
Log.i(TAG, String.format(Locale.US, "Trying: 0x%02X - SUCCESS", address));
} catch (final IOException e) {
Log.i(TAG, String.format(Locale.US, "Trying: 0x%02X - FAIL", address));
}
} catch (final IOException e) {
//in case the openI2cDevice(name, address) fails
}
}
How do I get data by I2C?
The linked test project appears to use the I2C protocol poorly in several ways.
First, it makes the assumption that there is only a single I2C bus on a particular board. Although that is true now, it may not scale to additional SOMs that support Android Things in the future.
Second, it assumes the register address to read from (0x00). This may have worked for whatever device the developer started with, but a large number of I2C peripherals may not respond to that address.
You should take a look at the datasheet for this device. After a cursory examination, it seems that there is no register corresponding to 0x00. Additionally, it has a custom read flow that would make it difficult to use the snippet above. The microcontroller getting these values on your sensor probably throws them away and returns no signal.
It may be useful to read through the datasheet again. It seems like the sensor is "one-wire" instead of I2C. While the two protocols may be similar, using the built in readByte method may make some assumptions in the data transmission that may not match the peripheral protocol exactly.
As Nick Felker wrote in his answer DS18B20 has 1-Wire interface and you can't connect it to Raspberry Pi with Android Things directly. You should use industrial (e.g DS2482-100) or custom MCU-based (like in that project) 1-Wire <-> I2C converter, or other (e.g. USB <-> 1-Wire, UART<-> 1-Wire) converters.