I'm using an ESP32-S3-WROOM dev board and trying to read data from a PowerTech bluetooth battery monitor. I'm certain that it is a BLE device because I have a bunch of scanner apps that report it as such.
The problem is that the ESP32 is resetting itself every time it connects to the BLE device.
The dev is being done in Arduino IDE 2.0. The selected board is ESP32S3 Dev Module.
I'm using Sensorslot's heart rate watch monitor sketch from GitHub - SensorsIot/Bluetooth-BLE-on-Arduino-IDE: Scketches which are used in my YouTube video. Pretty much all I have changed is the serviceUUID and charUUID. I was able to determine these from via the Android app, BLE Scanner. The Powertech batter monitor app reports the device's address, which I was able to identify in BLE Scanner. From there I was able to drill in and find the service id and characteristic id, which I entered into the code, below.
The code finds the device, creates a client and connects to the server. It finds the service and characteristic and seems to register for notification events... and then the ESP32 crashes and resets. A sample of the output is below. This is just an extract, it goes around and around in circles:
Starting Arduino BLE Client application...
BLE Advertised Device found: Name: , Address: 09:41:df:90:69:52, manufacturer data: 06000109200292439ae769adefa039d2d82ad7ed3fea807c906a535706
BLE Advertised Device found: Name: , Address: 69:92:63:52:85:fb, manufacturer data: 4c001005531c44517e, txPower: 12
BLE Advertised Device found: Name: , Address: 5f:5f:5f:e3:97:7e, manufacturer data: e000041dca912c18, serviceUUID: 0000fe9f-0000-1000-8000-00805f9b34fb
BLE Advertised Device found: Name: , Address: cb:c3:44:23:ac:33, manufacturer data: fc330305
BLE Advertised Device found: Name: LE_WH-1000XM4, Address: c7:e4:db:dd:85:80, serviceUUID: 0000fe03-0000-1000-8000-00805f9b34fb
BLE Advertised Device found: Name: , Address: 3c:9c:c3:90:f4:97, manufacturer data: 06000109200297dea6c6ad1343f03fedd07e51a1449cca4c394cf34143
BLE Advertised Device found: Name: , Address: 59:71:c5:cd:28:1c, manufacturer data: e0000426ca3695c2, serviceUUID: 0000fe9f-0000-1000-8000-00805f9b34fb
BLE Advertised Device found: Name: , Address: 54:7e:27:34:80:e6, manufacturer data: 4c0010053f18e91453, txPower: 8
BLE Advertised Device found: Name: , Address: 56:96:96:cd:77:46, manufacturer data: e0000422ca3c27d3, serviceUUID: 0000fe9f-0000-1000-8000-00805f9b34fb
BLE Advertised Device found: Name: , Address: 76:1f:cb:b2:93:99, manufacturer data: e0000421ca7d5fda, serviceUUID: 0000fe9f-0000-1000-8000-00805f9b34fb
BLE Advertised Device found: Name: Battery Monitor, Address: e0:62:34:e2:55:3d, serviceUUID: 0000fff0-0000-1000-8000-00805f9b34fb, txPower: 0
Found our device! address: Forming a connection to e0:62:34:e2:55:3d
- Created client
- Connecting 1
- Connected to server
- Services: 0
- Found our service
- Created client
- Connecting 1
- Connected to server
- Services: 0
- Found our service
- Found our characteristic
The characteristic value was:
registerForNotify: start
registerForNotify: end
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x42006736 PS : 0x00060830 A0 : 0x820032c5 A1 : 0x3fce2d60
A2 : 0x00000000 A3 : 0x3fce2dce A4 : 0x00000002 A5 : 0x00000001
A6 : 0x3fcf7e74 A7 : 0x00010000 A8 : 0x3fc97e60 A9 : 0x3fce2d30
A10 : 0x3fce2d7c A11 : 0x3fcf7e78 A12 : 0x00000020 A13 : 0x40b98bf6
A14 : 0x3fcf7e74 A15 : 0x3f012db0 SAR : 0x00000013 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000030 LBEG : 0x40056fc5 LEND : 0x40056fe7 LCOUNT : 0x00000000
Backtrace:0x42006733:0x3fce2d600x420032c2:0x3fce2db0 0x42003351:0x3fce2e20 0x42009475:0x3fce2e60
BLE Advertised Device found: Name: , Address: 09:41:df:90:69:52, manufacturer data: 06000109200292439ae769adefa039d2d82ad7ed3fea807c906a535706
BLE Advertised Device found: Name: , Address: cb:c3:44:23:ac:33, manufacturer data: fc330305
BLE Advertised Device found: Name: , Address: c7:e4:db:dd:85:80, manufacturer data: 2d01040001310501c8e47ddf0440d5000000000000, txPower: -21
BLE Advertised Device found: Name: , Address: 54:7e:27:34:80:e6, manufacturer data: 4c0010053f18e91453, txPower: 8
BLE Advertised Device found: Name: , Address: 76:1f:cb:b2:93:99, manufacturer data: e0000421ca7d5fda, serviceUUID: 0000fe9f-0000-1000-8000-00805f9b34fb
BLE Advertised Device found: Name: , Address: 5f:5f:5f:e3:97:7e, manufacturer data: e000041dca912c18, serviceUUID: 0000fe9f-0000-1000-8000-00805f9b34fb
BLE Advertised Device found: Name: Battery Monitor, Address: e0:62:34:e2:55:3d, serviceUUID: 0000fff0-0000-1000-8000-00805f9b34fb, txPower: 0
Found our device! address: Forming a connection to e0:62:34:e2:55:3d
- Created client
- Connecting 1
- Connected to server
- Services: 0
- Found our service
- Found our characteristic
The characteristic value was:
registerForNotify: start
registerForNotify: end
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x42006736 PS : 0x00060830 A0 : 0x820032c5 A1 : 0x3fce2d60
A2 : 0x00000000 A3 : 0x3fce2dce A4 : 0x00000002 A5 : 0x00000001
A6 : 0x3fcf7e74 A7 : 0x00010000 A8 : 0x3fc97e60 A9 : 0x3fce2d30
A10 : 0x3fce2d7c A11 : 0x3fcf7e78 A12 : 0x00000020 A13 : 0x40b98bf6
A14 : 0x3fcf7e74 A15 : 0x3f012db0 SAR : 0x00000013 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000030 LBEG : 0x40056fc5 LEND : 0x40056fe7 LCOUNT : 0x00000000
Backtrace:0x42006733:0x3fce2d600x420032c2:0x3fce2db0 0x42003351:0x3fce2e20 0x42009475:0x3fce2e60
ELF file SHA256: 0000000000000000
The sketch is below:
/*
*
* This sketch emulates a Heart rate watch and is able to receive BLE signals of a Polar H7 Heart Rate Sensor.
* It shows the received values in Serial and is also able to switch notificaton on the sensor on and off (using BLE2902)
Copyright <2017> <Andreas Spiess>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Based on Neil Kolban's example file: https://github.com/nkolban/ESP32_BLE_Arduino
*/
#include "BLEDevice.h"
//#include "BLEScan.h"
// The remote service we wish to connect to.
static BLEUUID serviceUUID(BLEUUID((uint16_t)0x1801));
// The characteristic of the remote service we are interested in.
static BLEUUID charUUID(BLEUUID((uint16_t)0x2a05));
static BLEAddress *pServerAddress;
static boolean doConnect = false;
static boolean connected = false;
static BLERemoteCharacteristic* pRemoteCharacteristic;
BLEUUID powerPalUUID;
static void notifyCallback(
BLERemoteCharacteristic* pBLERemoteCharacteristic,
uint8_t* pData,
size_t length,
bool isNotify) {
Serial.print("Notify callback for characteristic ");
for (int i = 0; i < length; i++) {
Serial.print(pData[i]);
Serial.print(" ");
}
Serial.println();
}
bool connectToServer(BLEAddress pAddress) {
Serial.print("Forming a connection to ");
Serial.println(pAddress.toString().c_str());
BLEClient* pClient = BLEDevice::createClient();
Serial.println(" - Created client");
// Connect to the remove BLE Server.
Serial.print(" - Connecting "); Serial.println(pClient->connect(pAddress));
Serial.println(" - Connected to server");
Serial.print(" - Services: "); Serial.println(String(pClient->getConnId()));
// Obtain a reference to the service we are after in the remote BLE server.
BLERemoteService* pRemoteService = pClient->getService(serviceUUID);
if (pRemoteService == nullptr) {
Serial.print("Failed to find our service UUID: ");
Serial.println(serviceUUID.toString().c_str());
return false;
}
Serial.println(" - Found our service");
// Obtain a reference to the characteristic in the service of the remote BLE server.
pRemoteCharacteristic = pRemoteService->getCharacteristic(charUUID);
if (pRemoteCharacteristic == nullptr) {
Serial.print("Failed to find our characteristic UUID: ");
Serial.println(charUUID.toString().c_str());
return false;
}
Serial.println(" - Found our characteristic");
// Read the value of the characteristic.
std::string value = pRemoteCharacteristic->readValue();
Serial.print("The characteristic value was: ");
Serial.println(value.c_str());
Serial.println("registerForNotify: start");
pRemoteCharacteristic->registerForNotify(notifyCallback);
Serial.println("registerForNotify: end");
const uint8_t indicationOn[] = {0x2, 0x0};
pRemoteCharacteristic->getDescriptor(BLEUUID((uint16_t)0x2902))->writeValue((uint8_t*)indicationOn, 2, true);
}
/**
Scan for BLE servers and find the first one that advertises the service we are looking for.
*/
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
/**
Called for each advertising BLE server.
*/
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.getServiceUUID().equals(serviceUUID)) {
//
Serial.print("Found our device! address: ");
advertisedDevice.getScan()->stop();
pServerAddress = new BLEAddress(advertisedDevice.getAddress());
doConnect = true;
} // Found our server
} // onResult
}; // MyAdvertisedDeviceCallbacks
void setup() {
Serial.begin(115200);
Serial.println("Starting Arduino BLE Client application...");
BLEDevice::init("");
// Retrieve a Scanner and set the callback we want to use to be informed when we
// have detected a new device. Specify that we want active scanning and start the
// scan to run for 30 seconds.
BLEScan* pBLEScan = BLEDevice::getScan();
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(true);
pBLEScan->start(30);
} // End of setup.
const uint8_t notificationOff[] = {0x0, 0x0};
const uint8_t notificationOn[] = {0x1, 0x0};
bool onoff = true;
void loop() {
// If the flag "doConnect" is true then we have scanned for and found the desired
// BLE Server with which we wish to connect. Now we connect to it. Once we are
// connected we set the connected flag to be true.
if (doConnect == true) {
if (connectToServer(*pServerAddress)) {
Serial.println("We are now connected to the BLE Server.");
connected = true;
} else {
Serial.println("We have failed to connect to the server; there is nothin more we will do.");
}
doConnect = false;
}
// If we are connected to a peer BLE Server, update the characteristic each time we are reached
// with the current time since boot.
if (connected) {
if (onoff) {
Serial.println("Notifications turned on");
pRemoteCharacteristic->getDescriptor(BLEUUID((uint16_t)0x2902))->writeValue((uint8_t*)notificationOn, 2, true);
}
else {
Serial.println("Notifications turned off");
pRemoteCharacteristic->getDescriptor(BLEUUID((uint16_t)0x2902))->writeValue((uint8_t*)notificationOff, 2, true);
}
onoff = onoff ? 0 : 1;
}
delay(10000); // Delay a second between loops.
} // End of loop
This is the Powertech Battery Monitor app, showing the device address
This is the BLE Scanner app, identifying the device at the expected address
Service and characteristic id's in BLE Scanner
Any thought on why the device is repeatedly crashing would be greatly appreciated.









