Paso 2: Aplicación BLE y los servicios
Para un posible periférico, necesitará registrar servicios que usted se expone para otros hosts. Con el módulo bleno, puede registrar el servicio y comenzar a funciones de publicidad.
var bleno = require('bleno');<br>var BlenoPrimaryService = bleno.PrimaryService; var FirstCharacteristic = require('./characteristic');<br><br>bleno.on('stateChange', function(state) {<br>console.log('BLE State: ' + state); if (state === 'poweredOn') { bleno.startAdvertising('BLE Light', ['fc00']); } else { if(state === 'unsupported'){ error.log("BLE error. Check board configuration."); } bleno.stopAdvertising(); } }); bleno.on('advertisingStart', function(error) {console.log('Advertising:' + (error ? 'error ' + error : 'success')); if (!error) { bleno.setServices([ new BlenoPrimaryService({ uuid: 'fc00', // Custom BLE Service characteristics: [] // TODO: Add characteristic }) ]); } }); console.log("BLE app initiated...");
El es el esqueleto básico que formará su app.js. Estamos todavía para añadir características a nuestro servicio, que nos va a hacer en la siguiente sección.