GATT_READ_NOT_PERMIT on BLE Characteristic Read

Tom_Koller
Posts: 3
Joined: Thu Feb 15, 2018 4:14 pm

GATT_READ_NOT_PERMIT on BLE Characteristic Read

Postby Tom_Koller » Thu Feb 15, 2018 4:41 pm

Hi,
I am currently trying to setup a BLE Connection between a ESP32-ST and a BGM111 from Silabs.

I can connect to the service and find the characteristic I want but whenever i try to read the value i get

E (36655) BT: GATT_READ_NOT_PERMIT

Aswell when I want to apply the BGM for notifications I get

E (36155) BT: format mismatch

which indicates that the chips are somehow using different BLE protocols.

When I try to read/write the value with another esp32 it just works fine so the basic setup of my BLE Server should be ok.

So is there anything I have to take into account when I connect a non-ESP32 BLE device to a esp32 ? I really need a new idea how to debug that error.

The Error Messages are generated in esp-idf/components/bt/bluedroid/stack/gatt/gatt_db.c


Here is my ESP32 code based on the BLE Server Example of arduino-espressif:

Code: Select all

#if (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
#include <string>
#include <sstream>
#include <vector>
#include <esp_log.h>
#include <cstdio>
BLECharacteristic *dist;
bool deviceConnected = false;
uint8_t value = 0;

// See the following for generating UUIDs:
// https://www.uuidgenotifynerator.net/

#define SERVICE_UUID        "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID1 "beb5483e-36e1-4688-b7f5-ea07361b26a8"
class MyServerCallbacks: public BLEServerCallbacks {
    void onConnect(BLEServer* pServer) {
      deviceConnected = true;

    };

    void onDisconnect(BLEServer* pServer) {
      deviceConnected = false;
    }
};

#define createCharact(uuid,charac,pService) charac =pService->createCharacteristic(uuid,   \
    BLECharacteristic::PROPERTY_READ   | \
    BLECharacteristic::PROPERTY_WRITE  | \
    BLECharacteristic::PROPERTY_NOTIFY | \
    BLECharacteristic::PROPERTY_INDICATE | \
    BLECharacteristic::PROPERTY_WRITE_NR \
                                                                                  );                                      \
charac->addDescriptor(new BLE2902());

void createChars(BLEService *pService) {
  createCharact(CHARACTERISTIC_UUID2, dist, pService);

}
int print_F(const char* msg,va_list list){
  char temp[200];
  vsprintf(temp,msg,list);
  Serial.print(temp);
  return 0;
}
void setup() {
  esp_log_level_set("*", ESP_LOG_VERBOSE);
  esp_log_set_vprintf(print_F);
  // Create the BLE Device
  BLEDevice::init("RBase");

  // Create the BLE Server
  BLEServer *pServer = BLEDevice::createServer();
  pServer->setCallbacks(new MyServerCallbacks());

  // Create the BLE Service
  BLEService *pService = pServer->createService(SERVICE_UUID);
  createChars(pService);

  // Start the service
  pService->start();
  pServer->getAdvertising()->addServiceUUID(BLEUUID(SERVICE_UUID));
  pServer->getAdvertising()->start();
 dist->setValue("hallo");
}
void loop() {
//wait for a change of value
    std::string temp=dist->getValue();
    if(temp != "hallo")
    Serial.println(temp.c_str());
  delay(50);
}
Log:
ets Jun 8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:956
load:0x40078000,len:0
load:0x40078000,len:13076
entry 0x40078a58
Starting up
Gestartet
E (79543) BT: format mismatch
E (80043) BT: GATT_READ_NOT_PERMIT

E (80543) BT: GATT_READ_NOT_PERMIT

E (81043) BT: GATT_READ_NOT_PERMIT

E (81543) BT: GATT_READ_NOT_PERMIT

E (82043) BT: GATT_READ_NOT_PERMIT
Last edited by Tom_Koller on Mon Feb 19, 2018 3:36 pm, edited 1 time in total.

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: GATT_READ_NOT_PERMIT on BLE Characteristic Read

Postby chegewara » Fri Feb 16, 2018 2:40 am

As you said this code works with another esp32 then there is not much we can do without logs. If you can provide logs when you are trying to connect with BGM that might be more helpful. Just make sure you turn on logging to verbose or at least to debug.

Tom_Koller
Posts: 3
Joined: Thu Feb 15, 2018 4:14 pm

Re: GATT_READ_NOT_PERMIT on BLE Characteristic Read

Postby Tom_Koller » Mon Feb 19, 2018 3:40 pm

I tried to add the log to my post but the post itself disappeared.

so here is the log:

ets Jun 8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:956
load:0x40078000,len:0
load:0x40078000,len:13076
entry 0x40078a58
Starting up
Gestartet
E (79543) BT: format mismatch
E (80043) BT: GATT_READ_NOT_PERMIT

E (80543) BT: GATT_READ_NOT_PERMIT

E (81043) BT: GATT_READ_NOT_PERMIT

E (81543) BT: GATT_READ_NOT_PERMIT

E (82043) BT: GATT_READ_NOT_PERMIT

E (82543) BT: GATT_READ_NOT_PERMIT

E (83043) BT: GATT_READ_NOT_PERMIT


and code with printing:

Code: Select all

/*
    Video: https://www.youtube.com/watch?v=oCMOYS71NIU
    Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleNotify.cpp
    Ported to Arduino ESP32 by Evandro Copercini

   Create a BLE server that, once we receive a connection, will send periodic notifications.
   The service advertises itself as: 4fafc201-1fb5-459e-8fcc-c5c9c331914b
   And has a characteristic of: beb5483e-36e1-4688-b7f5-ea07361b26a8

   The design of creating the BLE server is:
   1. Create a BLE Server
   2. Create a BLE Service
   3. Create a BLE Characteristic on the Service
   4. Create a BLE Descriptor on the characteristic
   5. Start the service.
   6. Start advertising.

   A connect hander associated with the server starts a background task that performs notification
   every couple of seconds.
*/
#if (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
#include <string>
#include <sstream>
#include <vector>
#include <esp_log.h>
#include <cstdio>
BLECharacteristic *dist, *distR, *distL, *force, *forceB;
bool deviceConnected = false;
uint8_t value = 0;

// See the following for generating UUIDs:
// https://www.uuidgenotifynerator.net/

#define SERVICE_UUID        "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID2 "ede93193-cb18-414a-b42e-9dfb2ee8ac9f"




class MyServerCallbacks: public BLEServerCallbacks {
    void onConnect(BLEServer* pServer) {
      deviceConnected = true;

    };

    void onDisconnect(BLEServer* pServer) {
      deviceConnected = false;
    }
};


#define createCharact(uuid,charac,pService) charac =pService->createCharacteristic(uuid,   \
    BLECharacteristic::PROPERTY_READ   | \
    BLECharacteristic::PROPERTY_WRITE  | \
    BLECharacteristic::PROPERTY_NOTIFY | \
    BLECharacteristic::PROPERTY_INDICATE | \
    BLECharacteristic::PROPERTY_WRITE_NR \
                                                                                  );                                      \
charac->addDescriptor(new BLE2902());


void createChars(BLEService *pService) {
  createCharact(CHARACTERISTIC_UUID2, force, pService);

}

int print_F(const char* msg,va_list list){
  char temp[200];
  vsprintf(temp,msg,list);
  Serial.print(temp);
  return 0;
}
void setup() {
  esp_log_level_set("*", ESP_LOG_VERBOSE);
  esp_log_set_vprintf(print_F);
  Serial.begin(115200);
  Serial.println("Starting up");
  // Create the BLE Device
  BLEDevice::init("RBase");

  // Create the BLE Server
  BLEServer *pServer = BLEDevice::createServer();
  pServer->setCallbacks(new MyServerCallbacks());

  // Create the BLE Service
  BLEService *pService = pServer->createService(SERVICE_UUID);

  createChars(pService);

  // Start the service
  pService->start();
  // Start advertising
  pServer->getAdvertising()->addServiceUUID(BLEUUID(SERVICE_UUID));
  pServer->getAdvertising()->start();
  force->setValue("hallo");
    Serial.println("Gestartet");
}
int i=0;
void loop() {
    std::string temp=force->getValue();
    if(temp != "hallo")
    Serial.println(temp.c_str());
  delay(50);
}

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: GATT_READ_NOT_PERMIT on BLE Characteristic Read

Postby chegewara » Tue Feb 20, 2018 8:43 am

As you can see from logs this does not work:

Code: Select all

  esp_log_level_set("*", ESP_LOG_VERBOSE);
  esp_log_set_vprintf(print_F);
You need to change logging level in arduino-ide. Code you pasted here seems to looks fine, but its a small chance that BGM requires encrypted connection (even if so GATT_READ_NOT_PERMIT shouldnt be a problem) or something and without more detailed logs i cant tell you more.
Attachments
debug.JPG
debug.JPG (54.48 KiB) Viewed 9459 times

Tom_Koller
Posts: 3
Joined: Thu Feb 15, 2018 4:14 pm

Re: GATT_READ_NOT_PERMIT on BLE Characteristic Read

Postby Tom_Koller » Tue Feb 20, 2018 10:21 am

Thanks for the Log level settings here is the verbose log:


ets Jun 8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:956
load:0x40078000,len:0
load:0x40078000,len:13076
entry 0x40078a58
Starting up
[D][BLEDevice.cpp:69] createServer(): >> createServer
[D][BLEServer.cpp:304] registerApp(): >> registerApp - 0
[D][BLEDevice.cpp:95] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 3] ... ESP_GATTS_REG_EVT
[D][BLEUtils.cpp:1647] dumpGattServerEvent(): GATT ServerEvent: ESP_GATTS_REG_EVT
[D][BLEUtils.cpp:1791] dumpGattServerEvent(): [status: ESP_GATT_OK, app_id: 0]
[D][BLEServer.cpp:176] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_REG_EVT
[D][BLEServer.cpp:308] registerApp(): << registerApp
[D][BLEServer.cpp:294] handleGATTServerEvent(): << handleGATTServerEvent
[D][BLEDevice.cpp:76] createServer(): << createServer
[D][BLEServer.cpp:76] createService(): >> createService - 4fafc201-1fb5-459e-8fcc-c5c9c331914b
[D][BLEDevice.cpp:95] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 3] ... ESP_GATTS_CREATE_EVT
[D][BLEUtils.cpp:1647] dumpGattServerEvent(): GATT ServerEvent: ESP_GATTS_CREATE_EVT
[D][BLEUtils.cpp:1716] dumpGattServerEvent(): [status: ESP_GATT_OK, service_handle: 40 0x28, service_id: [uuid: 4fafc201-1fb5-459e-8fcc-c5c9c331914b, inst_id: 0]]
[D][BLEServer.cpp:176] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_CREATE_EVT
[D][BLEService.cpp:160] setHandle(): >> setHandle - Handle=0x28, service UUID=4fafc201-1fb5-459e-8fcc-c5c9c331914b)
[D][BLEService.cpp:166] setHandle(): << setHandle
[D][BLEService.cpp:89] executeCreate(): << executeCreate
[D][BLEServer.cpp:294] handleGATTServerEvent(): << handleGATTServerEvent
[D][BLEServer.cpp:93] createService(): << createService
[D][BLEService.cpp:188] addCharacteristic(): >> addCharacteristic()
[D][BLEService.cpp:191] addCharacteristic(): Adding characteristic: uuid=ede93193-cb18-414a-b42e-9dfb2ee8ac9f to service: UUID: 4fafc201-1fb5-459e-8fcc-c5c9c331914b, handle: 0x28
[D][BLEService.cpp:203] addCharacteristic(): << addCharacteristic()
[D][BLECharacteristic.cpp:72] addDescriptor(): >> addDescriptor(): Adding UUID: 00002902-0000-1000-8000-00805f9b34fb, handle: 0xffff to UUID: ede93193-cb18-414a-b42e-9dfb2ee8ac9f, handle: 0xffff Read Write WriteNoResponse Notify Indicate
[D][BLECharacteristic.cpp:74] addDescriptor(): << addDescriptor()
[D][BLEService.cpp:125] start(): >> start(): Starting service (esp_ble_gatts_start_service): UUID: 4fafc201-1fb5-459e-8fcc-c5c9c331914b, handle: 0x28
[D][BLECharacteristic.cpp:83] executeCreate(): >> executeCreate()
[D][BLECharacteristic.cpp:94] executeCreate(): Registering characteristic (esp_ble_gatts_add_char): uuid: ede93193-cb18-414a-b42e-9dfb2ee8ac9f, service: UUID: 4fafc201-1fb5-459e-8fcc-c5c9c331914b, handle: 0x28
[D][BLEDevice.cpp:95] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 3] ... ESP_GATTS_ADD_CHAR_EVT
[D][BLEUtils.cpp:1647] dumpGattServerEvent(): GATT ServerEvent: ESP_GATTS_ADD_CHAR_EVT
[D][BLEUtils.cpp:1669] dumpGattServerEvent(): [status: ESP_GATT_OK, attr_handle: 42 0x2a, service_handle: 40 0x28, char_uuid: ede93193-cb18-414a-b42e-9dfb2ee8ac9f]
[D][BLEServer.cpp:176] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_ADD_CHAR_EVT
[D][BLECharacteristic.cpp:609] setHandle(): >> setHandle: handle=0x2a, characteristic uuid=ede93193-cb18-414a-b42e-9dfb2ee8ac9f
[D][BLECharacteristic.cpp:611] setHandle(): << setHandle
[D][BLECharacteristic.cpp:209] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_ADD_CHAR_EVT
[D][BLECharacteristic.cpp:461] handleGATTServerEvent(): << handleGATTServerEvent
[D][BLEDescriptor.cpp:63] executeCreate(): >> executeCreate(): UUID: 00002902-0000-1000-8000-00805f9b34fb, handle: 0xffff
[D][BLEServer.cpp:294] handleGATTServerEvent(): << handleGATTServerEvent
[D][BLEDevice.cpp:95] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 3] ... ESP_GATTS_ADD_CHAR_DESCR_EVT
[D][BLEUtils.cpp:1647] dumpGattServerEvent(): GATT ServerEvent: ESP_GATTS_ADD_CHAR_DESCR_EVT
[D][BLEUtils.cpp:1657] dumpGattServerEvent(): [status: ESP_GATT_OK, attr_handle: 43 0x2b, service_handle: 40 0x28, char_uuid: 00002902-0000-1000-8000-00805f9b34fb]
[D][BLEServer.cpp:176] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_ADD_CHAR_DESCR_EVT
[D][BLECharacteristic.cpp:209] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_ADD_CHAR_DESCR_EVT
[D][BLEDescriptor.cpp:275] setHandle(): >> setHandle(0x2b): Setting descriptor handle to be 0x2b
[D][BLEDescriptor.cpp:277] setHandle(): << setHandle()
[D][BLECharacteristic.cpp:461] handleGATTServerEvent(): << handleGATTServerEvent
[D][BLEDescriptor.cpp:87] executeCreate(): << executeCreate
[D][BLEServer.cpp:294] handleGATTServerEvent(): << handleGATTServerEvent
[D][BLECharacteristic.cpp:135] executeCreate(): << executeCreate
[D][BLEDevice.cpp:95] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 3] ... ESP_GATTS_START_EVT
[D][BLEUtils.cpp:1647] dumpGattServerEvent(): GATT ServerEvent: ESP_GATTS_START_EVT
[D][BLEUtils.cpp:1805] dumpGattServerEvent(): [status: ESP_GATT_OK, service_handle: 0x28]
[D][BLEServer.cpp:176] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_START_EVT
[D][BLEService.cpp:151] start(): << start()
[D][BLECharacteristic.cpp:209] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_START_EVT
[D][BLEAdvertising.cpp:164] start(): >> start: customAdvData: 0, customScanResponseData: 0
[D][BLECharacteristic.cpp:461] handleGATTServerEvent(): << handleGATTServerEvent
[D][BLEAdvertising.cpp:177] start(): - advertising service: 4fafc201-1fb5-459e-8fcc-c5c9c331914b
[D][BLEServer.cpp:294] handleGATTServerEvent(): << handleGATTServerEvent
[D][BLEAdvertising.cpp:221] start(): << start
[D][BLEUtils.cpp:1091] dumpGapEvent(): Received a GAP event: ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT
[D][BLECharacteristic.cpp:664] setValue(): >> setValue: length=5, data=68616c6c6f, characteristic UUID=ede93193-cb18-414a-b42e-9dfb2ee8ac9f
[D][BLECharacteristic.cpp:671] setValue(): << setVal[D][BLECharacteristic.cpp:671] setValue(): << setValue
[D][BLEServer.cpp:134] handleGAPEvent(): BLEServer ... handling GAP event!
Gestartet
[D][BLEUtils.cpp:1091] dumpGapEvent(): Received a GAP event: ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT
[D][BLEUtils.cpp:1285] dumpGapEvent(): [status: 0]
[D][BLEServer.cpp:134] handleGAPEvent(): BLEServer ... handling GAP event!
[D][BLEUtils.cpp:1091] dumpGapEvent(): Received a GAP event: ESP_GAP_BLE_ADV_START_COMPLETE_EVT
[D][BLEUtils.cpp:1123] dumpGapEvent(): [status: 0]
[D][BLEServer.cpp:134] handleGAPEvent(): BLEServer ... handling GAP event!
[D][BLEDevice.cpp:95] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 3] ... ESP_GATTS_CONNECT_EVT
[D][BLEUtils.cpp:1647] dumpGattServerEvent(): GATT ServerEvent: ESP_GATTS_CONNECT_EVT
[D][BLEUtils.cpp:1707] dumpGattServerEvent(): [conn_id: 0, remote_bda: 00:0b:57:e6:f8:c0]
[D][BLEServer.cpp:176] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_CONNECT_EVT
[D][BLECharacteristic.cpp:209] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_CONNECT_EVT
[D][BLECharacteristic.cpp:461] handleGATTServerEvent(): << handleGATTServerEvent
[D][BLEServer.cpp:294] handleGATTServerEvent(): << handleGATTServerEvent
[D][BLEDevice.cpp:95] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 3] ... ESP_GATTS_MTU_EVT
[D][BLEUtils.cpp:1647] dumpGattServerEvent(): GATT ServerEvent: ESP_GATTS_MTU_EVT
[D][BLEUtils.cpp:1766] dumpGattServerEvent(): [conn_id: 0, mtu: 247]
[BLEDevice.cpp:110] gattServerEventHandler(): ESP_GATTS_MTU_EVT, MTU 247
[D][BLEServer.cpp:176] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_MTU_EVT
[D][BLECharacteristic.cpp:209] handleGATTServerEvent(): >> handleGATTServerEvent: ESP_GATTS_MTU_EVT
[D][BLECharacteristic.cpp:461] handleGATTServerEvent(): << handleGATTServerEvent
[D][BLEServer.cpp:294] handleGATTServerEvent(): << handleGATTServerEvent
E (13595) BT: format mismatch
E (14095) BT: GATT_READ_NOT_PERMIT

E (14595) BT: GATT_READ_NOT_PERMIT

E (15095) BT: GATT_READ_NOT_PERMIT

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 67 guests