{"id":20284157,"url":"https://github.com/clebert/node-bluez","last_synced_at":"2025-03-04T03:41:58.903Z","repository":{"id":57102500,"uuid":"360202407","full_name":"clebert/node-bluez","owner":"clebert","description":"A Node.js API for BlueZ with native TypeScript support.","archived":false,"fork":false,"pushed_at":"2023-11-12T09:33:56.000Z","size":81,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-24T16:05:08.552Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clebert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-04-21T14:35:17.000Z","updated_at":"2023-03-25T13:39:13.000Z","dependencies_parsed_at":"2023-11-12T10:26:33.113Z","dependency_job_id":"a8946a65-77ec-4994-a83d-a5483f3efc76","html_url":"https://github.com/clebert/node-bluez","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clebert%2Fnode-bluez","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clebert%2Fnode-bluez/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clebert%2Fnode-bluez/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clebert%2Fnode-bluez/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clebert","download_url":"https://codeload.github.com/clebert/node-bluez/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241780465,"owners_count":20019058,"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":[],"created_at":"2024-11-14T14:18:33.308Z","updated_at":"2025-03-04T03:41:58.854Z","avatar_url":"https://github.com/clebert.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node.js BlueZ\n\n\u003e A Node.js API for BlueZ with native TypeScript support.\n\nThis package runs only on Linux and has a very limited feature set. It is\nspecially designed for controlling simple BLE devices (e.g.\n[@clebert/node-switch-bot](https://github.com/clebert/node-switch-bot) and\n[@clebert/node-plant-sensor](https://github.com/clebert/node-plant-sensor)) in\nthe context of home automation.\n\n## Installation\n\n```\nnpm install @clebert/node-bluez @clebert/node-d-bus\n```\n\n## Features\n\n- Designed from the ground up with TypeScript.\n- Uses a solid and well-tested D-Bus implementation to communicate with BlueZ.\n\n## Usage example\n\n```js\nimport {Adapter} from '@clebert/node-bluez';\nimport {SystemDBus} from '@clebert/node-d-bus';\n\n(async () =\u003e {\n  const dBus = new SystemDBus();\n\n  await dBus.connectAsExternal();\n\n  try {\n    await dBus.hello();\n\n    const [adapter] = await Adapter.getAll(dBus);\n\n    if (!adapter) {\n      throw new Error(`Adapter not found.`);\n    }\n\n    const unlockAdapter = await adapter.lock.aquire();\n\n    try {\n      await adapter.setPowered(true);\n\n      await adapter.setDiscoveryFilter({\n        serviceUUIDs: [`xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`],\n        transport: `le`,\n      });\n\n      await adapter.startDiscovery();\n\n      let device;\n\n      try {\n        device = await adapter.waitForDevice(`XX:XX:XX:XX:XX:XX`);\n      } finally {\n        await adapter.stopDiscovery();\n      }\n\n      await device.connect();\n\n      const gattCharacteristic = await device.waitForGattCharacteristic(\n        `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`,\n      );\n\n      await gattCharacteristic.writeValue([\n        `f`.charCodeAt(0),\n        `o`.charCodeAt(0),\n        `o`.charCodeAt(0),\n      ]);\n\n      await device.disconnect();\n    } finally {\n      unlockAdapter();\n    }\n  } finally {\n    dBus.disconnect();\n  }\n})().catch((error) =\u003e {\n  console.error(error);\n  process.exit(1);\n});\n```\n\n## Configure user permissions\n\nCreate the `/etc/dbus-1/system.d/node-bluez.conf` configuration file. The\nusername may need to be modified.\n\n```xml\n\u003c!DOCTYPE busconfig PUBLIC \"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN\"\n  \"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd\"\u003e\n\n\u003cbusconfig\u003e\n  \u003cpolicy user=\"pi\"\u003e\n    \u003callow own=\"org.bluez\"/\u003e\n    \u003callow send_destination=\"org.bluez\"/\u003e\n    \u003callow send_interface=\"org.bluez.GattCharacteristic1\"/\u003e\n    \u003callow send_interface=\"org.bluez.GattDescriptor1\"/\u003e\n    \u003callow send_interface=\"org.freedesktop.DBus.ObjectManager\"/\u003e\n    \u003callow send_interface=\"org.freedesktop.DBus.Properties\"/\u003e\n  \u003c/policy\u003e\n\u003c/busconfig\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclebert%2Fnode-bluez","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclebert%2Fnode-bluez","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclebert%2Fnode-bluez/lists"}