Use the BBM Enterprise SDK to Interface with Your Custom Hardware

Enterprise Solutions

Let’s begin by taking a look at Rachel: a (fictional) young professional who lives in our remarkably connected world. Her day begins with a fresh cup of coffee from her IoT brewing machine, which she enjoys as her mattress uploads her sleeping patterns to the cloud from the night before. Her car knows exactly what time she needs to leave to make it to work at 9:00 AM but picks her up 5 minutes earlier today since highway traffic is heavier than normal. When Rachel arrives at the hospital to do rounds, her patient’s Emergency Medical Records (EMRs) are seamlessly loaded onto her tablet. Thanks to the connected pulse oximetry machines at the hospital, she is also alerted that Mr. Anderson in room 1808 has been experiencing low SpO2 levels since last night.

The information collected and distributed by the connected devices in Rachel’s day could wreak havoc on her life if they were to ever be intercepted and fall into the wrong hands. Privacy is of the upmost importance in the digital era, which is why securely transferring data between peripheral devices and access points is crucial. BlackBerry’s BBM Enterprise SDK was built from the ground up to do just that.

Getting Started Interfacing with Your Custom Hardware

While the BBM Enterprise SDK is capable of securely transferring copious amounts of data at outstanding speeds, the project discussed in this blog will get you up and running sending small packets of data with a simple colour picker application. The app will allow you to authenticate your iOS device using Google Sign In, then to select a colour that will be sent to a Raspberry Pi and displayed on an RGB LED.

This sample will get you off the ground and ready to implement the BBM-E SDK with your own IoT devices, providing you with the secure data transfer service you need.

Requirements

For this project to run, you will need the following components (or similar):

  • iOS device
  • Raspberry Pi 3 running Raspbian OS
  • RGB LED (common cathode LED used in sample)
  • 220Ω 1/4W resistor (x3)
  • Solderless breadboard
  • GPIO breakout board or female-male jumper wires
  • Male-male jumper wires

Begin by configuring your hardware for this sample. Your Raspberry Pi should be configured as shown in the diagram below; GPIO pin 17, 27 and 22 should be connected to the RGB LED’s red, green and blue leads, respectively, through a 220Ω resistor. The common cathode of the LED is then connected to ground (-).

