@here, @all
Hello Guys,
We plan to develop a RN Apps to manage BLE Device. The concept is following:
* the Mobiles App goes into background Mode
* the Mobile app is closed by the USER
I have following questions:
can we develop a React Native Mobile Application using react-native-ble-plx library that meets all above requirements or we'll need a Native Code Interference ?
if you read this message please write your opinion,
Thanks in Advance
Hello
I have initial project setup in RN and implemented the react-native-ble-plx library. I am able to connect to BLE Device and retrieve its services and characteristics. then I want to subscribe to characteristics and read data. I did this using
serviceChar.monitor((error, characteristic) => {
if(error){
console.log({error})
}
if(characteristic){
console.log("Does not enter's here");
console.log(characteristic.value())
}
})
I did the same functionality using Browser's Navigator.Bluetooth
with following steps:
characteristic.startNotifications()
characteristic.addListener('characteristicvaluechanged', someListenerFunction)
Please tell me what I am doing wrong? Why I am not able to subscribe to these services? I did everything according to https://github.com/Polidea/react-native-ble-plx/wiki/Characteristic-Notifying this documentation
Thanks in Advance
Hey there. I'm creating a device editor menu that is a separate component from the one where the device connection is established to allow users to modify settings on their device. However I think my error is because the connection isn't available in the new component, I'm wondering how I can write to a characteristic on a device that was connected in a previous component.
The following yields the error Possible Unhandled Promise Rejection (id: 4):
BleError: Device 24:62:AB:CF:24:DA is not connected
writeToPlantWave(value) {
const {devices} = this.props;
let deviceID = null;
devices.forEach((pw) => {
if (pw.connected === true) {
console.log('Within', pw.bleDevice.id);
deviceID = pw.bleDevice.id;
}
});
const encodedValue = base64.encode('set sense', value);
const service = '6E400001-B5A3-F393-E0A9-E50E24DCCA9E';
const characteristicW = '6E400002-B5A3-F393-E0A9-E50E24DCCA9E';
console.log('Without', deviceID);
this.manager.writeCharacteristicWithoutResponseForDevice(
deviceID,
service,
characteristicW,
encodedValue,
);
}
Am I going about this correctly? Or maybe the error lies somewhere else?
startBLEActions = async () => {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: 'Location Access for Bluetooth Usage',
message:
'This app collects location data to enable your PlantWave to pair with your phone even when the app is closed or not in use',
buttonNeutral: 'Ask Me Later',
buttonNegative: 'Cancel',
buttonPositive: 'OK',
},
);
if(this.manager == null){
this.manager = new BleManager();
this.manager.setLogLevel('Verbose');
}
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log('You can access location');
clearInterval(this.findPlantwavesInterval);
clearInterval(this.flushConnectedListInterval);
this.findPlantWaves();
this.flushConnectedList();
this.findPlantwavesInterval = setInterval(() => this.findPlantWaves(), 7000);
this.flushConnectedListInterval = setInterval(() => this.flushConnectedList(), 2000);
} else {
console.log('Location permission denied');
}
} catch (err) {
console.warn(err);
}
};
this.info('Connecting to PlantWave');
this.manager
.connectToDevice(selectedAddress)
.then((device) => {
this.info('Discovering services and characteristics');
device.discoverAllServicesAndCharacteristics();
return device;
})
.then((device) => {
console.log('Negotiating MTU');
device.requestMTU(300);
console.log('Setting notifications');`
${dev.name} Disconnected
, useEffect(() => {
const subscription = bleManager.onStateChange((state) => {
console.log('hei');
setIsBlePoweredOn(state === State.PoweredOn);
if (state === State.PoweredOn) {
subscription.remove();
}
}, true);
}, []);
[RxBLEKit|DEBG|15:26:22.486]: Peripheral(uuid: ...
from the code? I'm fine with file paths or any other way that I can upload that logs from someones device elsewhere to debug issues on the device/peripheral that I don't have access to.
Hi there i have to read all glucose measurement from a ble device. I can read the glucose value from realtime measurement this is my code to write characteristic 0101 for all stored values.code
async readAll(device) {
const service = this.serviceUUID()
const characteristicW = this.writeUUID()
var myData = '0x0101';
const dataMostSignificantByte = (myData >> 8) & 0xFF;
const dataLeastSignificantByte = myData & 0xFF;
const dataByteArrayInLittleEndian = [dataLeastSignificantByte, dataMostSignificantByte];
const dataInBase64 = Buffer.from(dataByteArrayInLittleEndian).toString('base64');
const write = this.manager.writeCharacteristicWithResponseForDevice(
device.id,
service,
characteristicW,
dataInBase64,
)
console.log(write)
}code
manager.cancelDeviceConnection(device)
.then(() => {
setConnectedDeviceStatus(false)
})
.catch(error => {
console.log('Unable to disconnect from device', error);
})
}
//connect to select device
const connectToDevice = async(device) => {
console.log('ok process ongoing to connectToDevice');
console.log('device nme',device.name);
console.log('deviceId',device.id)
setDeviceId(device.id);
//check connection state of a device
/*if(manager.isDeviceConnected(deviceId) === true){
console.log("cancelling");
manager.cancelDeviceConnection(deviceId); // deconnexion
}*/
//setConnectedDeviceList([]);
//connexion au device
device.connect()
.then((connectedDevice) => {
console.log('device connected',connectedDevice)
//Add device to connectedDeviceList
// setConnectedDeviceList([...connectedDeviceList, device])
//processing double
var newConnectedDevice = true
//console.log('lenght device', deviceList.length)
for( let connectDevice of connectedDeviceList ) {
if( connectDevice.id === connectedDevice.id ) {
//console.log('connect device id',connectDevice.id)
//console.log('connected device id',connectedDevice.id)
//console.log("ok same devices")
newConnectedDevice = false
break;
} else {
console.log('break ?')
}
}
if( newConnectedDevice === true ) {
//console.log('device news')
setConnectedDeviceList([...connectedDeviceList, device])
}
setConnectedDeviceName(device.name);
setConnectedDeviceStatus(true);
setConnectedDevice(device);
//check deconnection
//listenerDeviceDisconnect(deviceId);
//store in AsyncStorage deviceId
//storeDeviceConnected(device.id)
//console.log('connectedDevice',connectedDevice)
console.log('Discovering services and characteristics');
device.discoverAllServicesAndCharacteristics()
.then(device=>{ console.log('device discover',device.name)})
.catch(c=>{console.log('error discover',c)})
})
.then((device) => {
console.log('Setting notifications');
//const services = device.services();
})
.catch(error => {
if(error) {
console.log('error connectToDevice',error)
}
})
}
Hi !
Recently I have some iOS phone that failed to keep the connection active. I can connect to my device, but after some delay (it looks like every time, 30s after connecting), it gets automatically disconnected.
When I check with onDeviceDisconnected
I have no error.
Any idea why ?
2021-02-18 22:45:41.863 18865-20061/com.datagarden.plantwaveandroid W/ReactNativeJS: Possible Unhandled Promise Rejection (id: 0):
BleError: Characteristic 6e400002-b5a3-f393-e0a9-e50e24dcca9e write failed for device FC:F5:C4:08:98:6A and service 6e400001-b5a3-f393-e0a9-e50e24dcca9
2021-02-18 23:17:19.443 28788-30924/com.datagarden.plantwaveandroid W/RxBle#ConnectionOperationQueue: Queue's awaitRelease() has been interrupted abruptly while it wasn't released by the release() method.
java.lang.InterruptedException
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:442)
at java.lang.Object.wait(Object.java:568)
at com.polidea.rxandroidble.internal.serialization.QueueSemaphore.awaitRelease(QueueSemaphore.java:15)
at com.polidea.rxandroidble.internal.serialization.ConnectionOperationQueueImpl$1.run(ConnectionOperationQueueImpl.java:73)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
2021-02-18 23:17:19.597 28788-28788/com.datagarden.plantwaveandroid E/ViewRootImpl: sendUserActionEvent() mView returned.
2021-02-17 10:13:14.105 -0500 EST error RN Method.java:-2 java.lang.reflect.Method.invoke 20681_46fa990f-2e9b-5bc0-9823-5cbbdb28e927 4.15.15 1024605174 en 10 245213 106 Error while reading characteristic (service: 0000181c-0000-1000-8000-00805f9b34fb, characteristic: 00002B00-0000-1000-8000-00805f9b34fb): Error BleError: Characteristic 00002b00-0000-1000-8000-00805f9b34fb read failed for device 08:7C:BE:7F:1A:1F and service 0000181c-0000-1000-8000-00805f9b34fb
2021-02-17 10:13:14.111 -0500 EST error RN Method.java:-2 java.lang.reflect.Method.invoke 20681_46fa990f-2e9b-5bc0-9823-5cbbdb28e927 4.15.15 1024605174 en 10 245213 107 BleError: Characteristic 00002b00-0000-1000-8000-00805f9b34fb read failed for device 08:7C:BE:7F:1A:1F and service 0000181c-0000-1000-8000-00805f9b34fb
2021-02-17 10:13:14.118 -0500 EST error RN Method.java:-2 java.lang.reflect.Method.invoke 20681_46fa990f-2e9b-5bc0-9823-5cbbdb28e927 4.15.15 1024605174 en 10 245213 108 Error while reading characteristic (service: 0000181c-0000-1000-8000-00805f9b34fb, characteristic: 00002B03-0000-1000-8000-00805f9b34fb): Error BleError: Device 08:7C:BE:7F:1A:1F is not connected
2021-02-17 10:13:14.119 -0500 EST warning RN Method.java:-2 java.lang.reflect.Method.invoke 20681_46fa990f-2e9b-5bc0-9823-5cbbdb28e927 4.15.15 1024605174 en 10 245213 109 connection error: Device 08:7C:BE:7F:1A:1F is not connected, retry: 2
2021-02-17 10:13:14.131 -0500 EST warning RN Method.java:-2 java.lang.reflect.Method.invoke 20681_46fa990f-2e9b-5bc0-9823-5cbbdb28e927 4.15.15 1024605174 en 10 245213 110 BleError: Device 08:7C:BE:7F:1A:1F is not connected
2021-02-17 10:13:16.405 -0500 EST error RN Method.java:-2 java.lang.reflect.Method.invoke 20681_46fa990f-2e9b-5bc0-9823-5cbbdb28e927 4.15.15 1024605174 en 10 245213 122 Error while reading characteristic (service: 0000181c-0000-1000-8000-00805f9b34fb, characteristic: 00002B00-0000-1000-8000-00805f9b34fb): Error BleError: Device 08:7C:BE:7F:1A:1F was disconnected
2021-02-17 10:13:19.725 -0500 EST error RN Method.java:-2 java.lang.reflect.Method.invoke 20681_46fa990f-2e9b-5bc0-9823-5cbbdb28e927 4.15.15 1024605174 en 10 245213 133 Error while reading characteristic (service: 0000181c-0000-1000-8000-00805f9b34fb, characteristic: 00002B00-0000-1000-8000-00805f9b34fb): Error BleError: Characteristic 00002b00-0000-1000-8000-00805f9b34fb read failed for device 08:7C:BE:7F:1A:1F and service 0000181c-0000-1000-8000-00805f9b34fb
2021-02-17 10:13:19.726 -0500 EST error RN Method.java:-2 java.lang.reflect.Method.invoke 20681_46fa990f-2e9b-5bc0-9823-5cbbdb28e927 4.15.15 1024605174 en 10 245213 134 BleError: Characteristic 00002b00-0000-1000-8000-00805f9b34fb read failed for device 08:7C:BE:7F:1A:1F and service 0000181c-0000-1000-8000-00805f9b34fb
2021-02-17 10:13:19.733 -0500 EST error RN Method.java:-2 java.lang.reflect.Method.invoke 20681_46fa990f-2e9b-5bc0-9823-5cbbdb28e927 4.15.15 1024605174 en 10 245213 135 Error while reading characteristic (service: 0000181c-0000-1000-8000-00805f9b34fb, characteristic: 00002B03-0000-1000-8000-00805f9b34fb): Error BleError: Device 08:7C:BE:7F:1A:1F is not connected
2021-02-17 10:13:19.734 -0500 EST warning RN Method.java:-2 java.lang.reflect.Method.invoke 20681_46fa990f-2e9b-5bc0-9823-5cbbdb28e927 4.15.15 1024605174 en 10 245213 136 connection error: Device 08:7C:BE:7F:1A:1F is not connected, retry: 2
2021-02-17 10:13:19.746 -0500 EST warning RN Method.java:-2 java.lang.reflect.Method.invoke 20681_46fa990f-2e9b-5bc0-9823-5cbbdb28e927 4.15.15 1024605174 en 10 245213 137 BleError: Device 08:7C:BE:7F:1A:1F is not connected
2021-02-17 10:13:25.184 -0500 EST error RN Method.java:-2 java.lang.reflect.Method.invoke 20681_46fa990f-2e9b-5bc0-9823-5cbbdb28e927 4.15.15 1024605174 en 10 245213 159 Error while reading characteristic (service: 0000181c-0000-1000-8000-00805f9b34fb, characteristic: 00002B00-0000-1000-8000-00805f9b34fb): Error BleError: Characteristic 00002b00-0000-1000-8000-00805f9b34fb read failed for device 08:7C:BE:7F:1A:1F and service 0000181c-0000-1000-8000-00805f9b34fb
2021-02-17 10:13