wot-ble-client-factory 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,12 +12,23 @@ npm install wot-ble-client-factory @node-wot/core
12
12
  ```
13
13
 
14
14
  ## Minimal Setup
15
+
16
+ #### GATT
17
+ ```js
18
+ const { Servient } = require("@node-wot/core");
19
+ const { BluetoothGATTClientFactory } = require("wot-ble-client-factory");
20
+
21
+ const servient = new Servient();
22
+ servient.addClientFactory(new BluetoothGATTClientFactory());
23
+ ```
24
+
25
+ #### GAP
15
26
  ```js
16
27
  const { Servient } = require("@node-wot/core");
17
- const { BluetoothClientFactory } = require("wot-ble-client-factory");
28
+ const { BluetoothGapClientFactory } = require("wot-ble-client-factory");
18
29
 
19
30
  const servient = new Servient();
20
- servient.addClientFactory(new BluetoothClientFactory());
31
+ servient.addClientFactory(new BluetoothGapClientFactory());
21
32
  ```
22
33
 
23
34
  Check the `examples` folder for more complete Thing Descriptions.
@@ -27,11 +38,9 @@ To enable debug logs run with this command:
27
38
  DEBUG=binding-Bluetooth node example.js
28
39
  ```
29
40
 
30
- ## Protocol specifier
31
-
32
- The protocol prefix handled by this binding is <code>gatt://</code>.
41
+ ## Protocol Specifier
33
42
 
34
- A planned protocol prefix is <code>gap://</code>.
43
+ The protocol prefix handled by this binding is <code>gatt://</code> and <code>gap://</code>.
35
44
 
36
45
  ## Getting Started
37
46
  If you want to build this package locally:
@@ -40,8 +49,19 @@ git clone git@github.com:wintechis/Bluetooth-Bindings.git
40
49
  cd Bluetooth-Bindings
41
50
  npm install
42
51
  npm run build
52
+ ```
53
+
54
+ For local development you can use yalc:
55
+ ```
56
+ npm install -g yalc
57
+ ./publish_yalc.sh
58
+ ```
43
59
 
60
+ If the library code has been updated run:
44
61
  ```
62
+ ./update_yalc.sh
63
+ ```
64
+
45
65
  Then you can run the examples:
46
66
 
47
67
  ```
@@ -54,7 +74,7 @@ node examples/govee_lamp.js
54
74
  In order to align a new protocol into the WoT context, the required abstract WoT operations must first be mapped to the concrete operations of the new protocol.
55
75
  A distinction must be made between the two GATT methods write and write-without-response. Both are capable of writing WoT resources, but the two methods differ in that write expects a confirmation message from the server after a write operation, while write-without-response requires no such confirmation. Thus the GATT method chosen depends on the implementation of the attribute in the GATT server.
56
76
 
57
- | WoT Operation | BLE GATT Method |
77
+ | WoT Operation | BLE GATT Method |
58
78
  | -------------- | -------------------------- |
59
79
  | readproperty | read |
60
80
  | writeproperty | write / write-w/o-response |
@@ -69,9 +89,13 @@ It has the following structure:
69
89
  ```
70
90
  gatt://<MAC>/<service>/<characteristic>
71
91
  ```
92
+ or
93
+ ```
94
+ gap://<MAC>
95
+ ```
72
96
 
73
97
  with the following meaning:
74
- - `gatt` Identification of the transfer protocol
98
+ - `gatt` or `gap` Identification of the transfer protocol
75
99
  - `<MAC>` MAC address of the Bluetooth device
76
100
  - `<service>` GATT service containing the characteristic
77
101
  - `<characteristic>` GATT characteristic to interact with
