123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- var bleno = require('bleno');
- var StringDecoder = require('string_decoder').StringDecoder;
- var name = 'wifitest';
- var serviceUuids = ['fffffffffffffffffffffffffffffff0']
- function bytesToString(buffer) {
- return String.fromCharCode.apply(null, new Uint8Array(buffer));
- }
- bleno.on('stateChange', function (state) {
- console.log(state);
- bleno.startAdvertising(name, serviceUuids, function (error) {
- if (error) {
- console.log(error);
- }
- console.log('start');
- var Descriptor = bleno.Descriptor;
- var descriptor = new Descriptor({
- uuid: '2901',
- value: 'test' // static value, must be of type Buffer or string if set
- });
- var Characteristic = bleno.Characteristic;
- var characteristic = new Characteristic({
- uuid: 'fffffffffffffffffffffffffffffff1', // or 'fff1' for 16-bit
- properties: ['read', 'write', 'writeWithoutResponse'], // can be a combination of 'read', 'write', 'writeWithoutResponse', 'notify', 'indicate'
- value: null, // optional static value, must be of type Buffer - for read only characteristics
- descriptors: [
- // see Descriptor for data type
- descriptor
- ],
- onWriteRequest: function (data, offset, withoutResponse) {
- console.log(bytesToString(data));
- }
- });
- var PrimaryService = bleno.PrimaryService;
- var primaryService = new PrimaryService({
- uuid: 'fffffffffffffffffffffffffffffff0', // or 'fff0' for 16-bit
- characteristics: [
- // see Characteristic for data type
- characteristic
- ]
- });
- bleno.setServices(primaryService, function (error) {
- if (error) {
- console.log(error);
- }
- console.log('success');
- });
- });
- });
|