Star - Gists · GitHub

Skip to content Search Gists Search Gists All gists Back to GitHub Sign in Sign up Sign in Sign up Dismiss alert {{ message }}

Instantly share code, notes, and snippets.

@JAICHANGPARK JAICHANGPARK/ble_callback.ino Last active July 28, 2018 08:23 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
  • Embed Select an option
    • Embed Embed this gist in your website.
    • Share Copy sharable link for this gist.
    • Clone via HTTPS Clone using the web URL.

    No results found

    Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/JAICHANGPARK/d4e5e71b970a3672523ecd00c551389f.js"></script>
  • Save JAICHANGPARK/d4e5e71b970a3672523ecd00c551389f to your computer and use it in GitHub Desktop.
Code Revisions 4 Embed Select an option
  • Embed Embed this gist in your website.
  • Share Copy sharable link for this gist.
  • Clone via HTTPS Clone using the web URL.

No results found

Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/JAICHANGPARK/d4e5e71b970a3672523ecd00c551389f.js"></script> Save JAICHANGPARK/d4e5e71b970a3672523ecd00c551389f to your computer and use it in GitHub Desktop. Download ZIP [Arduino] Read BLE Byte Array on Arduino 101 ref: https://qiita.com/Dreamwalker/items/4f1d984f99d15e1f0744 Raw ble_callback.ino This file contains hidden or 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 Show hidden characters
/*
Copyright (c) 2016 Intel Corporation. All rights reserved.
See the bottom of this file for the license terms.
*/
#include <CurieBLE.h>
const int ledPin = 13; // set ledPin to use on-board LED
BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // create service
// create switch characteristic and allow remote device to read and write
BLECharacteristic switchChar("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite, 20);
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // use the LED on pin 13 as an output
// begin initialization
BLE.begin();
// set the local name peripheral advertises
BLE.setLocalName("LEDCB");
// set the UUID for the service this peripheral advertises
BLE.setAdvertisedService(ledService);
// add the characteristic to the service
ledService.addCharacteristic(switchChar);
// add service
BLE.addService(ledService);
// assign event handlers for connected, disconnected to peripheral
BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler);
BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);
// assign event handlers for characteristic
switchChar.setEventHandler(BLEWritten, switchCharacteristicWritten);
// set an initial value for the characteristic
switchChar.setValue(0,0);
// start advertising
BLE.advertise();
Serial.println(("Bluetooth device active, waiting for connections..."));
}
void loop() {
// poll for BLE events
BLE.poll();
}
void blePeripheralConnectHandler(BLEDevice central) {
// central connected event handler
Serial.print("Connected event, central: ");
Serial.println(central.address());
}
void blePeripheralDisconnectHandler(BLEDevice central) {
// central disconnected event handler
Serial.print("Disconnected event, central: ");
Serial.println(central.address());
}
int rxHead = 0;
volatile static uint8_t rxBuffer[20];
void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteristic) {
// central wrote new value to characteristic, update LED
Serial.print("Characteristic event, written: ");
size_t len = switchChar.valueLength();
const unsigned char *data = switchChar.value();
Serial.print("Got data:");
Serial.write(data, len);
}
void addReceiveBytes(const uint8_t* bytes, size_t len) {
// note increment rxHead befor writing
// so need to increment rxTail befor reading
for (size_t i = 0; i < len; i++) {
rxHead = (rxHead + 1) % sizeof(rxBuffer);
rxBuffer[rxHead] = bytes[i];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment You can’t perform that action at this time.

Tag » Arduino Ble Byte Array