
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
@particle/device-control-ble
Advanced tools
A library for controlling Particle devices over BLE.
npm install @particle/device-control-ble @particle/device-constants --save
NOTE: @particle/device-control-ble declares @particle/device-constants as a peerDependency - this ensures your app only ever has one copy of that dependency
A class implementing the Device OS control request protocol for BLE.
Kind: global class
StringPromiseConstructor.
| Param | Type | Default | Description |
|---|---|---|---|
| options | Object | Options. | |
| options.stream | Object | Transport stream. The stream object is expected to behave similarly to a Node's stream.Duplex in flowing mode. The only method of the stream.Duplex interface that has to be implemented by the stream is write(). The method's callback argument and return value are not used. All writes must be buffered by the stream. The channel will add listeners for the following stream events: data, end, finish, close, error. Half-closed streams are not supported, meaning that an end or a finish event emitted by the stream will result in the channel being closed immediately. | |
| options.secret | String | Uint8Array | Device secret. | |
| [options.concurrentRequests] | Number | 1 | Maximum number of requests that can be sent to the device concurrently. Requests attempted to be sent above this limit will be queued. |
| [options.requestTimeout] | Number | 60000 | Default request timeout in milliseconds. |
| [options.handshakeTimeout] | Number | 10000 | Handshake timeout in milliseconds. |
| [options.env] | Env | defaultEnv() | Environment-specific functions. |
StringChannel state.
Possible values are new, opening, open and closed.
Kind: instance property of BleControlRequestChannel
PromiseOpen the channel and initiate a handshake with the device.
An open event will be emitted when the channel is open. Requests can still be enqueued for
sending via sendRequest() while the channel is being opened.
The transport stream and the underlying BLE characteristics must be in a readable and writable state by the time this method is called.
A closed channel cannot be reopened.
Kind: instance method of BleControlRequestChannel
Close the channel.
A closed event will be emitted when the channel is closed. All pending requests will be
rejected with an error.
Kind: instance method of BleControlRequestChannel
A base class for a BLE characteristic.
Kind: global class
Emits: data, error
StringPromise.<Uint8Array>PromisePromisePromiseStringCharacteristic UUID.
Kind: instance property of BleCharacteristic
Promise.<Uint8Array>Read the current value of the characteristic.
Kind: instance method of BleCharacteristic
PromiseWrite to the characteristic.
Kind: instance method of BleCharacteristic
| Param | Type | Default | Description |
|---|---|---|---|
| data | Uint8Array | Data to write. | |
| [options] | Object | Options. | |
| [options.withoutResponse] | Boolean | false | Whether to write with or without a response. |
PromiseEnable notifications for this characteristic.
Kind: instance method of BleCharacteristic
PromiseDisable notifications for this characteristic.
Kind: instance method of BleCharacteristic
An event emitted when the peripheral indicates that the characteristic has changed.
In order to start receiving these events, notifications for the characteristic need to be enabled via enableNotifications.
Kind: event emitted by BleCharacteristic
An event emitted when an error occurs.
Kind: event emitted by BleCharacteristic
A base class for a BLE service.
Kind: global class
StringPromise.<Array.<BleCharacteristic>>StringService UUID.
Kind: instance property of BleService
Promise.<Array.<BleCharacteristic>>Get the characteristics of this service.
Kind: instance method of BleService
A base class for a BLE peripheral device.
Kind: global class
Emits: connect, disconnect, error
StringUint8ArrayNumberPromisePromisePromise.<Array.<BleService>>StringPeripheral name.
Kind: instance property of BlePeripheral
Uint8ArrayAdvertised manufacturer data.
If present, the manufacturer data is expected to start with a 2-byte company ID.
Kind: instance property of BlePeripheral
NumberATT MTU of the current established connection.
If defined, the value must be greater than or equal to 23, which is the minimum supported ATT MTU.
Kind: instance property of BlePeripheral
PromiseConnect to the peripheral.
Kind: instance method of BlePeripheral
PromiseDisconnect from the peripheral.
Kind: instance method of BlePeripheral
Promise.<Array.<BleService>>Get the services of this peripheral.
Kind: instance method of BlePeripheral
An event emitted when the host has connected to the peripheral.
Kind: event emitted by BlePeripheral
An event emitted when the host has disconnected from the peripheral.
Kind: event emitted by BlePeripheral
An event emitted when an error occurs.
Kind: event emitted by BlePeripheral
A base class for a BLE manager.
Kind: global class
Promise.<Array.<BlePeripheral>>PromiseConstructor.
Promise.<Array.<BlePeripheral>>Scan for available peripherals.
If filtering options, such as names or services, are provided, a discovered peripheral will
only be reported by this method if it satisfies all of the filtering options.
Only one scan can be active at a time.
Kind: instance method of BleManager
Returns: Promise.<Array.<BlePeripheral>> - Discovered peripherals.
| Param | Type | Default | Description |
|---|---|---|---|
| [options] | Object | Options. | |
| [options.names] | Array.<(String|RegExp)> | Peripheral names. | |
| [options.services] | Array.<String> | Service UUIDs. | |
| [options.count] | Number | Maximum number of peripherals to scan for. | |
| [options.timeout] | Number | 5000 | Maximum duration of the scan in milliseconds. |
PromiseShut down the BLE manager.
Calling this method will interrupt the ongoing scan process and close all connections with peripherals with an error.
Kind: instance method of BleManager
A base class for an AES-128 cipher operating in ECB mode.
Kind: global class
Promise.<Uint8Array>Encrypt a single block of data.
Kind: instance method of Aes128Cipher
Returns: Promise.<Uint8Array> - Ciphertext block.
| Param | Type | Description |
|---|---|---|
| block | Uint8Array | Plaintext block. The block must be 16 bytes long. |
A base class defining environment-specific functions used by the library.
Kind: global class
Aes128CipherPromise.<Uint8Array>Aes128CipherCreate an AES-128 cipher operating in ECB mode.
Kind: instance method of Env
Returns: Aes128Cipher - Cipher object.
| Param | Type | Description |
|---|---|---|
| key | Uint8Array | Encryption key. The key must be 16 bytes long. |
Promise.<Uint8Array>Generate cryptographically strong random data.
Kind: instance method of Env
Returns: Promise.<Uint8Array> - Random data.
| Param | Type | Description |
|---|---|---|
| size | Number | Number of bytes to generate. |
Default timeout of a BLE scan.
Kind: global constant
EnvGet the default environment-specific functions.
Kind: global function
Promise.<Response>Send a request to the device.
Kind: global typedef
| Param | Type | Description |
|---|---|---|
| type | Number | Request type. See system_control.h in Device OS for the list of defined request types. |
| [data] | Uint8Array | Request payload data. |
| [options] | Object | Options. |
| [options.timeout] | Number | Request timeout in milliseconds. If not specified, the default timeout configured at construction time will be used. |
Properties
| Name | Type | Description |
|---|---|---|
| result | Number | Result code. See system_error.h in Device OS for the list of defined result codes. |
| data | Uint8Array | Response payload data. |
NOTE: Unfortunately, docs have a nasty habit of falling out of date. When in doubt, check usage in tests
FAQs
A library for controlling Particle devices over BLE
The npm package @particle/device-control-ble receives a total of 3 weekly downloads. As such, @particle/device-control-ble popularity was classified as not popular.
We found that @particle/device-control-ble demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 23 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.