@@ -85,15 +109,16 @@ For the Bluetooth LE bindings, we chose the new, non-standard subtype `x.binary-
85
109
  The Binary Data Ontology (bdo) is intended to provide maximum flexibility and describe all kinds of binary data.
86
110
  We want to use the bdo ontology to describe the data transmitted by Bluetooth LE devices, even those that do not comply with the Bluetooth standard. The terms of the vocabulary are in our use case only useful within the properties, actions, or events parts of a Thing Description because they contain information about the data that is needed in the codec associated with application/x.binary-data-stream.
87
111
 
88
- | Vocabulary term | Description | Assignment | Type | Default Value |
89
- | --------------- | ------------------------------------------- | ------------------------------- | ------- | ---------------- |
90
- | bdo:bytelength | Number of octets in the data | required | integer | None |
91
- | bdo:signed | Indicates if the data is signed | required | boolean | false |
92
- | bdo:endianess | Byte order of the binary data | required | string | bdo:littleEndian |
93
- | bdo:scale | Scale of received integer value | optional | float | 1.0 |
94
- | bdo:offset | Offset in number of octets | optional | integer | 0 |
95
- | bdo:pattern | The byte pattern of the binary data | optional | string | None |
96
- | bdo:variable | Description of the variables in bdo:pattern | required if bdo:pattern is used | --- | None |
112
+ | Vocabulary term | Description | Assignment | Type | Default Value |
113
+ | --------------- | ------------------------------------------------ | ------------------------------- | ------- | ---------------- |
114
+ | bdo:bytelength | Number of octets in the data | required | integer | None |
115
+ | bdo:signed | Indicates if the data is signed | required | boolean | false |
116
+ | bdo:byteOrder | Byte order of the binary data | required | string | bdo:littleEndian |
117
+ | bdo:scale | Scale of received integer value (multiplicaiton) | optional | float | 1.0 |
118
+ | bdo:valueAdd | Scale of received integer value (addition) | optional | float | 0 |
119
+ | bdo:offset | Offset in number of octets | optional | integer | 0 |
120
+ | bdo:pattern | The byte pattern of the binary data | optional | string | None |
121
+ | bdo:variables | Description of the variables in bdo:pattern | required if bdo:pattern is used | --- | None |
97
122
 
98
123
  ### Simple Bluetooth Ontology
99
124
  The communication and metadata of a Bluetooth Low Energy device is described using the Simple Bluetooth Ontology with preferred prefix sbo.
@@ -1,5 +1,13 @@
1
1
  import { ProtocolClientFactory, ProtocolClient } from '@node-wot/core';
2
- export default class BluetoothClientFactory implements ProtocolClientFactory {
2
+ export declare class BluetoothGATTClientFactory implements ProtocolClientFactory {
3
+ readonly scheme: string;
4
+ constructor();
5
+ private registerCodec;
6
+ getClient(): ProtocolClient;
7
+ init: () => boolean;
8
+ destroy: () => boolean;
9
+ }
10
+ export declare class BluetoothGapClientFactory implements ProtocolClientFactory {
3
11
  readonly scheme: string;
4
12
  constructor();
5
13
  private registerCodec;
@@ -3,13 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.BluetoothGapClientFactory = exports.BluetoothGATTClientFactory = void 0;
6
7
  const core_1 = require("@node-wot/core");
7
- const Bluetooth_client_js_1 = __importDefault(require("./Bluetooth-client.js"));
8
+ const Bluetooth_gatt_client_js_1 = __importDefault(require("./Bluetooth-gatt-client.js"));
9
+ const Bluetooth_gap_client_js_1 = __importDefault(require("./Bluetooth-gap-client.js"));
8
10
  const codec_js_1 = require("./codec.js");
9
11
  const debug_1 = __importDefault(require("debug"));
10
- // Create a logger with a specific namespace
11
12
  const log = (0, debug_1.default)('binding-Bluetooth');
12
- class BluetoothClientFactory {
13
+ class BluetoothGATTClientFactory {
13
14
  scheme = 'gatt';
14
15
  constructor() {
15
16
  this.registerCodec();
@@ -22,10 +23,29 @@ class BluetoothClientFactory {
22
23
  }
23
24
  }
24
25
  getClient() {
25
- return new Bluetooth_client_js_1.default();
26
+ return new Bluetooth_gatt_client_js_1.default();
26
27
  }
27
28
  init = () => true;
28
29
  destroy = () => true;
29
30
  }
30
- exports.default = BluetoothClientFactory;
31
+ exports.BluetoothGATTClientFactory = BluetoothGATTClientFactory;
32
+ class BluetoothGapClientFactory {
33
+ scheme = 'gap';
34
+ constructor() {
35
+ this.registerCodec();
36
+ }
37
+ registerCodec() {
38
+ const cs = core_1.ContentSerdes.get();
39
+ if (!cs.getSupportedMediaTypes().includes('application/x.binary-data-stream')) {
40
+ cs.addCodec(new codec_js_1.BLEBinaryCodec());
41
+ log('Registered BLEBinaryCodec for "application/x.binary-data-stream"');
42
+ }
43
+ }
44
+ getClient() {
45
+ return new Bluetooth_gap_client_js_1.default();
46
+ }
47
+ init = () => true;
48
+ destroy = () => true;
49
+ }
50
+ exports.BluetoothGapClientFactory = BluetoothGapClientFactory;
31
51
  //# sourceMappingURL=Bluetooth-client-factory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Bluetooth-client-factory.js","sourceRoot":"","sources":["../src/Bluetooth-client-factory.ts"],"names":[],"mappings":";;;;;AAAA,yCAIwB;AACxB,gFAAoD;AACpD,yCAA4C;AAC5C,kDAA0B;AAE1B,4CAA4C;AAC5C,MAAM,GAAG,GAAG,IAAA,eAAK,EAAC,mBAAmB,CAAC,CAAC;AAEvC,MAAqB,sBAAsB;IACzB,MAAM,GAAW,MAAM,CAAC;IAExC;QACE,IAAI,CAAC,aAA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AO,GAAG,GAAY,EAAE,CAAC,IAAI,CAAC;CACtC;AArBD,gEAqBC;AAED,MAAa,yBAAyB;IACpB,MAAM,GAAW,KAAK,CAAC;IAEvC;QACE,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC;IACO,aAAa;QACnB,MAAM,EAAE,GAAG,oBAAa,CAAC,GAAG,EAAE,CAAC;QAC/B,IAAI,CAAC,EAAE,CAAC,sBAAsB,EAAE,CAAC,QAAQ,CAAC,kCAAkC,CAAC,EAAE,CAAC;YAC7E,EAAE,CAAC,QAAQ,CAAC,IAAI,yBAAc,EAAE,CAAC,CAAC;YAClC,GAAG,CAAC,kEAAkE,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;IAEM,SAAS;QACd,OAAO,IAAI,iCAAkB,EAAE,CAAC;IAClC,CAAC;IAEM,IAAI,GAAG,GAAY,EAAE,CAAC,IAAI,CAAC;IAC3B,OAAO,GAAG,GAAY,EAAE,CAAC,IAAI,CAAC;CACtC;AApBD,8DAoBC"}
@@ -0,0 +1,14 @@
1
+ import { Content, ProtocolClient } from '@node-wot/core';
2
+ import type { Form, SecurityScheme } from 'wot-thing-description-types';
3
+ export default class BluetoothGapClient implements ProtocolClient {
4
+ toString(): string;
5
+ readResource(form: Form): Promise<Content>;
6
+ writeResource(form: Form, content?: Content): Promise<void>;
7
+ invokeResource(form: Form, content?: Content): Promise<Content>;
8
+ unlinkResource(form: Form): Promise<void>;
9
+ subscribeResource(form: Form, next: (content: Content) => void, error?: (error: Error) => void, complete?: () => void): Promise<any>;
10
+ start(): Promise<void>;
11
+ stop(): Promise<void>;
12
+ setSecurity(_metadata: SecurityScheme[], _credentials?: unknown): boolean;
13
+ requestThingDescription(uri: string): Promise<Content>;
14
+ }
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ const stream_1 = require("stream");
40
+ const debug_1 = __importDefault(require("debug"));
41
+ const BLELibCore = __importStar(require("./bluetooth/Bluetooth_lib"));
42
+ const log = (0, debug_1.default)('binding-Bluetooth-GAP');
43
+ // --- Helper Functions ---
44
+ function fromObject(data) {
45
+ const json = JSON.stringify(data);
46
+ return {
47
+ type: 'application/json',
48
+ body: stream_1.Readable.from(json),
49
+ async toBuffer() {
50
+ return Buffer.from(json);
51
+ },
52
+ };
53
+ }
54
+ // Add this function here:
55
+ function fromBuffer(type, buf) {
56
+ return {
57
+ type,
58
+ body: stream_1.Readable.from(buf),
59
+ async toBuffer() {
60
+ return buf;
61
+ },
62
+ };
63
+ }
64
+ // --- Class Definition ---
65
+ class BluetoothGapClient {
66
+ toString() {
67
+ return '[BluetoothGapClient]';
68
+ }
69
+ async readResource(form) {
70
+ // Parse URL
71
+ // Expected formats:
72
+ // - gap://<mac>
73
+ // - gap://<mac>/manufacturerData (Auto-select first)
74
+ // - gap://<mac>/manufacturerData/<id> (Select specific)
75
+ const path = form.href.split('//')[1];
76
+ const parts = path.split('/');
77
+ let deviceId = parts[0];
78
+ let resource = parts[1] ?? "manufacturerData";
79
+ const companyIdStr = parts[2]; // Optional
80
+ deviceId = deviceId.toUpperCase().replaceAll('-', ':');
81
+ if (resource !== 'manufacturerData') {
82
+ throw new Error(`[BluetoothGapClient] Only 'manufacturerData' is supported.`);
83
+ }
84
+ log(`invoke read GAP on ${deviceId}`);
85
+ // Fetch all data
86
+ const dataEntries = await BLELibCore.getDeviceManufacturerData(deviceId);
87
+ if (dataEntries.length === 0) {
88
+ throw new Error(`No manufacturer data found on ${deviceId}`);
89
+ }
90
+ // LOGIC: Auto-select or Specific Select
91
+ let selectedEntry;
92
+ if (companyIdStr) {
93
+ // Case A: ID specified in URL (e.g. 0x0499)
94
+ const companyId = companyIdStr.startsWith('0x')
95
+ ? parseInt(companyIdStr, 16)
96
+ : parseInt(companyIdStr, 10);
97
+ selectedEntry = dataEntries.find(e => e.companyId === companyId);
98
+ if (!selectedEntry) {
99
+ throw new Error(`Company ID ${companyIdStr} not found in advertisements.`);
100
+ }
101
+ }
102
+ else {
103
+ // Case B: No ID specified -> Auto-select the first one
104
+ selectedEntry = dataEntries[0];
105
+ log(`Auto-selected Manufacturer ID: 0x${selectedEntry.companyId.toString(16)}`);
106
+ }
107
+ // Return Data based on Content-Type
108
+ // If the TD expects binary (for the Codec), return the Buffer directly.
109
+ // If the TD expects JSON (debugging), return the simplified object.
110
+ if (form.contentType === 'application/json') {
111
+ // Return the simplified object info if JSON is requested
112
+ return fromObject(selectedEntry);
113
+ }
114
+ else {
115
+ // Default / Binary: Return the RAW BUFFER so the Codec can parse it
116
+ return fromBuffer(form.contentType || 'application/x.binary-data-stream', selectedEntry.data);
117
+ }
118
+ }
119
+ async writeResource(form, content) {
120
+ throw new Error('Method not implemented for GAP.');
121
+ }
122
+ async invokeResource(form, content) {
123
+ throw new Error('Method not implemented for GAP.');
124
+ }
125
+ async unlinkResource(form) {
126
+ throw new Error('Method not implemented for GAP.');
127
+ }
128
+ async subscribeResource(form, next, error, complete) {
129
+ throw new Error('Subscribe not yet implemented for GAP.');
130
+ }
131
+ async start() {
132
+ // no-op
133
+ }
134
+ async stop() {
135
+ // no-op
136
+ }
137
+ setSecurity(_metadata, _credentials) {
138
+ return false;
139
+ }
140
+ // --- ADDED THIS METHOD TO FIX ERROR 1 & 2 ---
141
+ async requestThingDescription(uri) {
142
+ throw new Error('requestThingDescription not supported by BluetoothGapClient');
143
+ }
144
+ }
145
+ exports.default = BluetoothGapClient;
146
+ //# sourceMappingURL=Bluetooth-gap-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Bluetooth-gap-client.js","sourceRoot":"","sources":["../src/Bluetooth-gap-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,mCAAkC;AAClC,kDAA0B;AAC1B,sEAAwD;AAExD,MAAM,GAAG,GAAG,IAAA,eAAK,EAAC,uBAAuB,CAAC,CAAC;AAE3C,2BAA2B;AAE3B,SAAS,UAAU,CAAC,IAAS;IAC3B,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAClC,OAAO;QACL,IAAI,EAAE,kBAAkB;QACxB,IAAI,EAAE,iBAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;QACzB,KAAK,CAAC,QAAQ;YACZ,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC;KACF,CAAC;AACJ,CAAC;AAED,0BAA0B;AAC1B,SAAS,UAAU,CAAC,IAAY,EAAE,GAAW;IAC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AC,iCAAiC,CAAC,CAAC;IACrD,CAAC;IAEM,KAAK,CAAC,iBAAiB,CAC5B,IAAU,EACV,IAAgC,EAChC,KAA8B,EAC9B,QAAqB;QAErB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IAEM,KAAK,CAAC,KAAK;QAChB,QAAQ;IACV,CAAC;IAEM,KAAK,CAAC,IAAI;QACf,QAAQ;IACV,CAAC;IAEM,WAAW,CAAC,SAA2B,EAAE,YAAsB;QACpE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,+CAA+C;IACxC,KAAK,CAAC,uBAAuB,CAAC,GAAW;QAC7C,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;IAClF,CAAC;CACF;AAzGD,qCAyGC"}
@@ -114,6 +114,7 @@ class BluetoothClient {
114
114
  async readResource(form) {
115
115
  const deconstructedForm = (0, exports.deconstructForm)(form);
116
116
  await BLELibCore.connect(deconstructedForm.deviceId);
117
+ BLELibCore.touchConnection(deconstructedForm.deviceId);
117
118
  log(`invoke read operation on characteristic ${deconstructedForm.characteristicId}` +
118
119
  ` from service ${deconstructedForm.serviceId} on ${deconstructedForm.deviceId}`);
119
120
  // Get Characteristic
@@ -128,7 +129,8 @@ class BluetoothClient {
128
129
  throw new Error(`Error reading from Bluetooth device ${deconstructedForm.characteristicId}`);
129
130
  }
130
131
  if (autoDisconnect) {
131
- await BLELibCore.close();
132
+ // disconnect on idle (handled inside BLELibCore timers)
133
+ BLELibCore.touchConnection(deconstructedForm.deviceId);
132
134
  }
133
135
  // Return proper Content (with toBuffer)
134
136
  return fromBuffer(deconstructedForm.contentType || 'application/x.binary-data-stream', buffer);
@@ -139,6 +141,7 @@ class BluetoothClient {
139
141
  async writeResource(form, content) {
140
142
  const deconstructedForm = (0, exports.deconstructForm)(form);
141
143
  await BLELibCore.connect(deconstructedForm.deviceId);
144
+ BLELibCore.touchConnection(deconstructedForm.deviceId);
142
145
  // Convert content -> Buffer
143
146
  let buffer;
144
147
  if (content) {
@@ -198,7 +201,7 @@ class BluetoothClient {
198
201
  }
199
202
  }
200
203
  if (autoDisconnect) {
201
- await BLELibCore.close();
204
+ BLELibCore.touchConnection(deconstructedForm.deviceId);
202
205
  }
203
206
  }
204
207
  /**
@@ -224,6 +227,8 @@ class BluetoothClient {
224
227
  */
225
228
  async subscribeResource(form, next, error, complete) {
226
229
  const deconstructedForm = (0, exports.deconstructForm)(form);
230
+ await BLELibCore.connect(deconstructedForm.deviceId);
231
+ BLELibCore.holdConnection(deconstructedForm.deviceId);
227
232
  if (deconstructedForm.ble_operation !== 'sbo:notify') {
228
233
  throw new Error(`[binding-Bluetooth] operation ${deconstructedForm.ble_operation} is not supported`);
229
234
  }
@@ -252,9 +257,11 @@ class BluetoothClient {
252
257
  void characteristic
253
258
  .stopNotifications()
254
259
  .then(() => {
260
+ BLELibCore.releaseConnection(deconstructedForm.deviceId);
255
261
  complete?.();
256
262
  })
257
263
  .catch((e) => {
264
+ BLELibCore.releaseConnection(deconstructedForm.deviceId);
258
265
  error?.(e);
259
266
  });
260
267
  });
@@ -274,4 +281,4 @@ class BluetoothClient {
274
281
  }
275
282
  }
276
283
  exports.default = BluetoothClient;
277
- //# sourceMappingURL=Bluetooth-client.js.map
284
+ //# sourceMappingURL=Bluetooth-gatt-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Bluetooth-gatt-client.js","sourceRoot":"","sources":["../src/Bluetooth-gatt-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,oDAEC;AAED,sDAEC;AAhBD,yCAA0E;AAC1E,oDAAiD;AAEjD,mCAAkC;AAClC,kDAA0B;AAC1B,sEAAwD;AAExD,+CAA+C;AAC/C,IAAI,cAAc,GAAG,IAAI,CAAC;AAE1B,SAAgB,oBAAoB;IAClC,cAAc,GAAG,IAAI,CAAC;AACxB,CAAC;AAED,SAAgB,qBAAqB;IACnC,cAAc,GAAG,KAAK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AAC;IAC9E,CAAC;IAEM,WAAW,CAChB,SAA2B,EAC3B,YAAsB;QAEtB,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAxPD,kCAwPC"}
@@ -1,6 +1,7 @@
1
1
  import { Form } from "@node-wot/core";
2
- export { default as BluetoothClient } from './Bluetooth-client.js';
3
- export { default as BluetoothClientFactory } from './Bluetooth-client-factory.js';
2
+ export { default as BluetoothClient } from './Bluetooth-gatt-client.js';
3
+ export { BluetoothGATTClientFactory } from './Bluetooth-client-factory.js';
4
+ export { BluetoothGapClientFactory } from './Bluetooth-client-factory.js';
4
5
  export declare class BluetoothForm extends Form {
5
6
  'wbt:id': string;
6
7
  'datatype': string;
package/dist/Bluetooth.js CHANGED
@@ -3,12 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.BluetoothForm = exports.BluetoothClientFactory = exports.BluetoothClient = void 0;
6
+ exports.BluetoothForm = exports.BluetoothGapClientFactory = exports.BluetoothGATTClientFactory = exports.BluetoothClient = void 0;
7
7
  const core_1 = require("@node-wot/core");
8
- var Bluetooth_client_js_1 = require("./Bluetooth-client.js");
9
- Object.defineProperty(exports, "BluetoothClient", { enumerable: true, get: function () { return __importDefault(Bluetooth_client_js_1).default; } });
8
+ var Bluetooth_gatt_client_js_1 = require("./Bluetooth-gatt-client.js");
9
+ Object.defineProperty(exports, "BluetoothClient", { enumerable: true, get: function () { return __importDefault(Bluetooth_gatt_client_js_1).default; } });
10
+ // Export the default (GATT) factory as expected by legacy code
10
11
  var Bluetooth_client_factory_js_1 = require("./Bluetooth-client-factory.js");
11
- Object.defineProperty(exports, "BluetoothClientFactory", { enumerable: true, get: function () { return __importDefault(Bluetooth_client_factory_js_1).default; } });
12
+ Object.defineProperty(exports, "BluetoothGATTClientFactory", { enumerable: true, get: function () { return Bluetooth_client_factory_js_1.BluetoothGATTClientFactory; } });
13
+ // Also export the GAP factory so it can be used
14
+ var Bluetooth_client_factory_js_2 = require("./Bluetooth-client-factory.js");
15
+ Object.defineProperty(exports, "BluetoothGapClientFactory", { enumerable: true, get: function () { return Bluetooth_client_factory_js_2.BluetoothGapClientFactory; } });
12
16
  class BluetoothForm extends core_1.Form {
13
17
  'wbt:id';
14
18
  'datatype';
@@ -1 +1 @@
1
- {"version":3,"file":"Bluetooth.js","sourceRoot":"","sources":["../src/Bluetooth.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAsC;AAEtC,6DAAiE;AAAzD,uIAAA,OAAO,OAAmB;AAClC,6EAAgF;AAAxE,sJAAA,OAAO,OAA0B;AAEzC,MAAa,aAAc,SAAQ,WAAI;IAC9B,QAAQ,CAAS;IACjB,UAAU,CAAS;CAC3B;AAHD,sCAGC"}
1
+ {"version":3,"file":"Bluetooth.js","sourceRoot":"","sources":["../src/Bluetooth.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAsC;AAEtC,uEAAwE;AAA/D,4IAAA,OAAO,OAAmB;AACnC,+DAA+D;AAC/D,6EAA2E;AAAlE,yIAAA,0BAA0B,OAAA;AAEnC,gDAAgD;AAChD,6EAA0E;AAAjE,wIAAA,yBAAyB,OAAA;AAElC,MAAa,aAAc,SAAQ,WAAI;IAC9B,QAAQ,CAAS;IACjB,UAAU,CAAS;CAC3B;AAHD,sCAGC"}
@@ -2,68 +2,40 @@
2
2
  * Handle basic bluetooth communication and discovery.
3
3
  */
4
4
  export declare const reinit: () => void;
5
+ export declare const setDeviceIdleDisconnectMs: (ms: number) => void;
6
+ export declare const setDbusIdleCloseMs: (ms: number) => void;
7
+ export declare function touchConnection(id: string): void;
8
+ export declare function holdConnection(id: string): void;
9
+ export declare function releaseConnection(id: string): void;
5
10
  export declare let connection_established_obj: Record<string, any>;
6
- /**
7
- * Returns a the default adapter instance.
8
- * @returns {Adapter} instance of default adapter.
9
- */
10
11
  export declare const getAdapter: () => Promise<import("node-ble").Adapter>;
11
- /**
12
- * Starts a scan operation
13
- */
14
12
  export declare const startScan: () => Promise<void>;
15
- /**
16
- * Stops an ongoing scan operation
17
- */
18
13
  export declare const stopScan: () => Promise<void>;
19
- /**
20
- * Gets the current status of the adapter
21
- * @returns {boolean} indicates if discovery is active.
22
- */
23
14
  export declare const getAdapterStatus: () => Promise<boolean>;
24
- /**
25
- * Returns a paired bluetooth device by their id.
26
- * @param {BluetoothDevice.id} id identifier of the device to get.
27
- * @returns {BluetoothDevice} the bluetooth device with id.
28
- */
29
15
  export declare const getDeviceById: (id: string, timeoutMs?: number) => Promise<any>;
30
- /**
31
- * Sends a connect command.
32
- * @param {BluetoothDevice.id} id identifier of the device to connect to.
33
- * @return {Promise<Object>} representation of the complete request with response.
34
- */
35
16
  export declare const connect: (id: string) => Promise<any>;
36
- /**
37
- * Returns a promise to the BluetoothRemoteGATTCharacteristic offered by
38
- * the bluetooth device for a specified BluetoothServiceUUID and
39
- * BluetoothCharacteristicUUID.
40
- * @param {BluetoothDevice.id} id identifier of the device to get the characteristic from.
41
- * @param {BluetoothServiceUUID} serviceUUID identifier of the service.
42
- * @param {BluetoothCharacteristicUUID} characteristicUUID identifier of the characteristic.
43
- * @returns {Promise<BluetoothRemoteGATTCharacteristic>} A BluetoothRemoteGATTCharacteristic object.
44
- */
45
17
  export declare const getCharacteristic: (id: string, serviceUUID: string, characteristicUUID: string) => Promise<any>;
46
- /**
47
- * Connects ta a selected device based on a Thing object.
48
- * @param {object} Thing Thing instance of device.
49
- */
50
- export declare const connectThing: (Thing: any) => Promise<void>;
51
- /**
52
- * Disconnects from a selected device based on a Thing object.
53
- * @param {object} Thing Thing instance of device.
54
- */
55
- export declare const disconnectThing: (Thing: any) => Promise<void>;
56
- /**
57
- * Disconnects from a selected device based on a mac address.
58
- * @param {string} id identifier of the device to read from.
59
- */
18
+ export declare function parseManufacturerData(mfg: Record<string, Buffer>): {
19
+ companyId: number;
20
+ length: number;
21
+ dataHex: string;
22
+ data: Buffer<ArrayBufferLike>;
23
+ }[];
24
+ /**
25
+ * Scans for a device and returns its manufacturer data without establishing a GATT connection.
26
+ */
27
+ export declare const getDeviceManufacturerData: (id: string, timeoutMs?: number) => Promise<{
28
+ companyId: number;
29
+ length: number;
30
+ dataHex: string;
31
+ data: Buffer<ArrayBufferLike>;
32
+ }[]>;
60
33
  export declare const disconnectByMac: (id: string) => Promise<void>;
61
- /**
62
- * Disconnects from all connected devices.
63
- */
64
34
  export declare const disconnectAll: () => Promise<void>;
65
35
  /**
66
36
  * Disconnects from all connected devices and stops all operations by node-ble.
67
- * Needed to exit programm after execution.
37
+ * Needed to exit program after execution (we call this automatically when idle).
68
38
  */
69
39
  export declare const close: () => Promise<void>;
40
+ export declare const connectThing: (Thing: any) => Promise<void>;
41
+ export declare const disconnectThing: (Thing: any) => Promise<void>;