Skip to content

Instantly share code, notes, and snippets.

@wwj718
Created November 5, 2023 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wwj718/2004f9d24dfa77eaae98d59e7227a683 to your computer and use it in GitHub Desktop.
Save wwj718/2004f9d24dfa77eaae98d59e7227a683 to your computer and use it in GitHub Desktop.
#include <Arduino.h>
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEAdvertisedDevice.h>
BLEAdvertising* pAdvertising = NULL;
void setup() {
Serial.begin(115200);
Serial.println("Starting BLE work!");
BLEDevice::init("MicroBlocks OctoStudio");
pAdvertising = BLEDevice::getAdvertising();
}
void loop() {
pAdvertising->stop();
int randomNumber = random(256);
// The first four bytes are random numbers
uint8_t service_data[] = {0x2a, 0xa6, 0x84, randomNumber, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00};
BLEAdvertisementData advertisementData = BLEAdvertisementData();
advertisementData.setServiceData(BLEUUID("2540b6b0-0001-4538-bcd7-7ecfb51297c1"), std::string((char*)service_data, 13));
pAdvertising->setAdvertisementData(advertisementData);
pAdvertising->start();
delay(3000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment