Search code examples
androidandroid-studioflutterbluetooth-lowenergymicrochip

Write data to microchip rn4870 vie ble


I am working with microchip rn4780.
I succeed to connect to the device, but when I try to send it data (2 bytes),
I don't get a response (It should run some motor).
I think the problem is the characteristic I am working with, But I am not sure. This is my code

override fun onServicesDiscovered(gatt: BluetoothGatt?, status: Int) {
        super.onServicesDiscovered(gatt, status)
        for (service in gatt!!.services){
            Log.d(TAG, "Service: " + service.uuid.toString())
            for (char in service.characteristics) {
                Log.d(TAG, "Char: " + char.uuid.toString())
                if(char.uuid.toString() == "49535343-8841-43f4-a8d4-ecbe34729bb3") {
                    Log.d(TAG, "Try to write")
                    char.value = byteArrayOf(0x39, 0x31)
                    gatt!!.writeCharacteristic(char)
                    Log.d(TAG, "Finish to write")
                }
            }
        }
    }

I tried to work with other apps from google play, but only one worked, it calls "lightblue".
From that screen, it worked perfect (I send 39 and then 31 in hex)
From that screen it doesn't work, for each characteristic, I have tried

There is a guide of microchip but i dont understand what they are doing different:
https://microchipdeveloper.com/wireless:ble-mchp-transparent-uart-service

By the way, I tried it with flutter and it didn't work too, so if there is a solution for flutter it will be better.


Solution

  • I found the problem, what I used the microchip page on the app, it sends some bytes before and after my massage. I figure it out by looking at the Log file on the app.