@csllc/mb-conn-noble-ble
v1.2.0
Published
Connection type for MODBUS using Noble BLE transparent UART
Downloads
265
Keywords
Readme
@csllc/mb-conn-noble-ble
MODBUS-over-BLE connection package using @abandonware/noble.
Provides a BleConnection class (extending Connection from @csllc/modbus-types) that bridges BLE transparent UART characteristics to the MODBUS connection API, and a scan() utility for discovering BLE peripherals.
Installation
npm install @csllc/mb-conn-noble-bleExports
BleConnection
A Connection subclass that bridges BLE UART RX/TX characteristics to the Connection API used by @csllc/modbus-types.
import { BleConnection } from '@csllc/mb-conn-noble-ble';
const connection = new BleConnection(ble, peripheral, rxChar, txChar);
await connection.open(); // subscribes to UART RX notifications
await connection.write(buf); // writes to UART TX characteristic
await connection.close(); // unsubscribes and disconnectsopen()— Subscribes to the UART RX characteristic. Incoming BLE notifications are converted toArrayBufferand emitted as'data'events.write(data: ArrayBuffer)— Writes bytes to the UART TX characteristic. Emits'write'.close()— Unsubscribes from RX and disconnects the peripheral. Emits'close'.isOpen()— Returnstrueif the connection is active.destroy()— Closes and removes all listeners.
Events: 'open', 'close', 'data', 'write', 'error'
scan(serviceUuids?, duration?)
Discovers BLE peripherals using NobleBleManager from @csllc/noble-ble.
import { scan } from '@csllc/mb-conn-noble-ble';
const peripherals = await scan(['180a'], 5000);
// [{ id: '...', type: 'ble', peripheralId: '...', name: 'CS1816' }]BleConnectionInfo
interface BleConnectionInfo {
id: string; // unique identifier
type: 'ble'; // connection type
peripheralId: string; // BLE peripheral ID
name?: string; // advertised name
}See Also
@csllc/mb-conn-noble-mac— macOS variant using noble-mac / CoreBluetooth@csllc/noble-ble— theBleinterface adapter wrapping@abandonware/noble@csllc/mb-conn-node-serial— serial connection for USB dongles
