Skip to content

Instantly share code, notes, and snippets.

@loginov-rocks
Created August 27, 2018 11:47
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/58a1b7428f9a3bbc71a49ef36bea6e34 to your computer and use it in GitHub Desktop.
Save loginov-rocks/58a1b7428f9a3bbc71a49ef36bea6e34 to your computer and use it in GitHub Desktop.
How to make a web app for your own Bluetooth Low Energy device? Step 15
function send(data) {
data = String(data);
if (!data || !characteristicCache) {
return;
}
data += '\n';
if (data.length > 20) {
let chunks = data.match(/(.|[\r\n]){1,20}/g);
writeToCharacteristic(characteristicCache, chunks[0]);
for (let i = 1; i < chunks.length; i++) {
setTimeout(() => {
writeToCharacteristic(characteristicCache, chunks[i]);
}, i * 100);
}
}
else {
writeToCharacteristic(characteristicCache, data);
}
log(data, 'out');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment