Important JavaScript in the gateway project

In this section, we will quickly take a look at the important classes responsible for communicating with Bluetooth devices using the noble library. The BLE adapter handles all major BLE connections and traffic. This means that most classes call this if Bluetooth communication is required. You will also find references to the noble API and the customized Bluetooth SIG implementation of our_modules in this class. The main imports in this class are as follows:

var keystore = require('./keyStore');
var debug = require('debug')('bleAdapter');
//var error = debug('gateway:ble:error');
//var log = debug('gateway:ble:log');
var util = require('util');
var db = require('./dataModel');
var conts = require('./constants');
var timeconts = require('./timeconstants');
var events = require('events');
var Peripheral = require('./our_modules/noble/lib/peripheral');
var noble = require('./our_modules/noble');
var appserver = require('./app');
var bleNotify = require('./bleNotification');
var fs = require("fs");

The main module defines the major callbacks: which function to trigger if the device state changes, which function to call when scanning starts, and so on. You can customize these methods if you want different behavior to what is already written. Here is a brief guide on the functions written in this module:

  • onScanStarted: A callback upon starting a Bluetooth scan
  • onScanStopped: A callback upon stopping a Bluetooth scan
  • onDiscoveredDevices: A callback after finding a Bluetooth device
  • onNotification: A callback on receiving a notification from a characteristic
  • onDeviceDisconnect: A callback on disconnecting a Bluetooth device
  • connectDevice: A function that connects to a Bluetooth device

For a complete list of methods offered by this class, refer to the bleAdapter.js class:

  • The dataModel.js file contains functions to form data objects that will go back from the server. These data objects can be defined in nodes, services, characteristics, managers, NodesJson (complete JSON of a Bluetooth device), ServicesJson (complete JSON of a service), characteristicsJson (complete JSON of a characteristic), and ManagementJson, which will incorporate all other JSONs to form a big payload.
  • The management.js file provides all the functionalities related to the management of a Bluetooth device. If you refer to the RESTful table as mentioned previously, all the calls starting with /management/... are handled in this .js file. This class primarily depends on the bleAdapter.js (for any communication with the Bluetooth devices) and dataModel.js (to prepare objects to return back).
  • The services.js file contains all the GATT-related RESTful calls. For example, the implementation of retrieving the services from a particular Bluetooth device can be found here. This class primarily depends on bleAdapter.js (for Bluetooth communication) and dataModel.js (preparing data objects to return back).
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.204.208