Gateway reference implementation

In order to be able to monitor social interactions, the SDT offer an interface to retrieve the logs from the device. In order to accelerate time to market, a reference implementation is provided as C source code. The gateway is tested on a Raspberry Pi using BLUEZ bluetooth stack and gattlib.

Functional Overview

Calling the script of gateway_scan_and_log.c will scan for devices with BLE service UUID D643D847-157F-07A1-E741-6FEF4D79E9C6 advertised. If the UUID advertised is changed make sure to also change #define UUID_FILTER_VALUE in file gateway_scan_and_log.c to reflect the change.

Any devices found will be put into a list and a separate thread will be created for each element to handle the particular device.

Each thread will attempt to connect to a remote SDT, setting the time (through the Current Time Service) of the remote device. The time set is the UTC time sources from the gateway.

Next the device will request the Remote Device Information in order to retrieve the Remote Device Unique ID. The remote Device Unique ID will be used to construct the filename of the log file that will be created for the particular device. The filename is the concatenation of the #define PATH_AND_FILENAME constant and the remote device unique identifier. By default logs are saved on the Desktop.

Then the SDT Gateway will request the logs of all the zones stored on the Flash of the Remote Device. Once all the logs are read, the SDT Gateway will truncate all the folders of the Remote Device freeing up all the space that the logs were taking in the Flash releasing it back to be used for new logs.

Finally, the thread will close the opened file and then release the MUTEX and disconnect allowing other threads to do the same process for other devices.

System Requirements

Hardware Requirements:

  • Raspberry Pi 3 Model B+

Software Requirements:

  • Raspbian Buster

  • BLUEZ version 5.50 or newer.

  • Gattlib Open Source Library.

  • Cmake.

Symbols

From this point onwards whenever the following terms are used they will reflect the meaning given below.

  • gattlib-master - This is the main folder of the unzipped version of the GATTLIB library.

  • client_folder - This is where the Gateway Files will be copied to and it will reflect the name chosen by the client.

Preparing the Environment

In order to run the example, the steps below should be followed.

  • The Gateway software runs on a Raspberry Pi 3 Model B+ running Raspbian Buster. To find more information about Raspbian Buster check the Raspbian Official Downloads Webpage.

  • The Software requires BLUEZ 5.50 version or later. The Raspbian Buster with desktop and recommended software package contains BLUEZ 5.50. If you are using an older version of BLUEZ please make sure to update it to ensure compatibility.

  • Download the open source code of Gattlib library from here.

  • Unzip the downloaded file to the destination of your choice.

  • Open a terminal and execute install and missing dependencies…

    sudo apt install libbluetooth-dev

    sudo apt install libreadline-dev

    sudo apt-get install cmake

  • Navigate to gattlib-master/examples folder

  • Create a new folder and pick a name of your choice. This will from now on be referred to as client_folder.

  • Copy the Gateway files inside it.

  • In gattlib-master now edit file CmakeLists.txt. There find the snippet…

    if(GATTLIB_BUILD_EXAMPLES)

    #Examples

    and add as subdirectory the client_folder.

    add subdirectory(examples/<client_folder>)

  • In the terminal navigate to gattlib-master folder and create a folder named build and enter it.

    mkdir build && cd build

  • Make the Gateway files.

    cmake .. && make

    if Doxygen is not installed add argument -DGATTLIB_BUILD_DOCS=OFF right after cmake. The command should look like:

    cmake  -DGATTLIB_BUILD_DOCS=OFF .. && make

  • Optional Step: To be able to call the program from any directory in terminal, navigate to /home/pi folder and use a text editor to modify .profile by adding the following line at the end of the file…

    PATH="${PATH:+${PATH}:} ~/<path-to-gattlib-master>/build/examples/<client_folder>"

    … replacing with the path to folder gattlib-master and client_folder with the name of client_folder.

    Note: This will only take effect after restarting the system.

Usage

If the Optional Step was finished then type in the terminal…

> gtw_scan_and_log

else from the terminal navigate to gattlib-master/build/examples/client_folder and then type in the terminal the command above.