mbed BLE API for JerryScript
This library exposes the mbed BLE API to JerryScript targets forked from mbed-js-ble
The following objects are exposed:
- BLEDevice - holds reference to the Bluetooth stack.
- BLEService - references a GATT service.
- BLECharacteristic - references a GATT characteristic.
Usage
var ble = BLEDevice();
var characteristic = BLECharacteristic('9101', ['read', 'write', 'notify'], 1);
var service = BLEService('9100', [ characteristic ]);
ble.ready(function() {
print("ble is ready");
ble.addServices([
service
]);
ble.startAdvertising("YOUR_NAME", [
service.getUUID()
], 1000);
});
ble.onConnection(function() {
print("GATT connection established");
});
ble.onDisconnection(function() {
print("GATT disconnected, restarting advertisements");
ble.startAdvertising();
});
print("BLE is connected? " + ble.isConnected());
Interacting with characteristics
characteristic.write([ 0x98, 0x37 ]);
var arr = characteristic.read();
print("Length is " + arr.length + ", first element is " + arr[0]);
characteristic.onUpdate(function (newValue) {
print("Updated! New value is " + newValue.length + ", first element is " + newValue[0]);
});
Fork Details
Implememted support for 128-bit UUIDs
Examples:
characteristic = BLECharacteristic('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX', ['read', 'write', 'notify'], 1);
characteristic = BLECharacteristic('9100', ['read', 'write', 'notify'], 1);
service = BLEService('9100', [ characteristic ]);
service = BLEService('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX', [ characteristic ]);
Implemented Long UUID support in BLEService.GetUUID()
uuid = service.GetUUID()
Added Manufacturer info in the startAdveritising method:
BLE ble = BLEDevice();
ble.startAdvertising('advertisingName', [ service.getUUID() ]);
ble.startAdvertising('advertisingName', [ service.getUUID() ], 100);
ble.startAdvertising('advertisingName', [ service.getUUID() ], 100, '018000E00000');
ble.startAdvertising('advertisingName', [ service.getUUID() ], '018000E00000');