Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. bleConnect() {
  2. return new Promise((resolve, reject) => {
  3. resolve(
  4. this.ble.connect(this.device.id).toPromise().then(res => {
  5. console.log("Connect To Box : ", res);
  6. this.infos = res;
  7. this.isConnected = true;
  8. this.ble.requestMtu(this.device.id, 512);
  9. }, error1 => {
  10. console.log(error1);
  11. })
  12. ), reject(console.log('BLE : ', reject));
  13. });
  14. }
  15.  
  16. bleNotification() {
  17. return new Promise((resolve, reject) => {
  18. resolve(
  19. this.ble.startNotification(this.infos.id, this.infos.characteristics[3].service,
  20. this.infos.characteristics[3].characteristic).toPromise().then(res => {
  21. if (res.byteLength >= 6) {
  22. this.random = this.ab2str(res);
  23. }
  24. }, async error => {
  25. console.log(error);
  26. })
  27. ), reject(console.log('NOTIFICATION : ',reject));
  28. });
  29. }
  30.  
  31. async ConnectToBox() {
  32. await this.bleConnect().catch(error => { console.log(error)} );
  33. await this.bleNotification().catch(error => { console.log(error)} );
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement