Skip to content

Latest commit

 

History

History

webClient_match_dev_device

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Bluetooth pairing test using Chrome browser and development board

Simple one:

Firstly, Open chrome and enter about://bluetooth-internals, and then you should arrived the page below avatar Secondly,you should click "devices" button left,next,click “Start Scan” button top-right avatar Thirdly, click “Inspect” button on the right in the option named “ESP_GATTS_DEMO” avatar Finally, we can see the mac connect to the dev board, respone informations to mac on the page and outlog in the command line interface for the dev board, Client-Mac/Chrome: avatar Server-connected: avatar Server-disconnected: avatar

Web Bluetooth / Device Info (Async Await) Sample

JavaScript Snippet

async function onButtonClick() {
  let filters = [];

  let filterService = document.querySelector('#service').value;
  if (filterService.startsWith('0x')) {
    filterService = parseInt(filterService);
  }
  if (filterService) {
    filters.push({services: [filterService]});
  }

  let filterName = document.querySelector('#name').value;
  if (filterName) {
    filters.push({name: filterName});
  }

  let filterNamePrefix = document.querySelector('#namePrefix').value;
  if (filterNamePrefix) {
    filters.push({namePrefix: filterNamePrefix});
  }

  let options = {};
  if (document.querySelector('#allDevices').checked) {
    options.acceptAllDevices = true;
  } else {
    options.filters = filters;
  }

  try {
    log('Requesting Bluetooth Device...');
    log('with ' + JSON.stringify(options));
    const device = await navigator.bluetooth.requestDevice(options);

    log('> Name:             ' + device.name);
    log('> Id:               ' + device.id);
    log('> Connected:        ' + device.gatt.connected);
  } catch(error)  {
    log('Argh! ' + error);
  }
}