Initial commit to webble
This commit is contained in:
parent
f009bc3e2a
commit
0a3018af9c
8
package-lock.json
generated
8
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "node-poweredup",
|
||||
"version": "1.6.2",
|
||||
"version": "1.9.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -25,6 +25,12 @@
|
||||
"integrity": "sha512-fh+pAqt4xRzPfqA6eh3Z2y6fyZavRIumvjhaCL753+TVkGKGhpPeyrJG2JftD0T9q4GF00KjefsQ+PQNDdWQaQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/web-bluetooth": {
|
||||
"version": "0.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/web-bluetooth/-/web-bluetooth-0.0.4.tgz",
|
||||
"integrity": "sha512-C+BgVBBGY9c6ixcc5PsKAmGaCy3bswZ5zx/AWIAik9dgFuBkFsXBA3ze69jJi05xdZQ99QkfBSVIX6zl+6Tmww==",
|
||||
"dev": true
|
||||
},
|
||||
"abbrev": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
|
||||
|
@ -22,6 +22,7 @@
|
||||
"@types/debug": "0.0.31",
|
||||
"@types/noble": "0.0.38",
|
||||
"@types/node": "^10.12.18",
|
||||
"@types/web-bluetooth": "0.0.4",
|
||||
"ink-docstrap": "^1.3.2",
|
||||
"jsdoc": "^3.5.5",
|
||||
"jsdoc-to-markdown": "^4.0.1",
|
||||
|
31
src/bledevice.ts
Normal file
31
src/bledevice.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { Peripheral } from "noble";
|
||||
|
||||
import Debug = require("debug");
|
||||
const debug = Debug("bledevice");
|
||||
|
||||
|
||||
export class BLEDevice {
|
||||
|
||||
|
||||
// @ts-ignore
|
||||
private _noblePeripheral: Peripheral | null;
|
||||
private _webBLEServer: any;
|
||||
|
||||
|
||||
constructor (device: Peripheral | BluetoothRemoteGATTServer) {
|
||||
if (device instanceof Peripheral) {
|
||||
this._noblePeripheral = device;
|
||||
} else {
|
||||
this._webBLEServer = device;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public discoverService (uuid: string) {
|
||||
if (this._peripheral instanceof BluetoothRemoteGATTServer) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
73
webble_test.html
Normal file
73
webble_test.html
Normal file
@ -0,0 +1,73 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>node-poweredup Web Bluetooth Test</title>
|
||||
<script>
|
||||
|
||||
const scan = async function () {
|
||||
|
||||
const WEDO2_SMART_HUB = "00001523-1212-efde-1523-785feabcd123";
|
||||
const LPF2_HUB = "00001623-1212-efde-1623-785feabcd123";
|
||||
|
||||
const LPF2_ALL = "00001624-1212-efde-1623-785feabcd123"
|
||||
|
||||
const device = await navigator.bluetooth.requestDevice({
|
||||
filters: [
|
||||
{
|
||||
services: [
|
||||
WEDO2_SMART_HUB
|
||||
]
|
||||
},
|
||||
{
|
||||
services: [
|
||||
LPF2_HUB
|
||||
]
|
||||
}
|
||||
]
|
||||
});
|
||||
const server = await device.gatt.connect();
|
||||
console.log(server);
|
||||
|
||||
let connectComplete = false;
|
||||
let hubType = 0;
|
||||
let isLPF2Hub = false;
|
||||
let service;
|
||||
try {
|
||||
service = await server.getPrimaryService(WEDO2_SMART_HUB);
|
||||
hubType = 1;
|
||||
} catch (error) {}
|
||||
try {
|
||||
service = await server.getPrimaryService(LPF2_HUB);
|
||||
isLPF2Hub = true;
|
||||
} catch (error) {}
|
||||
|
||||
const characteristics = await service.getCharacteristics();
|
||||
const charMap = {};
|
||||
for (const characteristic of characteristics) {
|
||||
charMap[characteristic.uuid] = characteristic;
|
||||
}
|
||||
|
||||
charMap[LPF2_ALL].addEventListener("characteristicvaluechanged", (event) => {
|
||||
console.log(event.target.value.buffer);
|
||||
});
|
||||
|
||||
charMap[LPF2_ALL].startNotifications();
|
||||
|
||||
if (isLPF2Hub) {
|
||||
const hubTypeCmd = new Uint8Array([0x05, 0x00, 0x01, 0x0b, 0x05]);
|
||||
charMap[LPF2_ALL].writeValue(hubTypeCmd);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div>
|
||||
<button onclick="scan()">Scan</button>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user