platformio / platform-nordicnrf51

Nordic nRF51: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/nordicnrf51
Apache License 2.0
20 stars 25 forks source link

Change address and advertisement #40

Open beckmx opened 10 months ago

beckmx commented 10 months ago

Hello guys, I have been trying to change the address of the device, it compiles properly but somehow i am not able to change it, i also want to advertise custom data but no luck yet.

#include <SPI.h>
#include <BLEUtil.h>
#include <BLEPeripheral.h>
#include <utility/RFduino/ble_gap.h>
#include <utility/RFduino/ble_gatt.h>
#include <Arduino.h>

BLEPeripheral *advertiser;
iBeacon beacon;
void setup(){
      // Changing Bluetooth Address
  ble_gap_addr_t gap_address;
  gap_address.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC;
  gap_address.addr[0] = 0xac;  // Least significant byte
  gap_address.addr[1] = 0x06;
  gap_address.addr[2] = 0x50;
  gap_address.addr[3] = 0x97;
  gap_address.addr[4] = 0xa5;
  gap_address.addr[5] = 0xf9;  // Most significant byte

  sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &gap_address);

    advertiser=new(BLEPeripheral);
    advertiser->setConnectable(false);
    uint8_t custom_payload[] = {0xFF,0x4c, 0x00, 0x12, 0x19, 0x00,
  0xf8, 0x6d, 0xa4, 0xbc, 0x43, 0x65, 0x99, 0x62,
  0x0f, 0x53, 0x52, 0x01, 0x3e, 0x1f, 0x94, 0xb4,
  0x3f, 0x91, 0x00, 0x92, 0x54, 0x26,
  0x2, 0x00}; // Example payload
  advertiser->setManufacturerData(custom_payload, sizeof(custom_payload));

  advertiser->begin();
}

In theory i should be able to change the address and avertise but it doesnt happen :(