#include "sys/time.h"
#include "BLEDevice.h"
#include "BLEUtils.h"
#include "BLEServer.h"
#include "BLEBeacon.h"
#include "esp_sleep.h"
#define GPIO_DEEP_SLEEP_DURATION 1 // Сон в секундах
BLEAdvertising *pAdvertising;
#define BEACON_UUID "6dfe576b5525-f9af-6e46-f8f5-307f40b9"
void setBeacon()
{
BLEBeacon oBeacon = BLEBeacon();
oBeacon.setManufacturerId(0x4C00); // fake Apple 0x004C LSB (ENDIAN_CHANGE_U16!)
oBeacon.setProximityUUID(BLEUUID(BEACON_UUID));
oBeacon.setMajor(0x0001);
oBeacon.setMinor(0x0001);
oBeacon.setSignalPower(0x46)
; BLEAdvertisementData oAdvertisementData = BLEAdvertisementData();
BLEAdvertisementData oScanResponseData = BLEAdvertisementData();
oAdvertisementData.setFlags(0x04); // BR_EDR_NOT_SUPPORTED 0x04
std::string strServiceData = "";
strServiceData += (char)26; // Len
strServiceData += (char)0xFF; // Type
strServiceData += oBeacon.getData();
oAdvertisementData.addData(strServiceData);
pAdvertising->setAdvertisementData(oAdvertisementData);
pAdvertising->setScanResponseData(oScanResponseData);
}
void setup()
{
BLEDevice::init("iBeacon");
BLEServer *pServer = BLEDevice::createServer()
; pAdvertising = BLEDevice::getAdvertising();
BLEDevice::startAdvertising();
setBeacon();
pAdvertising->start();
delay(100);
pAdvertising->stop();
esp_deep_sleep(1000000LL * GPIO_DEEP_SLEEP_DURATION);
}
void loop()
{
}