-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d11fb3d
commit 2d7a339
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
This example configures LinkIt 7697 to act as a simple GATT server with 1 characteristic. | ||
To use it, open AppInventor project: | ||
* | ||
Build & install it on Android id | ||
created Mar 2017 | ||
*/ | ||
#include <LBLE.h> | ||
#include <LBLEPeriphral.h> | ||
|
||
// Define a simple GATT service with only 1 characteristic | ||
LBLEService ledService("19B10010-E8F2-537E-4F6C-D104768A1214"); | ||
LBLECharacteristicInt switchCharacteristic("19B10011-E8F2-537E-4F6C-D104768A1214", LBLE_READ | LBLE_WRITE); | ||
|
||
void setup() { | ||
|
||
// Initialize LED pin | ||
pinMode(LED_BUILTIN, OUTPUT); | ||
digitalWrite(LED_BUILTIN, LOW); | ||
|
||
//Initialize serial and wait for port to open: | ||
Serial.begin(9600); | ||
|
||
// Initialize BLE subsystem | ||
LBLE.begin(); | ||
while (!LBLE.ready()) { | ||
delay(100); | ||
} | ||
Serial.println("BLE ready"); | ||
|
||
Serial.print("Device Address = ["); | ||
Serial.print(LBLE.getDeviceAddress()); | ||
Serial.println("]"); | ||
|
||
// configure our advertisement data. | ||
// In this case, we simply create an advertisement that represents an | ||
// connectable device with a device name | ||
LBLEAdvertisementData advertisement; | ||
advertisement.configAsConnectableDevice("BLE LED"); | ||
|
||
// Configure our device's Generic Access Profile's device name | ||
// Ususally this is the same as the name in the advertisement data. | ||
LBLEPeripheral.setName("BLE LED"); | ||
|
||
// Add characteristics into ledService | ||
ledService.addAttribute(switchCharacteristic); | ||
|
||
// Add service to GATT server (peripheral) | ||
LBLEPeripheral.addService(ledService); | ||
|
||
// start the GATT server - it is now | ||
// available to connect | ||
LBLEPeripheral.begin(); | ||
|
||
// start advertisment | ||
LBLEPeripheral.advertise(advertisement); | ||
} | ||
|
||
void loop() | ||
{ | ||
delay(100); | ||
|
||
if (switchCharacteristic.isWritten()) { | ||
const char value = switchCharacteristic.getValue(); | ||
Serial.println(value); | ||
switch (value) { | ||
case 1: | ||
digitalWrite(LED_BUILTIN, HIGH); | ||
break; | ||
case 0: | ||
digitalWrite(LED_BUILTIN, LOW); | ||
break; | ||
default: | ||
Serial.println("Unknown value written"); | ||
break; | ||
} | ||
switchCharacteristic.setValue(digitalRead(LED_BUILTIN)); | ||
} | ||
|
||
} |