{"id":21140649,"url":"https://github.com/dokmic/bluetooth-device","last_synced_at":"2026-04-24T18:32:38.051Z","repository":{"id":143861701,"uuid":"330250225","full_name":"dokmic/bluetooth-device","owner":"dokmic","description":"Bluetooth Low-Energy Peripheral Device","archived":false,"fork":false,"pushed_at":"2021-11-18T21:02:41.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-07T21:43:13.802Z","etag":null,"topics":["abstraction","bluetooth","bluetooth-low-energy","device","node","peripheral","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dokmic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-16T20:28:31.000Z","updated_at":"2021-11-18T21:02:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"5fcf78d1-d67d-4552-a825-f703142e820a","html_url":"https://github.com/dokmic/bluetooth-device","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dokmic%2Fbluetooth-device","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dokmic%2Fbluetooth-device/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dokmic%2Fbluetooth-device/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dokmic%2Fbluetooth-device/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dokmic","download_url":"https://codeload.github.com/dokmic/bluetooth-device/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243581092,"owners_count":20314167,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abstraction","bluetooth","bluetooth-low-energy","device","node","peripheral","typescript"],"created_at":"2024-11-20T07:17:05.657Z","updated_at":"2025-12-28T18:31:25.251Z","avatar_url":"https://github.com/dokmic.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bluetooth Low-Energy Peripheral Device\n[![NPM](https://img.shields.io/npm/v/bluetooth-device.svg)](https://www.npmjs.com/package/bluetooth-device)\n[![Tests](https://github.com/dokmic/bluetooth-device/actions/workflows/tests.yaml/badge.svg?branch=master)](https://github.com/dokmic/bluetooth-device/actions/workflows/tests.yaml)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nThis package provides an abstraction layer on top of the Bluetooth Low-Energy (BLE) peripheral device.\n\n## Get Started\n```bash\nnpm install --save bluetooth-device\n```\n\n## Usage\n```typescript\nimport { BluetoothDevice } from 'bluetooth-device';\n\nconst HANDLE_TEMPERATURE_READ = 1234;\nconst HANDLE_TEMPERATURE_WRITE = 5678;\n\nconst thermostat = new BluetoothDevice('11:22:33:44:55:66', { timeout: 1000 });\nconst temperature = await thermostat.read(HANDLE_TEMPERATURE_READ);\n\nawait thermostat.write(HANDLE_TEMPERATURE_WRITE, temperature + 10);\n```\n\nYou can also extend your peripheral from the `BluetoothDevice` base class.\n```typescript\nimport { BluetoothDevice } from 'bluetooth-device';\n\nconst TEMPERATURE_MIN = 10;\nconst TEMPERATURE_MAX = 40;\n\nconst HANLDE_READ = 1234;\nconst HANDLE_WRITE = 5678;\n\nexport class Thermostat extends BluetoothDevice {\n  async setTemperature(temperature: number): Promise\u003cvoid\u003e {\n    const value = Math.min(Math.max(TEMPERATURE_MIN, temperature), TEMPERATURE_MAX);\n\n    return await this.write(HANDLE_WRITE, value);\n  }\n\n  getTemperature(): Promise\u003cnumber\u003e {\n    return this.read(HANLDE_READ);\n  }\n}\n```\n\n## API\n### `constructor`\nInitializes a Bluetooth device instance.\n\n```typescript\nconstructor(address: string, options?: object)\n```\n- `address` - Bluetooth address.\n- `options` - Device options.\n  - `discoveryTimeout` - Device discovery timeout in milliseconds. By default, it equals 30 seconds.\n  - `idleTimeout` - Device idle timeout in milliseconds. After that, the connection will be destroyed. By default, it equals to 2 minutes.\n  - `retries` - The number of retries on failed operations. By default, it is 3.\n  - `timeout` - Device operations timeout, namely, connection, read, and write. By default, it equals 10 seconds.\n\n### `discover`\nDiscovers peripheral device by address.\n\n```typescript\ndiscover(): Promise\u003cvoid\u003e\n```\n\n### `connect`\nTries to establish a connection with the device.\nIf the device was not previously discovered, the discovery operation will be performed before.\n\n```typescript\nconnect(): Promise\u003cvoid\u003e\n```\n\n### `disconnect`\nDestroys a connection with the device.\n\n```typescript\ndisconnect(): Promise\u003cvoid\u003e\n```\n\n### `notify`\nWaits for the next notification.\nIf the device was not previously connected, the connection will be established automatically.\n\n```typescript\nnotify(handle: number): Promise\u003cBuffer\u003e\n```\n- `handle` - The notification handle.\n\n### `read`\nReads data from the device.\nIf the device was not previously connected, the connection will be established automatically.\n\n```typescript\nread(handle: number): Promise\u003cBuffer\u003e\n```\n- `handle` - The handle to read from.\n\n### `write`\nWrites data to the device.\nIf the device was not previously connected, the connection will be established automatically.\n\n```typescript\nwrite(handle: number, data: Buffer): Promise\u003cvoid\u003e\n```\n- `handle` - The write handle.\n- `data` - The data buffer.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdokmic%2Fbluetooth-device","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdokmic%2Fbluetooth-device","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdokmic%2Fbluetooth-device/lists"}