ESP32 BLE 2018 V 2019 boards problem

hokahonay
Posts: 1
Joined: Wed Dec 04, 2019 10:32 am

ESP32 BLE 2018 V 2019 boards problem

Postby hokahonay » Wed Dec 04, 2019 10:39 am

i have developed a BLE project using Arduino to the point where i thought it was completed
to test it fully i needed more boards which i bought from Ebay, my original boards were bought in 2018 the new boards late 2019.
using the 2018 boards both server and client function perfectly and exactly as expected.
using a 2018 server and 2019 client i run into problems,
firstly the client can no longer connect to the server and for a long time the advertised device callback reports nothing. then after several minutes usually about 10 the client callback will report finding the server once, no attempt is made at connection ant the esp locks until reset is pressed
my code for the client is:
`

Code: Select all

#include "BLEDevice.h"

static BLEAdvertisedDevice* myDevice;
// custom service 1 PickleService
static BLEUUID PickleService("94698a03-dbb1-42b2-acb6-cc1abdffac35");
// custom characteristic 1 PickleChar
static BLEUUID PickleChar("94698a04-dbb1-42b2-acb6-cc1abdffac35");
static BLERemoteCharacteristic* pPickleChar;

static BLEScan* pBLEScan;

std::string PicksAddress = "a4:cf:12:26:10:d6";
std::string deviceAddress;
std::string serviceUUID;
long sTmr;

class MyClientCallback : public BLEClientCallbacks {
void onConnect(BLEClient* pclient) {
connected = true;
doScan = false;
}

void onDisconnect(BLEClient* pclient) {
connected = false;
doScan = true;
Serial.println("onDisconnect");
}
};
//================================================

static void notifyCallback(
BLERemoteCharacteristic* pBLERemoteCharacteristic,
uint8_t* pData,
size_t length,
bool isNotify) {
pData[length] = '\0';
NData = (char*)pData;
notified = true;
}
//================================================
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) {
Serial.print("BLE Advertised Device found: ");
Serial.println(advertisedDevice.toString().c_str());

// We have found a device, let us now see if it contains the service we are looking for.
if (advertisedDevice.haveServiceUUID() && advertisedDevice.isAdvertisingService(PickleService)) {

  BLEDevice::getScan()->stop();
  myDevice = new BLEAdvertisedDevice(advertisedDevice);
  doConnect = true;
  doScan = false;

} else Serial.println("Not Picks UUID");
} // onResult
}; // MyAdvertisedDeviceCallbacks

//================================================
bool connectToServer() {
// Serial.print("Forming a connection to ");
// Serial.println(myDevice->getAddress().toString().c_str());

BLEClient*  pClient  = BLEDevice::createClient();
Serial.println(" - Created client");

pClient->setClientCallbacks(new MyClientCallback());

// Connect to the remove BLE Server.
pClient->connect(myDevice);  // if you pass BLEAdvertisedDevice instead of address, it will be recognized type of peer device address (public or private)
Serial.println(" - Connected to server");

// Obtain a reference to the service we are after in the remote BLE server.
BLERemoteService* pRemoteService = pClient->getService(PickleService);
if (pRemoteService == nullptr) {
  Serial.print("Failed to find our service UUID: ");
  Serial.println(PickleService.toString().c_str());
  pClient->disconnect();
  return false;
}
Serial.println(" - Found our service");


// Obtain a reference to the characteristic in the service of the remote BLE server.
BLERemoteCharacteristic *pRemoteCharacteristic = pRemoteService->getCharacteristic(PickleChar);
if (pRemoteCharacteristic == nullptr) {
  Serial.print("Failed to find our characteristic UUID: ");
  Serial.println(PickleChar.toString().c_str());
  pClient->disconnect();
  return false;
}
Serial.println(" - Found our characteristic");

// Read the value of the characteristic.
if(pRemoteCharacteristic->canRead()) {
  std::string value = pRemoteCharacteristic->readValue();
  Serial.print("The characteristic value was: ");
  Serial.println(value.c_str());
}

if(pRemoteCharacteristic->canNotify())
  pRemoteCharacteristic->registerForNotify(notifyCallback);
connected = true;
	return true;
}
//================================================
void setup() {
Serial.println("- Client2 -");
BLEDevice::init("");
doScan = true;
pBLEScan = BLEDevice::getScan();
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setInterval(1000);
pBLEScan->setWindow(1000);
pBLEScan->setActiveScan(true);
clientLoop();
}
//================================================
void loop() {
if(!connected) {
if(!doConnect) {
if(doScan) {
if(millis() > sTmr) {
pBLEScan->start(5, false); // 5 groups of 1 sec
Serial.println("Scanning");
sTmr = millis() + 6000;
}
}
} else {
if(!connectToServer()) {
Serial.println("Unable to Connect");
}
// Serial.println("Connected");
}
} else if(notified) {
Serial.print("Notify Data: ");
Serial.println(NData);
notified = false;

	writeEEProm(switchLoc, switchVal);
	writeEEProm(modeLoc, 'S');
	delay(100);
	ESP.restart();
}
}
//================================================
the output from the serial monitor with verbose output is:[V][BLEUtils.cpp:1818] gapEventToString(): gapEventToString: Unknown event type 2 0x02
[V][FreeRTOS.cpp:70] wait(): >> wait: Semaphore waiting: name: ScanEnd (0x3ffde100), owner: start for start
[V][BLEUtils.cpp:1050] dumpGapEvent(): Received a GAP event: Unknown event type
[V][BLEUtils.cpp:1265] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
[V][BLEUtils.cpp:1818] gapEventToString(): gapEventToString: Unknown event type 7 0x07
[V][BLEUtils.cpp:1050] dumpGapEvent(): Received a GAP event: Unknown event type
[V][BLEUtils.cpp:1265] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
[V][BLEUtils.cpp:1818] gapEventToString(): gapEventToString: Unknown event type 3 0x03
[V][BLEUtils.cpp:1050] dumpGapEvent(): Received a GAP event: Unknown event type
[V][BLEUtils.cpp:1265] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
[W][BLEScan.cpp:78] handleGAPEvent(): ESP_GAP_SEARCH_INQ_CMPL_EVT
[V][FreeRTOS.cpp:120] give(): Semaphore giving: name: ScanEnd (0x3ffde100), owner: start
[V][FreeRTOS.cpp:86] wait(): << wait: Semaphore released: name: ScanEnd (0x3ffde100), owner: start
[D][BLEScan.cpp:204] start(): >> start(duration=5)
[D][FreeRTOS.cpp:165] take(): Semaphore taking: name: ScanEnd (0x3ffde100), owner: <N/A> for start
[D][FreeRTOS.cpp:174] take(): Semaphore taken: name: ScanEnd (0x3ffde100), owner: start
[D][BLEScan.cpp:236] start(): << start()

to here repeats until the following line

BLE Advertised Device found: Name: Middle Server, Address: 3c:71:bf:9e:24:4a, serviceUUID: 94698a03-dbb1-42b2-acb6-cc1abdffac35, txPower: 3
[D][BLEScan.cpp:259] stop(): >> stop()
[V][FreeRTOS.cpp:120] give(): Semaphore giving: name: ScanEnd (0x3ffde100), owner: start
[D][BLEScan.cpp:271] stop(): << stop()
[V][FreeRTOS.cpp:86] wait(): << wait: Semaphore released: name: ScanEnd (0x3ffde100), owner: start
[V][BLEUtils.cpp:1818] gapEventToString(): gapEventToString: Unknown event type 18 0x12
[V][BLEUtils.cpp:1050] dumpGapEvent(): Received a GAP event: Unknown event type
[D][BLEDevice.cpp:62] createClient(): >> createClient
[V][BLEUtils.cpp:1265] dumpGapEvent(): *** dumpGapEvent: Logger not coded ***
[D][BLEDevice.cpp:68] createClient(): << createClient
[D][BLEClient.cpp:464] handleGAPEvent(): BLEClient ... handling GAP event!
[D][BLEClient.cpp:103] connect(): >> connect(3c:71:bf:9e:24:4a)
[BLEDevice.cpp:596] addPeerDevice(): add conn_id: 0, GATT role: client
[D][FreeRTOS.cpp:165] take(): Semaphore taking: name: RegEvt (0x3ffde30c), owner: <N/A> for connect
[D][FreeRTOS.cpp:174] take(): Semaphore taken: name: RegEvt (0x3ffde30c), owner: connect
[V][FreeRTOS.cpp:70] wait(): >> wait: Semaphore waiting: name: RegEvt (0x3ffde30c), owner: connect for connect
[V][BLEUtils.cpp:952] gattClientEventTypeToString(): Unknown GATT Client event type: 0
[D][BLEDevice.cpp:150] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[V][BLEUtils.cpp:952] gattClientEventTypeToString(): Unknown GATT Client event type: 0
[V][BLEUtils.cpp:1284] dumpGattClientEvent(): GATT Event: Unknown
[V][BLEUtils.cpp:952] gattClientEventTypeToString(): Unknown GATT Client event type: 0
[D][BLEClient.cpp:165] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[V][FreeRTOS.cpp:120] give(): Semaphore giving: name: RegEvt (0x3ffde30c), owner: connect
[V][FreeRTOS.cpp:86] wait(): << wait: Semaphore released: name: RegEvt (0x3ffde30c), owner: connect
[D][FreeRTOS.cpp:165] take(): Semaphore taking: name: OpenEvt (0x3ffde868), owner: <N/A> for connect
[D][FreeRTOS.cpp:174] take(): Semaphore taken: name: OpenEvt (0x3ffde868), owner: connect
[V][FreeRTOS.cpp:70] wait(): >> wait: Semaphore waiting: name: OpenEvt (0x3ffde868), owner: connect for connect
[V][BLEUtils.cpp:952] gattClientEventTypeToString(): Unknown GATT Client event type: 41
[D][BLEDevice.cpp:150] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[V][BLEUtils.cpp:952] gattClientEventTypeToString(): Unknown GATT Client event type: 41
[V][BLEUtils.cpp:1284] dumpGattClientEvent(): GATT Event: Unknown
[V][BLEUtils.cpp:952] gattClientEventTypeToString(): Unknown GATT Client event type: 41
[D][BLEClient.cpp:165] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[BLEDevice.cpp:607] removePeerDevice(): remove: 0, GATT role client
[V][FreeRTOS.cpp:120] give(): Semaphore giving: name: RssiCmplEvt (0x3ffde928), owner: <N/A>
[V][FreeRTOS.cpp:120] give(): Semaphore giving: name: SearchCmplEvt (0x3ffde8c8), owner: <N/A>
[V][BLEUtils.cpp:952] gattClientEventTypeToString(): Unknown GATT Client event type: 2
[D][BLEDevice.cpp:150] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[V][BLEUtils.cpp:952] gattClientEventTypeToString(): Unknown GATT Client event type: 2
[V][BLEUtils.cpp:1284] dumpGattClientEvent(): GATT Event: Unknown
[V][BLEUtils.cpp:952] gattClientEventTypeToString(): Unknown GATT Client event type: 1
[D][BLEDevice.cpp:150] gattClientEventHandler(): gattClientEventHandler [esp_gatt_if: 4] ... Unknown
[V][BLEUtils.cpp:952] gattClientEventTypeToString(): Unknown GATT Client event type: 1
[V][BLEUtils.cpp:1284] dumpGattClientEvent(): GATT Event: Unknown
`
if anyone can find a problem in my code causing this i would be VERY grateful and have less grey hairs at the end of it
otherwise is anyone experiencing or had a similar problem. on the espressif site there was a case where one user was experiencing WiFi problems with the 2019 boards another thought is that this might be a similar issue.

it is also worth mentioning that a server app on my phone does register with my client but not connect (as expected) so this seems to be an esp 'thing'
My server esp (2018 board) is also found and connected to by my phone and notify's data ok
i would be very grateful for any help anyone can give
thanks in advance
Dave

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: ESP32 BLE 2018 V 2019 boards problem

Postby WiFive » Thu Dec 05, 2019 12:35 pm

If the binary is the same and you fully erased the flash then it could be a hardware rf problem. There was a report of a bad capacitor issue on this forum but I don't think there was any official statement about it.

Who is online

Users browsing this forum: No registered users and 105 guests