Blog‎ > ‎

EVOTHINGS - BLE Apps Development in JavaScript

pubblicato 8 dic 2015, 02:38 da iBlio connect   [ aggiornato in data 21 dic 2015, 12:56 ]
Evothings Studio is a set of development tools that makes it fun to develop and rapid prototype IoT-apps for mobile phones and tablets.

Hybrid  App Development Made Fast  post explain  that mobile app development with hybrid tools like Cordova/PhoneGap works great, but there is a catch – development turnaround times can kill you. The post will help you preserve your sanity as well as let you do faster prototyping and get more apps done.


Bluetooth Low Energy is used for connecting things


Bluetooth Low Energycommonly referred to as BLE, is a cool low-power wireless technology that is perfect for connecting things to mobile apps. In the near future, we will see lots of consumer products that use BLE; toys, home appliances, bikes, cars, sensors for sports equipment, clothes, you name it! Many of these devices will need an associated mobile application to be useful. 
Therefore, app developers have vast opportunities to create innovative applications for both custom-built and consumer BLE hardware.

In this post, we will first make an overview of BLE and then look at a mobile app for BLE written in JavaScript that you can run, modify and extend.

Bluetooth Low Energy is a low-power wireless radio technology that consumes very little energy (hence the name). Typically BLE 

devices are small, battery-powered and the battery can last for years. The transmission range depends on the nature of the surrounding area (walls, buildings etc), but is somewhere between 10 and 30 meters, some even like www.iBLio.net  claim up to 150 meters for it's standard products and 300 meters for long-range products.

BLE devices can be used for both reading (input) information and for writing (output) information to perform operations. Some devices are “read-only”, for example Beacons and Sensors that gather information from their environment. Others you can interact with, like door controllers (e.g. to open a garage-door), light controllers and radio-controlled toys.

Mobile phones and tablet are perfect to read/control BLE-devices. iOS has great support for BLE, and Android (4.3 and later) also has BLE support (but not all Android units have the required hardware). BLE makes it possible to program apps that interact with hardware devices, creating and eco-system of apps and all sorts of hardware.

The origin of BLE is Bluetooth (“Bluetooth Classic”), and Bluetooth 4.0 includes the BLE standard. That means that a device that 

supports Bluetooth 4.0 supports BLE. BLE is also referred to as “Bluetooth Smart”. One things that is handy with BLE is that it can operate without pairing. This makes it easy to monitor BLE devices (which is how iBeacons work) and connect to and communicate with devices.

Today, BLE is built into fitness wristbands, BLE powers Beacons such as iBLio, the Texas Instruments SensorTag, the LightBlue Bean, the RFduino, and you can easily equip an Arduino with a BLE Shield

There are a number of professional BLE development boards available, like Bluegiga Bluetooth 4.0 Smart ModulesCSR µEnergy® Development Kit, and Bluetooth products from Texas Instruments.

In the near future, we will see lots of consumer products that use BLE; toys, home appliances, bikes, cars, sports equipment, bags, clothes, and much more. It is a truly innovative area, with lots of projects on crowdfunding sites Kickstarter. 

BLE is one of the core technologies of the Internet of Things (IoT).

A interesting and useful property of BLE is that you can determine roughly how close a device is. This is possible because of the Received Signal Strength Indicator (RSSI) which is a value that hints at the distance from which the signal originated. iBeacons use this to detect the proximity of beacons. For example, if you stroll along a city street, you can use a mobile app that tells you when you approach a restaurant or cafe.

Importantly, BLE is a “local area” technology that works outside of the Internet and outside of WiFi networks. It is an independent radio technology. Note that mobile apps that connect to BLE devices can in turn connect to the Internet to transmit data, but this is not a requirement for BLE, it is rather an application of BLE. This makes Bluetooth Low Energy a very flexible technology for communication with things (it would even work on an expedition to Mars!).

A reference book for learning about BLE in depth is Bluetooth Low Energy: The Developer’s Handbook.

Quick guide to BLE programming


