Bluetooth for Internet of Things

By admin , 20 March 2016

Bluetooth (LE) 4.0+ was introduced in 2011 and it is growing day by day. Smart applications can be powered by Bluetooth with its low energy functionality.  Today, many smart devices support Bluetooth LE.  Low energy consumption is mainly advantage of this technology. It comes with Client-Server concept . CBDevices1_2x As in picture, Client which may be your smart phone or tablet, wants data from server such as your heart rate controller. So now heart rate controller will generate datas at a certain times every heart beat. In this senario, server(heart beat controller) is advertising when it wants to connent to client and client(phone, tablet, ...) is scanning for new devices. "Advertising" may contain data or may not. Central devices(clients) can connect to many peripherals(smart watch, heartbeat or temperature sensor).   Bluetooth terminologies Services: These functions or capabilities are provided by Bluetooth and non Bluetooth devices, they can be “profiles” or “services” like printing, internet access, etc. Characteristic: A data value transferred between client and server, for example, the current battery voltage. Descriptor: Descriptors are optional and each characteristic can have any number of descriptors. Characteristics are defined attribute types that contain a single logical value. Identifiers: Services, characteristics, and descriptors are collectively referred to as attributes, and identified by UUIDs. Node.js Libraries Bleno (Peripheral): https://github.com/sandeepmistry/bleno Noble (Central): https://github.com/sandeepmistry/noble   Intel Edison supports Javascript. Here is link for more detail. https://software.intel.com/en-us/node-js-templates-for-intel-xdk-iot-edition   Sample Javascript Code

var noble = require(‘noble’);

noble.on('stateChange', function(state) {
 if (state === 'poweredOn') {
   noble.startScanning();
 } else {
   noble.stopScanning();
 }
});

noble.on('discover', function(peripheral) {

 peripheral.on('disconnect', function() {
   process.exit(0);
 });

 peripheral.connect(function(error) {
   peripheral.discoverServices([], function(errServices, services) {
     services.forEach(function(service) {
       service.discoverCharacteristics([], function(errCharateristic, characteristics) {
         characteristics.forEach(function(characteristic) {
           characteristic.on("read", function(data, isNotification) {
             console.log(data.toString("utf-8”));
           });
         });
       });
     });
   });
 });

});