Bluetooth-for-STM32-and-Android icon indicating copy to clipboard operation
Bluetooth-for-STM32-and-Android copied to clipboard

Bluetooth low energy data reading

Open paxsipornax opened this issue 4 years ago • 2 comments

I used the bluetooth low energy app for esp32, but I can't read data from esp32, sending data from esp32. however, the application cannot catch it. Can you help me?

paxsipornax avatar May 26 '21 10:05 paxsipornax

First of all, you have to find out what service and characteristic UUID is used to read and write. Then...: In BluetoothLeService.java change your UUID: `

public void writeCharacteristic(String input) { try { BluetoothGattService Service = mBluetoothGatt.getService(UUID.fromString("0000ffe0-0000-1000-8000-00805f9b34fb")); BluetoothGattCharacteristic charac = Service.getCharacteristic(UUID.fromString("0000ffe1-0000-1000-8000-00805f9b34fb")); charac.setValue(input); mBluetoothGatt.writeCharacteristic(charac); }catch (IllegalStateException | NullPointerException e) { Log.e(TAG, "Wrong device, does not contain service/characteristic 0000fee1-0000-1000-8000-00805f9b34fb"); } }

`

And in your DeviceControlActivuty.java also change your UUID: `

//custom code if(uuid.equals("0000ffe1-0000-1000-8000-00805f9b34fb") && mNotifyCharacteristic == null) { mBluetoothLeService.setCharacteristicNotification(gattCharacteristic, true); mNotifyCharacteristic = gattCharacteristic; }

`

viktorvano avatar May 26 '21 14:05 viktorvano

First of all, you have to find out what service and characteristic UUID is used to read and write. Then...: In BluetoothLeService.java change your UUID: `

public void writeCharacteristic(String input) { try { BluetoothGattService Service = mBluetoothGatt.getService(UUID.fromString("0000ffe0-0000-1000-8000-00805f9b34fb")); BluetoothGattCharacteristic charac = Service.getCharacteristic(UUID.fromString("0000ffe1-0000-1000-8000-00805f9b34fb")); charac.setValue(input); mBluetoothGatt.writeCharacteristic(charac); }catch (IllegalStateException | NullPointerException e) { Log.e(TAG, "Wrong device, does not contain service/characteristic 0000fee1-0000-1000-8000-00805f9b34fb"); } } `

And in your DeviceControlActivuty.java also change your UUID: `

//custom code if(uuid.equals("0000ffe1-0000-1000-8000-00805f9b34fb") && mNotifyCharacteristic == null) { mBluetoothLeService.setCharacteristicNotification(gattCharacteristic, true); mNotifyCharacteristic = gattCharacteristic; } `

#define SERVICE_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E" #define CHARACTERISTIC_UUID_RX "6E400002-B5A3-F393-E0A9-E50E24DCCA9E" #define CHARACTERISTIC_UUID_TX "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"

BluetoothGattService Service = mBluetoothGatt.getService(UUID.fromString("6E400001-B5A3-F393-E0A9-E50E24DCCA9E")); BluetoothGattCharacteristic charac = Service.getCharacteristic(UUID.fromString("6E400002-B5A3-F393-E0A9E50E24DCCA9E")); charac.setValue(input); mBluetoothGatt.writeCharacteristic(charac); if(uuid.equals("6E400003-B5A3-F393-E0A9-E50E24DCCA9E") && mNotifyCharacteristic == null) { mBluetoothLeService.setCharacteristicNotification(gattCharacteristic, true); mNotifyCharacteristic = gattCharacteristic; }

The uuids I use, the uuids I change in the application, but the reading process is happening. Can write data to esp32 via aqq

paxsipornax avatar May 26 '21 14:05 paxsipornax