Using a custom Advertising Address

ruppie
Posts: 9
Joined: Sat Jan 20, 2018 9:34 am

Using a custom Advertising Address

Postby ruppie » Wed Jul 15, 2020 5:16 am

Hello,
i am building a "digital twin" of an LEGO technic Hub, by using an ESP32.
Target is that ESP32 can be connected to LEGO BLE Apps.

At least i have concerns, that one reason i did not get a connecteion request is because LEGO Apps using Address Filters .
An Example of a LEGO HUB Adress is like:Advertising Address: LegoSyst_4a:3a:0c (90:84:2b:4a:3a:0c) ( a hub owned by me)
As you may know ours is like: Advertising Address: Espressi_cb:69:fa (bc:dd:c2:cb:69:fa)

Question is, how to change Advertising address is scetch to be shown as "LegoSyste" like : 90:84:2b:aa:bb:cc for example

Thanks in advance

Marc

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

Re: Using a custom Advertising Address

Postby chegewara » Wed Jul 15, 2020 3:32 pm

Start with this:
https://maclookup.app/macaddress/90842B

As you can see this is part of mac addresses registered by LEGO System A/S, and here is espressif:
https://maclookup.app/vendors/espressif-inc

I dont remember now if you can set particular bluetooth mac with IDF API, but its not possible with arduino library.

ruppie
Posts: 9
Joined: Sat Jan 20, 2018 9:34 am

Re: Using a custom Advertising Address

Postby ruppie » Wed Jul 15, 2020 7:54 pm

"but its not possible with arduino library."


It was solved by another helping hand:

Code: Select all

/*
    Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleServer.cpp
    Ported to Arduino ESP32 by Evandro Copercini
    updates by chegewara
*/

#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>

// Set your new MAC Address
uint8_t newMACAddress[] = {0x90, 0x84, 0x2B, 0x4A, 0x3A, 0x0A};


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

#define SERVICE_UUID        "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"

void setup() {
  Serial.begin(115200);
  Serial.println("Starting BLE work!");
   
  esp_base_mac_addr_set(&newMACAddress[0]);

  BLEDevice::init("Long name works now");
  BLEServer *pServer = BLEDevice::createServer();
  BLEService *pService = pServer->createService(SERVICE_UUID);
  BLECharacteristic *pCharacteristic = pService->createCharacteristic(
                                         CHARACTERISTIC_UUID,
                                         BLECharacteristic::PROPERTY_READ |
                                         BLECharacteristic::PROPERTY_WRITE
                                       );

  pCharacteristic->setValue("Hello World says Neil");
  pService->start();
  // BLEAdvertising *pAdvertising = pServer->getAdvertising();  // this still is working for backward compatibility
  BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
  pAdvertising->addServiceUUID(SERVICE_UUID);
  pAdvertising->setScanResponse(true);
  pAdvertising->setMinPreferred(0x06);  // functions that help with iPhone connections issue
  pAdvertising->setMinPreferred(0x12);
  BLEDevice::startAdvertising();
  Serial.println("Characteristic defined! Now you can read it in your phone!");
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(2000);
}

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 63 guests