Created
August 27, 2018 00:59
-
-
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
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
// 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