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,
);