This image was created with Fritzing (https://github.com/fritzing/fritzing-app) and is licensed under CC-BY-SA 3.0 (https://creativecommons.org/licenses/by-sa/3.0/)

Once your hardware is configured, it’s time to configure the backend services to work with your project.

Configuring Your Project with BlackBerry and Google

We will be using Google’s Sign-In API for this sample, however you can use any OAuth provider with BBM-E. Begin by heading to your Firebase Console and doing the following:

  1. Select ‘Add a New Project’.
  2. Select “Add Firebase to Your Web App” and make note of the firebaseConfig parameters that you are prompted with.
  3. Close the pop up and then select “Add Firebase to Your iOS App”.

Once you have done so, open up Google’s API Console and do the following:

  1. Select the project you just created in Firebase from the drop down.
  2. The BBM-E SDK requires that you include the Google+ API, which you can do by pressing ‘Enable APIs and Services’, searching “Google+ API” and enabling it for this project.
  3. Your next step is to create the required OAuth credentials and enter it in your application under your organisation here. Begin by selecting “Credentials” in the left tab of your Google API Console, and finding the OAuth 2.0 Client IDs for the Web and iOS clients at the bottom of the page.
  4. In My Organization Account, paste the Keys for the Web and iOS clients under OAuth Client IDs in the application you wish to work with for this project.

Your project is now configured with BlackBerry and Google; it’s time to dive into some coding.

Running the Node.js Sample on Your Raspberry Pi

In order for your Pi to use the BBM-E SDK, you will need to ensure that the latest version of node and npm are installed on your machine. Do this by running the following commands on the terminal:

$ sudo apt-get update

$ sudo apt-get dist-upgrade

$ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -

$ sudo apt-get install -y nodejs

To verify the version of node and npm installed, run the following commands:

$ node -v

$ npm -v

Note that this sample was built using Node version 9.5.0 and npm version 5.6.0. If you have installed an earlier version of either, it is recommended that you update before continuing.

Now that node and npm are installed, you will want to download and unzip the Node.js BBM-E SDK on your Raspberry Pi which can be found here. Rename the unzipped SDK to “bbm-enterprise”. Next head over to this repository and download the Node.js sample files for this project.

The sample project requires you to install a handful of third party libraries to successfully authenticate the user and interface with the Pi’s GPIOs. To do so, run the following commands in the project directory:

$ npm install

After the third party libraries have successfully installed, you will need to install the BBM-E SDK for your project to use. Navigate to the unzipped SDK that you previously renamed “bbm-enterprise” and copy it. Next, head over to the node_modules folder in your project directory and paste in the SDK. The final step is to run the following npm command to start instillation:

$ npm install <PATH_TO_UNZIPPED_SDK> --production

It is important to note that the PATH_TO_UNZIPPED_SDK is not the path to the SDK you just pasted in node_modules; it is the path to the original instance of the SDK that you previously copied. If you left the SDK in your downloads folder, you will set the path to  /home/pi/Downloads/bbm-enterprise.

After installation is complete, we will want to configure this sample to use the OAuth Client and Firebase project that we set up earlier. Heading back to your Firebase Console, copy the contents of the config object you are presented with when you select “Add Firebase to Your Web App” and paste them in the firebaseConfig object of the project’s config.js file. Then, head back to your Google API Console open the Web client details under OAuth 2.0 Client IDs. Copy the Client ID and Client Secret, pasting them in under the ‘client_id’ and ‘client_secret’ properties, respectively, in config.js. The final step is adding the BlackBerry Domain to your config.js file; open up My Organization’s Account and navigate to application you are using for this project. Select the application’s Domain under Summary, and paste it under the ‘id_provider_domain’ property of the config.js file.

Your Node.js sample is now setup to run. Navigate to the project directory in your terminal and run the following command to start your project:

$ sudo node BBMColourPicker.js

Your RGB LED should illuminate green and you should be prompted to log in with Google. Once you do so, you will see the following lines on your terminal:

Your peripheral device Reg ID is: 897689437282941152

Copy this value and paste it in your iOS applications PERIPHERAL_REG_ID parameter in the ConfigSettings.h file.

Make note of the Reg ID printed in your console; this is required for the next step of this walk through.

Running the iOS Colour Picker App

The final component of this project is running the Colour Picker Application on your iOS device. Begin by downloading the sample code from this repository, and the BBM-E SDK for iOS here. Next, install the required pods for the project by navigating to your project directory in terminal and running the following command:

$ pod install

Once the pods are finished installing, add the SDK to your project by opening the SDK package you downloaded, copying the ‘sdk’ and ‘sdk-release’ folders and pasting them in your project directory. Your project makes use of the support libraries included in the examples directory of the SDK package; copy this folder and also paste it in your project directory.

Before you can run the iOS sample app, you will need to configure it to use the OAuth Client, Firebase project and Reg ID that we set up earlier. Open the .xcworkspace and then open ConfigSettings.h. Begin by filling in the SDK_SERVICE_DOMAIN property by pasting in the BlackBerry Domain you found for the Raspberry Pi on your My Organization Account. You will also be able to fill in the PERIPHERAL_REG_ID property from the console print out when you ran your Node.js project for the first time. Finally, head back to your Google API Console and copy the Key for your iOS Client; paste this under the GOOGLE_SIGNIN_CLIENTID property in ConfigSettings.h to finish setting up your iOS application.

Running the Sample

Now that the Node.js and iOS samples are configured, go ahead and run the iOS sample code on your device. Press the Google sign in button, and when prompted, make sure you sign in with a different Google account than the one you are currently signed in with on the Raspberry Pi. Once signed in, press “Pick a new Colour” and move the cursor around the colour wheel; watch as the colour of the RGB LED changes accordingly!

Next Steps

Congratulations! You have successfully interfaced with a hardware device securely using the BBM-E SDK. Now that you’ve got your feet wet with hardware, why not dive in deeper? Use this sample project as a starting point to interface with more complex hardware setups. Attach a heart rate monitor, RFID reader, IR camera or your own Rube Goldberg machine; the possibilities are literally endless. You can check out more samples built with the BBM-E SDK here, and learn more about getting started with the SDK here.  Happy experimenting and remember: just because it’s HARDware doesn’t mean it’s hard!

About Connor Holowachuk

Connor Holowachuk is a Enterprise Solutions Development Student at BlackBerry.

Join the conversation

Show comments Hide comments
+ -