BLE devices have one of two roles, “central” or “peripheral”. A peripheral is typically the “small thing”. It is that battery-powered Sensor or Beacon or radio-controlled quadcopter. A mobile device typically has the central role. This is usually where the “intelligence” or “business logic” is handled.

A peripheral can be in one of two states, advertising or connected. When advertising, the device sends out a signal that says “Here I am, and here is my name and my conditions”. The central device can listen for advertising devices, and eventually select one to connect to. Being connected is required to be able to exchange data, to read values from and to execute commands on the peripheral device.

Some peripherals use advertisement mode only, one example is iBeacons. An iBeacon sends out a signal every now and then (ranging from lots of times per second to once a minute or so) telling who it is. The RSSI value (signal strength) can then be used to determine who close the beacon is. This technique can even be used for in-door positioning, using triangulation of multiple beacons.

When you connect as a central to a device, you can read data from it. This is what the data structure of a BLE device looks like this:

device (peripheral)
  services
    characteristics
      descriptors

Key points:

  • Services group functionality.
  • Characteristics represent data that you can read, write, or subscribe to using notifications.
  • Descriptors contain “meta-data” for characteristics, however not all characteristics have descriptors.

For example, a thermometer device would have a service that has a characteristic for reading the temperature. You can then read the temperature by reading the value of the characteristic. You could also enable a notification for the characteristic, to get periodic calls with the updated temperature value (in this case you don’t have to poll the value).

To connect to a BLE device, you first scan for BLE devices, then connect to the device you wish to use. Here is an outline:

  • Scan for devices.
  • When a device is found, you can identify the device, and determine its RSSI value.
  • When the device you want is found, you can connect to it.
  • When connected you can read services, characteristics, descriptors.
  • Then write and/or read the characteristics you wish to use. Enable any notifications you want to use.

When you program a mobile app with Evothings Studio, you use JavaScript to perform the above. Now we will look at a hands on example of a BLE app you can try out yourself.

Hands on example – BLE Scan


The example app “BLE Scan” in Evothings Studio is a great starting point for learning how to scan for devices.

BLEScan

It is quick and easy to get started:

  • Install the Evothings Client app on your iOS or Android device (available in the AppStore and on Google Play). Note that for Android you need at least Android 4.3 and the required hardware.
  • Download Evothings Studio.
  • Launch Evothings Workbench on your computer.
  • Start the Evothings Client app and scan for and connect to the Workbench.
  • Locate the example app “BLE Scan” in the Workbench project list and press Run.
  • Press the “Scan” button in the app.
  • Nearby BLE devices that are in advertisement mode should now display, along with the RSSI value.

There are currently some quirks on Android, check out the documentation of the BLE Scan example to learn how to work around them.

JavaScript BLE plugin


To access BLE from JavaScript, the Evothings BLE plugin for Apache Cordova is used.

Files of interest:

  • ble.js is the API for the BLE plugin. This file is shipped with the Evothings Client app (which is built with Cordova), and is not included in the source code for the BLE Explorer app. You don’t have to include this file in your HTML code, it is included automatically with cordova.js.
  • easy-ble.js is a high-level abstraction of the API in ble.js. This file you need to include explicitly in your HTML code if you wish to use it.

More Evothings BLE example apps. tutorials and BLE tools


Evothings Studio comes with several apps that show how to use BLE. There are also lots of tutorials to try out – about iBeacons, radio controlled modules, and the TI SensorTag. 

The configuration and complete verification of the iBLio Devices may be fully performed by BLE skilled people using one of the generic and great BLE Mobile Tools availables on the stores, such as :

 for Android:  
  • "nRF Master Control Panel" by NORDIC SEMICONDUCTORS 
  • "BLE Scanner" by BLUE PIXEL
  • "Bluetooth LE Scanner" by Alexandros Schillings
 for iOS:
  • "BLExplr" by MICHAEL KROLL
  • "LightBlue" by PUNCH THROUGHT
  • "BLE Explorer" by DAYSIDE
  • "BTLExplorer" by KST   

Call to action 


Download Evothings Studio , use any BLE devices near you and start partecipate the BLE community ! 

Comments