简体   繁体   中英

How to change the connected BLE device name in Android programatically?

In my android application, BLE connection is working successfully, once BLE device has been connected to Android phone. How to change the connected BLE device name programatically? Sample code like below

private static final UUID Device_Name_UUID = UUID.fromString("00002a00-0000-1000-8000-00805f9b34fb");
private static final UUID Write_UUID = UUID.fromString("00001800-0000-1000-8000-00805f9b34fb");

        public void Device_Name(){
            BluetoothGattService Name_Service = mBluetoothGatt.getService(Write_UUID );
            if(Name_Service == null) {
                Log.d(TAG, "Name_Service service not found!");
                return;
            }

            BluetoothGattCharacteristic DeviceName = Name_Service.getCharacteristic(Device_Name_UUID);
            if(DeviceName == null) {
                Log.d(TAG, "DeviceName charateristic not found!");
                return;
            }
        }
        Log.v(TAG, "readCharacteristic(DeviceName) = " + mBluetoothGatt.readCharacteristic(DeviceName));
        String i = "123";       
        DeviceName.setValue(i);
        Log.v(TAG, "writeCharacteristic(DeviceName) = " + mBluetoothGatt.writeCharacteristic(DeviceName));
        Log.v(TAG, "writeCharacteristic(DeviceName) = " + mBluetoothGatt.writeCharacteristic(DeviceName));

Here mBluetoothGatt.writeCharacteristic(DeviceName); method always returns false .

After some Research I found Below solution

You need to modify the firmware of CC2541 keyfob to add the write permission of device name by adding the code below into KeyFobApp_Init() inside keyfobdemo.c:

uint8 devNamePermission = GATT_PERMIT_READ|GATT_PERMIT_WRITE; 
GGS_SetParameter( GGS_W_PERMIT_DEVICE_NAME_ATT, sizeof ( uint8 ), &devNamePermission );

Now my question is, where we need to add these permissions?

Please can anybody tell me that how to add these persmissions?

Thanks in advance

As the name indicates: keyfobdemo.c is a .c file, so TI is telling you that you have to add those permissions in the KeyFobDemo workspace, so you have to program the CC2541 kit in order to change the name. You cannot do it in Android.

All you have to do is:

Download the BLE stack from Texas Instruments website: http://www.ti.com/tool/ble-stack

Then in the stack, open Projects\\ble\\KeyFob\\CC2541DB\\KeyFobDemo.eww file.

Programming of CC2540 kit requires an IDE named IAR Embedded Workbench. You can download it and get access with 30-days trial: http://www.iar.com/Products/IAR-Embedded-Workbench/8051/

Then open the project and find the keyfobdemo.c file in the APP folder. From line 200-213 there is a char array named deviceName[], which actually defines the advertising name as "Keyfobdemo". You just have to change that to the desired name with correct hex values, and the length of the array as well. Then in line 236, you have to change attDeviceName[] array as well, since this parameter defines the name of your device once it is in connected state.

No way to do that in Android! unless you change your BLE firmware!

Possible solution, once you connected to your BLE device, you could send some configuration command to your device to change the device name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM