How to use the bleno.on function in bleno

To help you get started, we’ve selected a few bleno examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github balena-io-playground / wifi-connect-ble / apps / ble.js View on Github external
});
    }, 180000);

    bleno.on('stateChange', function(state) {
        console.log('BLE stateChange: ' + state);
        if (state === 'poweredOn') {
            poweredOn = true;
        } else {
            console.log('BLE advertising stopped');
            poweredOn = false;
            advertisingToggle = false;
            bleno.stopAdvertising();
        }
    });

    bleno.on('advertisingStart', function(error) {
        if (!error) {
            bleno.setServices([
                new bleno.PrimaryService({
                    uuid: 'F1D46062-7FD3-4C17-B096-9E8D61E15583',
                    characteristics: [
                        // Read device resin-UUID
                        new bleno.Characteristic({
                            uuid: 'FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFF1',
                            properties: ['read'],
                            descriptors: [
                                new bleno.Descriptor({
                                    uuid: '2901',
                                    value: 'Read device resin-UUID'
                                })
                            ],
                            onReadRequest: function(offset, callback) {
github SamsungInternet / SamsungBluetoothWiFiManager / bleno-orig / examples / pizza / peripherals.js View on Github external
//
    // We will also advertise the service ID in the advertising packet,
    // so it's easier to find.
    //
    bleno.startAdvertising(name, [pizzaService.uuid], function(err) {
      if (err) {
        console.log(err);
      }
    });
  }
  else {
    bleno.stopAdvertising();
  }
});

bleno.on('advertisingStart', function(err) {
  if (!err) {
    console.log('advertising...');
    //
    // Once we are advertising, it's time to set up our services,
    // along with our characteristics.
    //
    bleno.setServices([
      pizzaService
    ]);
  }
});
github PiSugar / sugar-wifi-conf / index.js View on Github external
// console.log('check bluetooth')
  // console.log(execSync('dmesg |grep -i Bluetooth').toString())
  console.log('Bleno starting...')
  util.inherits(wifiConfService, BlenoPrimaryService)

  bleno.on('stateChange', function(state) {
    console.log('on -> stateChange: ' + state + ', address = ' + bleno.address)
    if (state === 'poweredOn') {
      bleno.startAdvertising(config.name, [ UUID.SERVICE_ID ])
    } else {
      bleno.stopAdvertising()
    }
  })

// Linux only events /////////////////
  bleno.on('accept', function(clientAddress) {
    console.log('on -> accept, client: ' + clientAddress)
    bleno.updateRssi()
  })

  bleno.on('disconnect', function(clientAddress) {
    console.log('on -> disconnect, client: ' + clientAddress)
  })

  bleno.on('rssiUpdate', function(rssi) {
    console.log('on -> rssiUpdate: ' + rssi)
  })
//////////////////////////////////////

  bleno.on('mtuChange', function(mtu) {
    console.log('on -> mtuChange: ' + mtu)
  })
github TheBubbleworks / TheBubbleWorks_RaspberryPi_BLE_GPIO_Server / main.js View on Github external
bleno.on('advertisingStart', function(error) {
    debug('on -> advertisingStart: ' + (error ? 'error ' + error : 'success'));

    if (!error) {
        //if (advertisingState = GATT_ADV_STATE) {
            debug("Advertising Services");
            bleno.setServices([
                uartService
            ]);
        //}
    }
});


bleno.on('accept', function(clientAddress) {
    info('onConnect from: ' + clientAddress);
    flipFlopEnabled = false;
});

bleno.on('disconnect', function(clientAddress) {
    info('onDisconnect from: ' + clientAddress);
    flipFlopEnabled = true;
});




// ---------------------------------------------------------------------------------------------------------
// Notes

/*
github hardillb / mqtt2ble / index.js View on Github external
});

client.on('message',function(topic, message){
	console.log(message.toString());
  topicCharacteristic.update(message);
});

bleno.on('stateChange', function(state){
  if (state === 'poweredOn') {
    bleno.startAdvertising('mqtt', ['ba42561bb1d2440a8d040cefb43faece']);
  } else {
    bleno.stopAdvertising();
  }
});

bleno.on('advertisingStart', function(error){
  if(!error) {
  	bleno.setServices([
  	  new BlenoPrimarySerivce({
  	  	uuid: 'ba42561bb1d2440a8d040cefb43faece',
  	  	characteristics: [
  	  	  topicCharacteristic
  	  	]
  	  })
  	]);
  }
});
github noble / bleno / examples / battery-service / main.js View on Github external
var bleno = require('bleno'),
  BatteryService = require('./battery-service');
  
var primaryService = new BatteryService();

bleno.on('stateChange', function(state) {
    console.log('on -> stateChange: ' + state);

    if (state === 'poweredOn') {
        bleno.startAdvertising('Battery', [primaryService.uuid]);
    } else {
        bleno.stopAdvertising();
    }
});

bleno.on('advertisingStart', function(error) {
    console.log('on -> advertisingStart: ' + (error ? 'error ' + error : 'success'));

    if (!error) {
        bleno.setServices([primaryService]);
    }
});
github SamsungInternet / SamsungBluetoothWiFiManager / bleno-orig / examples / echo / main.js View on Github external
var EchoCharacteristic = require('./characteristic');

console.log('bleno - echo');

bleno.on('stateChange', function(state) {
  console.log('on -> stateChange: ' + state);

  if (state === 'poweredOn') {
    bleno.startAdvertising('echo', ['ec00']);
  } else {
    bleno.stopAdvertising();
  }
});

bleno.on('advertisingStart', function(error) {
  console.log('on -> advertisingStart: ' + (error ? 'error ' + error : 'success'));

  if (!error) {
    bleno.setServices([
      new BlenoPrimaryService({
        uuid: 'ec00',
        characteristics: [
          new EchoCharacteristic()
        ]
      })
    ]);
  }
});
github hardillb / mqtt2ble / index.js View on Github external
}

var client = mqtt.connect(config.broker);

var topicCharacteristic = new TopicCharacteristic(config);

client.on('connect', function(){
  client.subscribe(config.topic);
});

client.on('message',function(topic, message){
	console.log(message.toString());
  topicCharacteristic.update(message);
});

bleno.on('stateChange', function(state){
  if (state === 'poweredOn') {
    bleno.startAdvertising('mqtt', ['ba42561bb1d2440a8d040cefb43faece']);
  } else {
    bleno.stopAdvertising();
  }
});

bleno.on('advertisingStart', function(error){
  if(!error) {
  	bleno.setServices([
  	  new BlenoPrimarySerivce({
  	  	uuid: 'ba42561bb1d2440a8d040cefb43faece',
  	  	characteristics: [
  	  	  topicCharacteristic
  	  	]
  	  })
github line / line-simple-beacon / tools / line-simplebeacon-nodejs-sample / simplebeacon.js View on Github external
const args = argv.option([{
  name: 'hwid',
  description: '[REQUIRED] 10 digits of hexadecimal number. ',
  type: 'string',
  example: "'--hwid=c0d10ad7f8'"
}, {
  name: 'device-message',
  description: '[OPTIONAL] 2 .. 26 digits of hexadecimal number.',
  type: 'string',
  example: "'--device-message=ff'"
}]).run();

const HWID = args.options['hwid'];
const DEVICE_MESSAGE = args.options['device-message'] || '00';

bleno.on('stateChange', function (state) {
  console.log('stateChange: ' + state);
  if (state === 'poweredOn') {
    const data = simplebacon.createLineSimpleBeaconAdvertisingPDU(HWID, DEVICE_MESSAGE);
    console.log(data);
    bleno.startAdvertisingWithEIRData(data);
  } else {
    bleno.stopAdvertising();
  }
});
github balena-io-playground / wifi-connect-ble / apps / ble.js View on Github external
console.error("BLE script failed isOnline check");
            } else {
                if (!online && !advertisingToggle && poweredOn) {
                    console.log('BLE advertising started');
                    advertisingToggle = true;
                    bleno.startAdvertising("resin-" + process.env.RESIN_DEVICE_UUID.substr(0, 7), ['F1D46062-7FD3-4C17-B096-9E8D61E15583']);
                } else if (online && advertisingToggle && poweredOn) {
                  bleno.stopAdvertising();
                  console.warn('BLE advertising stopped');
                  advertisingToggle = false;
                }
            }
        });
    }, 180000);

    bleno.on('stateChange', function(state) {
        console.log('BLE stateChange: ' + state);
        if (state === 'poweredOn') {
            poweredOn = true;
        } else {
            console.log('BLE advertising stopped');
            poweredOn = false;
            advertisingToggle = false;
            bleno.stopAdvertising();
        }
    });

    bleno.on('advertisingStart', function(error) {
        if (!error) {
            bleno.setServices([
                new bleno.PrimaryService({
                    uuid: 'F1D46062-7FD3-4C17-B096-9E8D61E15583',

bleno

A Node.js module for implementing BLE (Bluetooth Low Energy) peripherals

MIT
Latest version published 7 years ago

Package Health Score

54 / 100
Full package analysis