Introduction
This article introduces us to the world of Internet of Things Services through a new service called Buddy Platform. We would learn what is Buddy, how to use Buddy and how Buddy can help us with the IoT projects we are building.
What is Internet of Things?
As we all have known and seen, Internet has helped us connect, communicate, entertain, earn, learn and share. Now the new buzzworld is to put small devices to connect with each other, share information and help us learn or manage our world. This mesh of devices connected with each other over the internet is called the Internet of things.
By having the ability to put the process, people, data and devices together, we have the ability to create the exponential responses to the exceptional challenges the businesses, individuals and countries face today. Hence, the need for Internet of Things has become more relevant than ever.
What are IoT Services?
In our previous articles, we learnt of different devices like Arduino, Netduino and Raspberry Pi and how to put them to work. Now once we have these devices programmed to read sensors or monitor processes, we will need to get the data transmitted from the device to a place where it can be used by us or other devices/processes.
To achieve this data transmission, we could either create our own webservices and interface with them or we can use some of the services called IoT Services that are already out there in the market and use them.
Examples of these services are:
- Amazon webservices with AMZ Kinesis
- Microsoft Azure with Intelligent Systems and Services
- IFTTT – If This Then That
- Buddy Services
- Why do we need IoT Services
With more and more things in our daily life becoming smart or inter connected, we will need a single and simple interface to control/manage most of them at one place. However since each device has a particular problem to solve and is developed by a different developer or a company, each one of these are on their own platforms with their own interfaces.
Due to the resource constraints and lack of expertise, more and more developers are turning towards readymade services that can be used to interface with their devices. This gives them the ability to focus on their products more intensely without having to invest or worry about the infrastructure the device would need.
These services also provide them with the ability/flexibility to scale, secure and perform depending on the usage instantaneously. This also helps avoid unnecessary losses due to investments in infrastructure for products that might not meet the expectations of the market and may need to be pulled back or re-done from ground up.
These services serve the same purpose as above, i.e., provide the infrastructure to Transmit, Host, Secure, use and Analyze the data from the devices as a Service.
In our article today, we shall focus on one of these premium Internet of Things Services platform by name Buddy.
Buddy Platform
What is Buddy?
- Buddy is one of the Backend services that can be used by developers right out of the box. These services are platform agnostic and can be interfaced with any platforms like Android, iOS,, Webapps, Raspberry Pi, Arduino and so on.
- Buddy has APIs that can help us manage the devices that are connected to the services and also users if there are.
- The APIs can push notifications to the mobile applications on Windows, Android or IoS.
- The Buddy platform supports recoding metrics events.
- The data from the apps and devices are sent as Telemetry and stored on the Buddy platform.
- Buddy also supports Deep Analytics which can help us understand our customers better.
- The Business intelligence applications of company could easily be interfaced with the data on Buddy platform.
- Buddy is scalable depending on the devices or applications being connected.
Software Development Kits for Buddy Platform
As we saw earlier, Buddy supports several platforms. The support is provided through the SDKs which are nothing but thin wrappers over the REST service to help take care of the complicated tasks such as request and response management, authentication and so on. Buddy has four SDKs for download as listed below:
- .NET SDK
- iOS SDK
- Android SDK
- JavaScript
.NET SDK
The .NET SDK is used for interfacing with the buddy platform from a .NET application, Windows phone application, Netduino App, Xamarin apps. And the SDK can be installed from the NuGet manager on Visual Studio.
The Software development kit helps us with the below tasks:
- Creating requests for the Buddy RESP API calls
- Managing authentication
- Parsing the received response from the API calls
- Storing and managing credentials
Prerequisites
This release supports development with Visual Studio 2012 & 2013, and supports the following platforms: .NET 4.5, Windows Phone 8.x, Windows 8.x, Xamarin Android, Xamarin iOS.
Below are the steps to install the SDK using the NuGet on the Visual Studio.
- Open Visual Studio
- Create a new project
- Search for Nuget Package manager
- Search for Buddy on the nugget Online search
- Click install
Below is a GIF with the above steps:
Using the .NET SDK
To use the SDK in our .NET code, we will need to initialize the SDK by using the init
method.
The init
method requires the App ID and App Key for your App on the Buddy Platform. Let’s start by creating an App on the platform called CodeProject_Sample
app.
Below are the steps to create a new app and get the App Key and ID from the dashboard.
Now let’s initiate the SDK on our .NET code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BuddySDK;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
Buddy.Init("jdjjjasdj.fGgbvKNcKsFv",
"111112211-5D48-4BFD-A36A-A975D0C34F20");
}
}
}
Register a Device
To register a device on the Buddy platform App, we can use the register device method. This method will register and authenticate the device with the buddy platform app.
Buddy.registerDevice("bbbbbc.fGgbvKNcKsFv",
"FB664210-5D48-4BFD-A36A-A975D0C34F20", function(error, res) {
Buddy.recordMetricEvent("app_started");
Buddy.get("/users", function(error_2, res_2) {
var myUsers = res_2.result;
});
});
var deviceToken = null;
$.ajax( {
type: 'POST',
url: "https://api.buddyplatform.com/devices",
processData: false,
data: JSON.stringify({appId:myAppId, appKey:myAppKey, platform:"REST"}),
headers: {"Content-Type":'application/json'},
success: function(data) {
if (data.success && data.result) {
deviceToken = data.result.accessToken;
}
$.ajax( {
type: 'GET',
url: "https://api.buddyplatform.com/users",
headers: {
"Content-Type":"application/json",
"Authorization" : "Buddy " + deviceToken
},
success: function(data) {
if (data.success && data.result) {
var users = data.result.pageResults;
}
});
});
})
Telemetry
As more and more devices from our everyday world are enabled to connect to the internet, the data that these devices can generate is huge and help in many ways for the businesses. Just a simple example of this is an internet enabled car.
Once a car is sold and is internet enabled, it can send data back to the manufacturer which can be used in many purposes, the data can be anything like below:
- How much is the car being used on a daily basis
- How is the car being maintained
- How is the car performing based on geography, climate, usage and so on
- Which dashboard features are being used most of the times
- Which features are never being used or used very rarely
- How frequently is the car being serviced, and so on
Having this data from our products helps make decisions and changes that will help us provide the best products and service to our customers.
Buddy helps us capture this data by using the Buddy Telemetry.
Configuring Telemetry
Before collecting the data, we will need to let Buddy know a little bit about the data that we would be sending so Buddy would know how to handle the same. This part is called the Configuration of the Telemetry.
The configuration is sent usually once before the data is sent and the configuration can be overwritten any number of times. I prefer sending the config when I initialize the app and after that only send the data. Below is a sample configuration.
{
Car: {
VIN: ‘234324234234324’,
Make: ‘2012’,
Model: ‘XXXX’
},
ssn: '111-11-1111',
name: ‘Mr.XXX YYY’,,
Coutry: ‘USA’,
State: ‘WA’,
City: ‘Seattle’,
GPS: ’12.12 12.12’,
MPG: 23,
}
Buddy.put('/telemetry/carconfig',
{filterKeys:[car.VIN','ssn',’name’],
metrics:{State:' State',City:’ City’, GPS:'GPS', Mileage:’MPG’}});
Once the configuration is complete, we will need to send the actual data as below:
var data = getSomeData();
Buddy.post('/telemetry/myconfig',{data:data});
filterKeys
FilterKeys
is used to exclude customer sensitive data from being stored, in the above example I am filtering out the SSN, the Name and the Vehicle Identification Number [VIN].
Storing and Retrieving Media and Files
Store a picture on Buddy
Just like storing data, we can store a picture on the buddy platform using the APIs. It always wise to limit picture size so that the time to upload and retrieve would be reduced. There are libraries available to resize the image before uploading to buddy platform.
Below is a code snippet we can use on the JavaScript to upload a file from the client side.
var options = {
readPermissions: "User",
writePermissions: "User",
permissions: "App",
data: "{binary picture data}",
location: "22.1, -678.21",
caption: "Sample picture for Codeproject article!",
tag: "samples",
watermark: "CPCPCPCPCP"
};
Buddy.post('/pictures',
options,
function(err, result) {
if(err)
return err;
}
);
Field |
data |
Required? |
Required |
Description |
The file to be uploaded in the Binary format |
|
|
Field |
location |
Required? |
Optional |
Description |
Latitude and longitude of the location, usually the Geolocation of the picture taken |
|
|
Field |
caption |
Required? |
Optional |
Description |
Any text as caption for the picture |
|
|
Field |
tag |
Required? |
Optional |
Description |
String value used as a tag for the picture, usually used to group pictures together |
|
|
Field |
watermark |
Required? |
Optional |
Description |
String value that will be overlayed as watermark by Buddy |
|
|
Field |
readPermissions |
Required? |
Optional |
Description |
Values can be either User or App, meaning either only user who created can view it or the App code can access it as well |
|
|
Field |
writePermissions |
Required? |
Optional |
Description |
Values can be either User or App, meaning either only user who created can modify it or the App code can modify it as well |
|
|
Field |
permissions |
Required? |
Optional |
Description |
Values can be either User or App, meaning either only user who created can view or modify it or the App code can access it and modify it as well |
The same code written for a .NET app would look like below:
BuddyFile data = new BuddyFile(myFile.AsStream(), "My File Name", fileType);
BuddyGeoLocation location = new BuddyGeoLocation(47.1, -122.3);
var options = new {
readPermissions= "User",
writePermissions= "User",
permissions= "App",
data= data_variable,
location= "22.1, -678.21",
caption= "Sample picture for Codeproject article!",
tag= "samples",
watermark= "CPCPCPCPCP"
};
var result = await Buddy.PostAsync<Picture>("/pictures", options);
These are some basic APIs on the service and we shall look more into other APIs through examples in our next article.