Skip to content

Instantly share code, notes, and snippets.

@ratacibernetica
Created June 22, 2018 04:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ratacibernetica/bc1f6fc39bf59cf6799900bec310ca00 to your computer and use it in GitHub Desktop.
Save ratacibernetica/bc1f6fc39bf59cf6799900bec310ca00 to your computer and use it in GitHub Desktop.
web bluetooth API, detect Chinese smartwatch CK12s and Nokia Body+ D8 Scale Services and Characteristics
/* Tested with these devices
Smartwatch: https://www.aliexpress.com/item/JUNWER-Graphene-ECG-Smart-Band-CK12-Heart-Rate-Monitor-Blood-Pressure-Monitoring-Smart-Wriatband-IP67-Waterproof/32824701799.html
Nokia Scale: https://www.amazon.com/Nokia-Body-Composition-Wi-Fi-Scale/dp/B071XW4C5Q
*/
//list of GATT servicess (excluding incompatibles or not recognized)
const gattServices = [
'alert_notification',
'automation_io',
'battery_service',
'blood_pressure',
'body_composition',
'bond_management',
'continuous_glucose_monitoring',
'current_time',
'cycling_power',
'cycling_speed_and_cadence',
'device_information',
'environmental_sensing',
'fitness_machine',
'generic_access',
'generic_attribute',
'glucose',
'health_thermometer',
'heart_rate',
'http_proxy',
//'human_interface_device',
'immediate_alert',
'indoor_positioning',
'internet_protocol_support',
'link_loss',
'location_and_navigation',
//'mesh_provisioning',
//'mesh_proxy',
'next_dst_change',
'object_transfer',
'phone_alert_status',
'pulse_oximeter',
//'reconnection_configuration',
'reference_time_update',
'running_speed_and_cadence',
'scan_parameters',
'transport_discovery',
'tx_power',
'user_data',
'weight_scale'
];
const myServices = [
0x0003, //smartwatch-CK12S
0x3E01, //smartwatch-CK12S
0x2C01, //smartwatch-CK12S
'00000020-5749-5448-0005-000000000000' //Nokia Scale
];
const connectedDevices = {};
//available only in chrome for now https://caniuse.com/#feat=web-bluetooth
const addDevice = () => {
if(navigator.bluetooth){
//this should prompt the device selection popup
const peripheral = await navigator.bluetooth.requestDevice({
acceptAllDevices: true,
optionalServices: [...myServices, ...gattServices]
});
connectedDevices[peripheral.name] = peripheral;
const gatt = await peripheral.gatt.connect();
const services = await gatt.getPrimaryServices();
connectedDevices[peripheral.name].services = services;
for(let service of services){
const characteristics = await service.getCharacteristics();
console.log(characteristics);
for(let characteristic of characteristics){
console.log(characteristic);
}
}
}
}
@pkyeck
Copy link

pkyeck commented Nov 14, 2018

@ratacibernetica were you able to grab data from the Body+?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment