B4R Code Snippet [ESP32] enable BT or BLE and get MAC-address

Module name 'others':
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public MacArray(6) As Byte
End Sub


Sub Get_btMacAddress(ble As Boolean)
    RunNative("getBTMac", ble)
End Sub
#if C
#include "esp_bt.h"
#include "esp_bt_main.h"
#include "esp_bt_device.h"
  void getBTMac(B4R::Object* o) {
      if (o->toLong() == 0) {
        esp_bt_controller_enable(ESP_BT_MODE_CLASSIC_BT);
    }else{
        esp_bt_controller_enable(ESP_BT_MODE_BLE);
    }
    esp_bluedroid_init();
    esp_bluedroid_enable();
    esp_read_mac((Byte*)b4r_others::_macarray->data, ESP_MAC_BT);
  }
#end if

Note: WiFi mac-address and BT mac address are different.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…