bool isAdvertising = false;
#define BEACON_UUID "8ec76ea3-6668-48da-9866-75be8bc86f4d"
static void taskHello(void *) {
}
static void taskLEDOff(void *) {
}
static void eventButtonPressed() {
if (!pAdvertising) {
Serial.printf("* BLE Advertiser is not initialized.\n");
return;
}
if (isAdvertising) {
Serial.printf("* Turn off beacon!\n");
isAdvertising = false;
} else {
Serial.printf("* Turn on beacon!\n");
isAdvertising = true;
}
}
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println("*** [nRF52-DK] BLE Beacon ***");
System.ledOn(0);
timerHello.
onFired(taskHello, NULL);
timerLEDOff.
onFired(taskLEDOff, NULL);
System.onButtonPressed(0, eventButtonPressed);
BLEDevice::init("");
BLEServer *pServer = BLEDevice::createServer();
pAdvertising = pServer->
getAdvertising();
oBeacon.
setManufacturerId(0x4C00);
oBeacon.
setProximityUUID(
BLEUUID(BEACON_UUID));
oBeacon.
setMajor(0x0102);
oBeacon.
setMinor(0x0304);
oAdvertisementData.
setFlags(0x04);
std::string strServiceData = "";
strServiceData += (char)26;
strServiceData += (char)0xFF;
strServiceData += oBeacon.
getData();
oAdvertisementData.
addData(strServiceData);
oScanResponseData.
setName(
"CoXlab");
isAdvertising = true;
Serial.println("* Advertising started...");
}
Representation of a beacon.
Advertisement data set by the programmer to be published by the BLE server.
Definition BLEAdvertising.hpp:43
Perform and manage BLE advertising.
Definition BLEAdvertising.hpp:73
void stop()
Stop advertising. Stop advertising.
void setScanResponseData(BLEAdvertisementData &advertisementData)
Set the advertisement data that is to be published in a scan response.
void setAdvertisementData(BLEAdvertisementData &advertisementData)
Set the advertisement data that is to be published in a regular advertisement.
void start()
Start advertising. Start advertising.
Representation of a beacon. See:
Definition BLEBeacon.hpp:42
The model of a BLE server.
Definition BLEServer.hpp:89
A model of a BLE UUID.
Definition BLEUUID.hpp:41
Timer는 일정 시간 이후에 1회 실행될 작업, 매 일정 시간마다 실행될 작업 등을 위한 기능입니다.
Definition Timer.hpp:61
void stop()
예약된, 혹은 측정 중인 Timer를 중단합니다.
bool startOneShot(uint32_t millis, bool interrupt=false)
작업함수를 millis 밀리초 이후 1회 실행합니다.
bool startPeriodic(uint32_t millis, bool interrupt=false)
작업함수를 매 millis 밀리초 주기로 반복하여 실행합니다.
void onFired(void(*func)(void *), void *args=nullptr)
타이머 만료시 실행시킬 작업함수를 지정합니다.
bool digitalWrite(int8_t pin, int value)
pin 를 HIGH 또는 LOW 로 설정합니다.
bool pinMode(int8_t pin, enum ioDirection direction)
pin 을 direction 방향을 갖는 디지털 핀으로 동작하도록 설정합니다.
@ OUTPUT
Definition nola-common.h:383