Silex Unwired

Develop BLE/IoT Gateway Using Linux Box LB-100AN

With the development of sensors, wireless communication, embedded systems and cloud computing, Internet of Things (IoT) technology is used in many applications like logistics, smart meter, public security, healthcare, telematics and so on. An IoT Gateway  plays an important role in IOT applications, which facilitates the seamless integration of wireless sensor networks and Internet. This article focuses on developing an embedded Linux application to use the Silex's newest Linux Box, LB-100AN, as an IoT gateway using Bluetooth technology.

What Do You Need to Develop an IoT Gateway

To build a gateway unit that collects sensory data from the devices and shares it via wireless to a cloud service, the following is required.

  • Sensors
  • Ability to collect data from the sensors
  • WLAN or Ethernet for accessing the network
  • Gateway Device to connect to the cloud
  • Cloud Service

For this application, we use LB-100AN and an off the shelf Bluetooth dongle (USB) along with the Kii as the cloud service to develop and demonstrate LB-100AN working as a gateway device. With this we will be able to transfer/send BLE information from the BT devices to the cloud.

The LB-100AN platform runs the Linux OS, and features a number of physical interfaces such as wired/wireless LAN, USB, and RS-232C. SIlex's SDK along with this "Mass Production Ready" hardware, makes the LB-100AN an ideal product to quickly go to market with customers own built in applications that fit their custom needs. It also features the SX-PCEAN2, which is a WLAN module that supports industrial temperature, access point and station modes with enterprise security. 

LB-100AN HW spec_image.png

 We will use Kii for cloud connectivity which is one of our cloud connectivity partners. Kii uses MBaaS (Mobile Back-end as a Service), which is ideal for developers as they can focus on programming their app and just pushing it out to Kii Cloud without having to build their own servers and back end. 

 

Gateway Development

There are three things that need to happen in a gateway application for BLE. We need Bluetooth, application/environment to communicate to the cloud, and a system to translate Bluetooth information into a form that can be used to push data to the cloud. The following sections will elaborate on each of these three functions. 

Enabling Bluetooth:

We need to add and enable Bluetooth function in the SDK provided with the LB-100AN. The SDK already contains the BlueZ stack compiled for the LB-100AN. In general BlueZ controls Bluetooth service in the three layers described below.

  • Application: Manages the setup of Bluetooth devices from the user space.
  • Daemon: BlueZ daemon runs in the background and sets up the Bluetooth adapter when it is inserted.
  • Driver: The driver is already built into the Linux kernel code. These are for the device interfaces for example USB etc.

Using the Mino Menu config, validate the Bluetooth driver. 

Mino Menu Config.jpg

By using zx build root, BlueZ can be downloaded and installed on the LB-100AN. 

bluez-utils.jpg

Using the latest LB-100AN, Bluetooth function will be available once the above steps are completed. Now verify that Bluetooth is working by

  1. Boot the Bluetooth daemon
  2. Scan BLE device using HCITOOL

It will start scanning for other Bluetooth devices in the vicinity once the daemon is started. 

 

Creating Application/Environment for Cloud Communication:

To enable the gateway functionality, next we need to prepare the environment and application to enable communicating to the cloud. we need the following two modules:

  1. Gateway Agent
  2. Gateway Manager

Kii Gateway client is created in GO language, which is a free and open source programming language created by Google. We need to set the environment variable of GOPATH. The GOPATH environment variable is used to specify directories outside of $GOROOT that contain the source for Go projects and their binaries. We must set the GOROOT environment variable to point to the directory in which the code was compiled.

We need:

  • GO Compiler
  • To create a directory for the GO Compiler. 

Below is an example of setting an environment variable in GO language.

GO language Example.jpg

Note: In order to use "https" with the Kii cloud, we would need to create and update certificates. This is beyond the scope of this tutorial. 

Gateway Agent

Gateway agent is used to communicate with the Kii cloud. See below. The information for the Kii cloud needs to be entered to the Kii agent configuration file. 

Kii Agent Configuration.jpg

 

Gateway Manager

This application is used to control the gateway agent. Follow the below steps to use the gateway manager application and provide the Kii cloud information. (Kii only provides a sample configuration).

Gateway Manager 1.jpg

Gateway Manager 2.jpg

Translating Bluetooth Information for Kii Cloud:

We need to convert the Bluetooth information or data into a form that we can push it up to the Kii cloud. Since we are using a Bluetooth, BLE beacons are being used that contain information for temperature, humidity, light intensity from the sensors in the environment. This information is stored in the advertising packet of the beacon. We can change it into a suitable format/data by using the PDU payload as shown below.

PDU Payload.jpg

How it Works?

The BLE cloud gateway is setup by following the steps above. Below chart explains the flow of operation.

BLE Gateway Flow Chart.jpg

  • Register Gateway Agent to cloud using Gateway Manager.
  • Perform the scan of BLE devices by hcitool, and acquire each beacon information with the sensor information.
  • Target sensor information is converted for the Kii Gateway Agent.
  • Information is uploaded to the cloud.

Summary

This tutorial just explains one of the application that can be developed using the LB-100AN. Customers are free to develop any other apps for their unique requirements. LB-100AN allows users to focus on developing apps for their unique requirements using a reliable MP-Ready hardware which allows customers to take their product to market quickly. Other developing platforms like raspberry pie for example are only for development purpose and cannot be taken to MP as-is.

Please visit our website, to get more information on the product. You can purchase the product by directly contacting Silex Sales by requesting a quote from the product page.