Advertisement
kolban

Untitled

Nov 22nd, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. /**
  2. *
  3. */
  4. $(function(){
  5. var requestDeviceParms = {
  6. filters: [
  7. {
  8. name: ["MYDEVICE"]
  9. }
  10. ],
  11. optionalServices: ["4fafc201-1fb5-459e-8fcc-c5c9c331914b"]
  12. };
  13.  
  14. $("#test").click(() => {
  15. console.log("Running BLE Code");
  16. navigator.bluetooth.requestDevice(requestDeviceParms).then(device => {
  17. device.gatt.connect().then(gattServer=>{
  18. gattServer.getPrimaryService("4fafc201-1fb5-459e-8fcc-c5c9c331914b").then(gattService=>{
  19. gattService.getCharacteristic("beb5483e-36e1-4688-b7f5-ea07361b26a8").then(gattCharacteristic=>{
  20. gattCharacteristic.startNotifications().then(gattCharacteristic=>{
  21. gattCharacteristic.addEventListener("characteristicvaluechanged", event=>{
  22. var value = event.target.value.getUint8(0);
  23. $("#notifiedValue").text("" + value);
  24. });
  25. });
  26. });
  27. });
  28. });
  29. });
  30. });
  31.  
  32. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement