Skip to content

Instantly share code, notes, and snippets.

@don
Last active January 26, 2018 06:06
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 don/536d9f1d605d9bfffcd99b5716a72cb4 to your computer and use it in GitHub Desktop.
Save don/536d9f1d605d9bfffcd99b5716a72cb4 to your computer and use it in GitHub Desktop.
Demonstrate BLE broadcast for connectionless data transfer
// Broadcast Characteristic Value
// Simple counter that broadcasts a value
#ifdef ARDUINO_ARCH_ARC32 // Arduino 101
#include <CurieBLE.h>
#else
#include <BLEPeripheral.h>
#endif
uint8_t value = 0;
BLEPeripheral peripheral;
BLEService service = BLEService("EEE0");
BLEShortCharacteristic characteristic = BLEShortCharacteristic("EEE1", BLERead | BLENotify | BLEBroadcast);
void setup() {
Serial.begin(9600);
peripheral.setLocalName("BLEBroadcast");
peripheral.setAdvertisedServiceUuid(service.uuid());
peripheral.addAttribute(service);
peripheral.addAttribute(characteristic);
characteristic.setValue(value);
peripheral.begin();
characteristic.broadcast();
Serial.println(F("BLE Broadcast Count"));
}
void loop() {
peripheral.poll();
characteristic.setValue(value);
delay(1000);
value++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment