About IOT(3)Using BLE in Javascript (noble)

Machine Learning Artificial Intelligence Natural Language Processing Semantic Web Algorithm Search Technology DataBase Technology Ontology Technology Digital Transformation UI and DataVisualization Workflow & Services IT Infrastructure Probabilistic Generative Model Computer Hardware Time Series Data Analysis Stream Data Control IOT&Sensor Navigation of this blog

About IOT(3)Using BLE in Javascript (noble)

In the previous article, I introduced bluejelly.hs, which is the simplest of all the lifelines for connecting to BLE. This time, I would like to introduce noble, which runs on node.js and can be combined with the server-side applications I have mentioned so far.

Noble is a javascript module that runs on node.js. To use noble, install the module using “npm install noble”. For example, in the case of the aforementioned ble device csan, the following code can be used.

var noble = require('noble');
noble.startScanning(); // any service UUID, no duplicates


noble.startScanning([], true); // any service UUID, allow duplicates


var serviceUUIDs = ["<service UUID 1>", ...]; // default: [] => all
var allowDuplicates = <false|true>; // default: false

noble.startScanning(serviceUUIDs, allowDuplicates[, callback(error)]); // particular UUID's

In the first stage of BLE communication, there is broadcast communication (communication without specifying the target) called advertisement, and the receiver scans it in the above form to obtain the transmitter’s ID called UUID and the information of received radio wave strength called RSSI. By using this information, it is possible to set up a service called “location information service” that provides information via the web when the information terminal is held over a specific location.

In addition, a connection request signal is sent to the destination of the obtained advertisement information, and if it is accepted, the communication switches to one-to-one communication called GATT (Generic attribute profile) communication. In GATT communication, data is exchanged using the concepts of Service and Characteristic. In GATT communication, data is exchanged based on the concepts of service and characteristic, where service is a label for characteristic, and characteristic is a data structure that the peripheral device shares with the central device.

peripheral.discoverAllServicesAndCharacteristics([callback(error, services, characteristics)]);
service.discoverCharacteristics() // any characteristic UUID

var characteristicUUIDs = ["<characteristic UUID 1>", ...];
service.discoverCharacteristics(characteristicUUIDs[, callback(error, characteristics)]); // particular UUID's
characteristic.read([callback(error, data)]);
characteristic.write(data, withoutResponse[, callback(error)]); // data is a buffer, withoutResponse is true|false

Since each IOT device defines its own characteristic, you can set it by referring to the API information that is available to the public.

If you want to build something like a sensor network, you can use small sensor tags such as TI’s sensor tag, or connect JINS’ MEME, a glasses-type device that became a hot topic a while ago.

コメント

タイトルとURLをコピーしました