Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add a new BLE service to Bluno nano? #5

Open
jimmyntu opened this issue Dec 17, 2015 · 1 comment
Open

How to add a new BLE service to Bluno nano? #5

jimmyntu opened this issue Dec 17, 2015 · 1 comment

Comments

@jimmyntu
Copy link

I tried below, seems doesn't work

include <SPI.h>

include <BLEPeripheral.h>

define BLE_REQ 10

define BLE_RDY 2

define BLE_RST 9

// LED and button pin

define LED_PIN 3

define BUTTON_PIN 4

// create peripheral instance, see pinouts above
BLEPeripheral blePeripheral = BLEPeripheral(BLE_REQ, BLE_RDY, BLE_RST);

// create service
BLEService ledService = BLEService("19b10010e8f2537e4f6cd104768a1214");

// create switch and button characteristic
BLECharCharacteristic switchCharacteristic = BLECharCharacteristic("19b10011e8f2537e4f6cd104768a1214", BLERead | BLEWrite);
BLECharCharacteristic buttonCharacteristic = BLECharCharacteristic("19b10012e8f2537e4f6cd104768a1214", BLERead | BLENotify);

void setup() {
Serial.begin(115200);

if defined (AVR_ATmega32U4)

delay(5000); //5 seconds delay for enabling to see the start up comments on the serial board

endif

// set LED pin to output mode, button pin to input mode
pinMode(LED_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT);

// set advertised local name and service UUID
blePeripheral.setLocalName("LED Switch");
blePeripheral.setAdvertisedServiceUuid(ledService.uuid());

// add service and characteristics
blePeripheral.addAttribute(ledService);
blePeripheral.addAttribute(switchCharacteristic);
blePeripheral.addAttribute(buttonCharacteristic);

// begin initialization
blePeripheral.begin();

Serial.println(F("BLE LED Switch Peripheral"));
}

void loop() {
// poll peripheral
blePeripheral.poll();

// read the current button pin state
char buttonValue = digitalRead(BUTTON_PIN);

// has the value changed since the last read
bool buttonChanged = (buttonCharacteristic.value() != buttonValue);

if (buttonChanged) {
// button state changed, update characteristics
switchCharacteristic.setValue(buttonValue);
buttonCharacteristic.setValue(buttonValue);
}

if (switchCharacteristic.written() || buttonChanged) {
// update LED, either central has written to characteristic or button state has changed
if (switchCharacteristic.value()) {
Serial.println(F("LED on"));
digitalWrite(LED_PIN, HIGH);
} else {
Serial.println(F("LED off"));
digitalWrite(LED_PIN, LOW);
}
}
}

@ustincameron
Copy link

Did you ever figure out how to read the bluno serial or get notifs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants