Skip to content

Instantly share code, notes, and snippets.

@oflarcade
Created October 30, 2019 10:21
Show Gist options
  • Save oflarcade/4b89795273e8bdf7bc7f58031008391b to your computer and use it in GitHub Desktop.
Save oflarcade/4b89795273e8bdf7bc7f58031008391b to your computer and use it in GitHub Desktop.
handleBattery(peripheral) {
setTimeout(() => {
BleManager.retrieveServices(peripheral.id).then(services => {
BleManager.read(peripheral.id, 'fee0', UUID_BASE('0006'))
.then(readData => {
let data = Buffer.Buffer.from(readData);
console.log('read battery level', data.readUInt8(1, true));
this.setState({battery: data.readUInt8(1, true)});
})
.catch(error => {
console.log('error', error);
});
});
}, 1000);
}
handleDeviceInfo(peripheral) {
setTimeout(() => {
BleManager.retrieveServices(peripheral.id).then(services => {
BleManager.read(peripheral.id, '180a', '2a28')
.then(readData => {
let data = Buffer.Buffer.from(readData);
console.log('Read !! Firmware Version : ', data.toString());
this.setState({fVersion: data.toString()});
})
.catch(error => {
console.log('error', error);
});
});
}, 2000);
setTimeout(() => {
BleManager.retrieveServices(peripheral.id).then(services => {
BleManager.read(peripheral.id, '180a', '2a25')
.then(readData => {
let data = Buffer.Buffer.from(readData);
console.log('Read !! Serial Number :', data.toString());
this.setState({Snumber: data.toString()});
})
.catch(error => {
console.log('error', error);
});
});
}, 3000);
setTimeout(() => {
BleManager.retrieveServices(peripheral.id).then(services => {
BleManager.read(peripheral.id, 'fee0', '2a2b')
.then(readData => {
let data = Buffer.Buffer.from(readData);
console.log('Read !! Time info :', parseDate(data).toString());
this.setState({time: parseDate(data).toString()});
})
.catch(error => {
console.log('error', error);
});
});
}, 4000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment