esp32-snippets icon indicating copy to clipboard operation
esp32-snippets copied to clipboard

How to initialise BLEAddress(advertisedDevice.getAddress())

Open skyng22003 opened this issue 6 years ago • 4 comments

I have read your previous post about removing "new" from "MyAdvertisedDeviceCallbacks" in the BLE Device example.

I was wondering how you would replace the "new" in BLEAddress(advertisedDevice.getAddress()); in the following code:

void MyAdvertisedDeviceCallbacks::onResult(BLEAdvertisedDevice advertisedDevice) {

	/**
	* Called for each advertising BLE server.
	*/
	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());
	
		BT_conStatus = doConnect;
	} // Found our server

Thanks again for your help!

skyng22003 avatar Aug 02 '18 22:08 skyng22003

Hi, I am also hoping there is another way to compare MAC addresses from an iBeacon. Massive memory leak. Stopping the scan or clearing the results or anything else short of reseting the ESP32, doesn't release the memory used by this line:

pServerAddress = new BLEAddress(Device.getAddress());

Tom5051 avatar Jan 15 '20 00:01 Tom5051

When you create class object with new, you have to delete it when no longer required.

chegewara avatar Jan 16 '20 01:01 chegewara

When you create class object with new, you have to delete it when no longer required.

Thank you! This worked :)

delete pServerAddress; pServerAddress = NULL;

Tom5051 avatar Jan 16 '20 01:01 Tom5051

When you create class object with new, you have to delete it when no longer required.

Thank you! This worked :)

delete pServerAddress; pServerAddress = NULL;

Hi,

Could you share the entire your code for us?

Best Regards,

JKSAR avatar Feb 06 '21 06:02 JKSAR