0

BLE Service & Characteristic on Adafruit Bluefruit not visib
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

BLE Service & Characteristic on Adafruit Bluefruit not visib

by benberry on Sun Aug 25, 2019 11:30 pm

I'm trying to read and write data from an Adafruit Bluefruit Feather 32u4 using an Android app.

As a starting place, I'm using the health thermometer demo that creates a custom GATT service and characteristic, then writes to the characteristic once per second.

The relevant part of that code sample:

Code: Select all | TOGGLE FULL SIZE
/* Add the Heart Rate Service definition */
  /* Service ID should be 1 */
  Serial.println(F("Adding the Health Thermometer Service definition (UUID = 0x1809): "));
  htsServiceId = gatt.addService(0x1809);
  if (htsServiceId == 0) {
    error(F("Could not add Thermometer service"));
  }
 
  /* Add the Temperature Measurement characteristic which is composed of
   * 1 byte flags + 4 float */
  /* Chars ID for Measurement should be 1 */
  Serial.println(F("Adding the Temperature Measurement characteristic (UUID = 0x2A1C): "));
  htsMeasureCharId = gatt.addCharacteristic(0x2A1C, GATT_CHARS_PROPERTIES_INDICATE, 5, 5, BLE_DATATYPE_BYTEARRAY);
  if (htsMeasureCharId == 0) {
    error(F("Could not add Temperature characteristic"));
  }


Running the sample on my 32u4 Feather and watching the serial output, everything appears to be good. Adding an invocation of `AT+GATTLIST` to the code sample prints this to the Serial output:


Code: Select all | TOGGLE FULL SIZE
AT+GATTLIST

<- ID=01,UUID=0x1809
  ID=01,UUID=0x2A1C,PROPERTIES=0x20,MIN_LEN=5,MAX_LEN=5,DATATYPE=2,VALUE=00-00-00-00-00


So the service is being created, the characteristic is being created, and then the `loop()` of the sample goes on to write every second to that characteristic.

However, from my Android app, I just can't seem to get a handle to that GATT service or characteristic. I can scan for BLE devices just fine, find the Feather, connect to it, and run `discoverServices` and then once that's done, try to get the custom service being created, but it's not there. Relevant snippet of code:


Code: Select all | TOGGLE FULL SIZE
    fun connect(device: BluetoothDevice) {
        /** Step 1: Connect to the device **/
        device.connectGatt(context, true, gattCallback)
    }

    fun deviceConnected(gatt: BluetoothGatt) {
        /** Step 2: Store connection to GATT interface, discover services **/
        this.gatt = gatt
        gatt.discoverServices()
    }

    private val gattCallback = object : BluetoothGattCallback() {
        override fun onConnectionStateChange(gatt: BluetoothGatt?, status: Int, newState: Int) {
            when (newState) {
                BluetoothGatt.STATE_CONNECTED -> {
                    gatt?.let {
                        deviceConnected(gatt)
                    }
                }
            }
        }

        override fun onServicesDiscovered(gatt: BluetoothGatt?, status: Int) {
            /** Step 3: Do things with services **/

            Log.d(TAG, gatt?.getService(expandUuid(0x1809))?.uuid.toString())
            Log.d(TAG, gatt?.getService(expandUuid(0x180A))?.uuid.toString())
        }
    }


The log line to get the `0x180A` service prints the UUID of that service (the standard Device Information service), but the line to get our custom `0x1809` service just prints null.

The feather thinks it's creating the service, but Android just doesn't see it. I'm not sure how to troubleshoot this any further. Any suggestions would be helpful.

benberry
 
Posts: 2
Joined: Sun Aug 25, 2019 11:26 pm

Re: BLE Service & Characteristic on Adafruit Bluefruit not v

by benberry on Sun Sep 01, 2019 2:59 pm

This issue is still outstanding. Has the sample code for the 32u4 Bluefruit just been deprecated?

benberry
 
Posts: 2
Joined: Sun Aug 25, 2019 11:26 pm

Please be positive and constructive with your questions and comments.