APIs
This website is NOT up-to-date, it has been moved to π https://itpnyu.github.io/p5ble-website
All APIs:
- Request and Connect to Bluetooth Devices
- Read a Bluetooth Characteristic
- Write to a Bluetooth Characteristic
- Start and stop GATT Notifications
- Get disconnected from a Bluetooth Device
p5ble
// Interact with multiple devices, each new p5ble() only connect to one device
const myBLE = new p5ble();
const myOtherBLE = new p5ble();
Properties:
1. device
Once itβs connected successfully, .device will have all the information of the device
2. server
3. service
4. characteristics, array
Methods:
.connect(service, gotCharacteristics?)
Parameters:
- Service: Service UUID(e.g.
0x1234,0x12345678,99999999-0000-1000-8000-00805f9b34fb) or Service Name(e.g.battery_service) - gotCharacteristics(optional): A callback function, e.g.
(err, characteristics) => { console.log(characteristics) }
Returns characteristics: array
.read(characteristic, dataType?, gotData?)
Parameters:
- characteristic: The characteristic UUID that you want to read
- dataType (optional): default to
uint8, options:uint16,uint32,string,int8,int16,int32,float32,float64 - gotData(optional): A callback function, e.g.
(err, data) => { console.log(data) }
Returns data
.write(characteristic, data)
Parameters:
- characteristic: The characteristic you want to write to
- data: String
.startNotifications(characteristic, handleNotifications, dataType?)
Parameters:
- characteristic: The characteristic you want to start notification
- handleNotifications: A callback function, e.g. (data) => { console.log(data) }
- dataType (optional): default to
uint8, options:uint16,uint32,string,int8,int16,int32,float32,float64
.stopNotifications(characteristic)
Parameters:
- characteristic: The characteristic you want to stop notification
.disconnect()
onDisconnected(handleDisconnected)
Parameters:
- handleDisconnected: A callback function, e.g. (device) => { console.log('Device ' + device.name + ' is disconnected.'); }
.isConnected()
returns a Boolean