Created
August 27, 2018 11:47
-
-
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
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
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