Package Exports
- ble-wormhole
- ble-wormhole/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ble-wormhole) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
WormholeProtocol
Bluetooth Low Energy Offline Communication Protocol
Installation
npm install ble-wormhole --save
Usage
CreateNativeEventEmitter
BLEWormhole.CreateNativeEventEmitter();
CreatServer
BLEWormhole.CreatServer(bleServiceUUID, connectCharaUUIDs, name);
Event handler
BLEWormhole.DisconnectHandler = deviceID => {
console.log('disconnect', deviceID);
};
BLEWormhole.ReceiveHandler = characteristic => {
//characteristic = {'uuid':'','value':Buffer.from(''),'service':'','device':''}
};
BLEWormhole.DiscoverDeviceStopHandler = () => {
console.log('stop scan');
};
BLEWormhole.DiscoverDeviceHandler = device => {
//device = {name:'',serviceUUIDs:['',''],deviceID:'',connected:false}
};
BLEWormhole.BluetoothStateHandler = state => {
/* `unknown`
* `resetting`
* `unsupported`
* `unauthorized`
* `poweredOff`
* `poweredOn`
*/
};
GenerateDeviceID
BLEWormhole.GenerateDeviceID()
.then(res => {})
.catch(err => {
console.error(err);
});
CheckState
BLEWormhole.CheckState();
Scan
BLEWormhole.Scan([bleServiceUUID], dicoveredSeconds, true);
StopScan
BLEWormhole.StopScan()
Start
receiveHandler
can replace BLEWormhole.ReceiveHandler
BLEWormhole.Start(receiveHandler)
.then(res => {})
.catch(err => {
console.error(err);
});
Connect
BLEWormhole.Connect(device.deviceID, bleServiceUUID, connectCharaUUIDs)
.then(res => {
console.log('connect:' + res);
})
.catch(err => {
console.error(err);
});
Disconnect
BLEWormhole.Disconnect(device.deviceID)
.then(res => {})
.catch(err => {
console.error(err);
});
StopNotification
BLEWormhole.StopNotification(deviceID,serviceUUID,characteristicUUID)
.then(res => {})
.catch(err => {
console.error(err);
});
Send
BLEWormhole.SendBuffer(
connectedDeviceName,
connectedDeviceID,
bleServiceUUID,
incomingCharaUUID,
data,
);