Skip to content

Instantly share code, notes, and snippets.

@loginov-rocks
Created August 27, 2018 00:59
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 loginov-rocks/b060cecbe50f09f40e2c29f6e3b7dc67 to your computer and use it in GitHub Desktop.
Save loginov-rocks/b060cecbe50f09f40e2c29f6e3b7dc67 to your computer and use it in GitHub Desktop.
How to make a web app for your own Bluetooth Low Energy device? Step 13
// Intermediate buffer for incoming data
let readBuffer = '';
// Data receiving
function handleCharacteristicValueChanged(event) {
let value = new TextDecoder().decode(event.target.value);
for (let c of value) {
if (c === '\n') {
let data = readBuffer.trim();
readBuffer = '';
if (data) {
receive(data);
}
}
else {
readBuffer += c;
}
}
}
// Received data handling
function receive(data) {
log(data, 'in');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment