Need help figuring out how to successfully communicate with simple Bluetooth Ble Button through UUID

Im currently working on an app which needs simple communication between a bluetooth button (basically a selfie button) and the connected phone through the app. Now, i can connect normally with my phone and it does work as intended, but as soon as i want to achieve this communication via code im running into problems. I got the discovery of devices and can connect via their mac adress. The device is a no name brand so there is no documentation on the UUIDS, but i have used ble apps to find out the UUIDS i need, or at least the ones i think i need. This is my current code when the device gets “clicked” in the device list. Im pretty new to this so i might be wrong but im basically trying to activate the notification by writing to the human interface UUID (on the physical button press)so i can later get notifications on button press to use for my app.Im trying this because simply trying to get communicate with the correspondant notification UUID hasnt worked so far. The whole setup notifcation part has yet to work. It would be a blessing if anyone was able to help me out here. Thanks in advance lads.

    package com.example.androidcounterapp

import android.annotation.SuppressLint
import android.bluetooth.BluetoothAdapter
import android.bluetooth.BluetoothGattDescriptor
import android.content.ContentValues.TAG
import android.content.Context
import android.util.Log
import com.polidea.rxandroidble3.RxBleClient
import com.polidea.rxandroidble3.RxBleDevice
import io.reactivex.rxjava3.disposables.Disposable
import java.util.UUID

class BluetoothConnection {

    val serviceUuidUUID = UUID.fromString("00001812-0000-1000-8000-00805f9b34fb")
    val characteristicUUID = UUID.fromString("00002a4d-0000-1000-8000-00805f9b34fb")
    val cccdUUID = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb")

    inner class ConnectThread(
        private val context: Context,
        private val macAddress: String,
        private val bluetoothAdapter: BluetoothAdapter
    ) : Thread() {

        private val rxBleClient: RxBleClient by lazy(LazyThreadSafetyMode.NONE) {
            RxBleClient.create(context)
        }

        private var connectionDisposable: Disposable? = null

        @SuppressLint("MissingPermission")
        private fun connectAndSetupNotification(
            device: RxBleDevice,
            characteristicUUID: UUID,
            cccdUUID: UUID,
        ) {

            Log.i(TAG, "Entered connectAndSetupNotification")

            connectionDisposable = device.establishConnection(false)
                .flatMap { rxBleConnection ->

                    Log.i(TAG, "GATT connection established")


                    rxBleConnection.setupNotification(characteristicUUID)
                        .flatMap { notificationObservable ->
                            val enableNotificationValue = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
                            val descriptor = BluetoothGattDescriptor(
                                cccdUUID,
                                BluetoothGattDescriptor.PERMISSION_WRITE
                            ).apply {
                                value = enableNotificationValue
                            }

                            rxBleConnection.writeDescriptor(descriptor, enableNotificationValue)
                                .andThen(notificationObservable)
                        }
                }
                .subscribe(
                    { notificationData ->
                        Log.i(TAG, "Notification data: ${notificationData.joinToString(", ")}")
                        val readableValue = CharacteristicConverter.convert(notificationData)
                        Log.i(TAG, "Readable value: $readableValue")
                    },
                    { throwable ->
                        Log.e(TAG, "Error occurred while setting up notification", throwable)
                    }
                )
        }

        @SuppressLint("MissingPermission")
        override fun run() {

            bluetoothAdapter.cancelDiscovery()
            Log.i(TAG, "Trying to connect")
            val device = rxBleClient.getBleDevice(macAddress)
            connectAndSetupNotification(device, characteristicUUID, cccdUUID)
        }

        fun cancel() {
            connectionDisposable?.dispose()
        }
    }
}

I have tried communcating with basically every UUID that the Bluetooth ble app tied to my button device to no avail. So my last hope is that the notification needs to be enabled to work and that im not overseeing something big along the way.

New contributor

Christian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật