Adding Real-world Context with Estimote Beacons and Stickers

James Montemagno

It’s no secret that iBeacons have created a buzz in the development community. Leveraging these Bluetooth Smart devices enables developers to add contextual awareness to their mobile apps with just a few lines of code. iBeacons were everywhere at Evolve 2014, including at the forefront of the Evolve Quest scavenger hunt and the conference mini-hacks, as well as taking the main stage for an in-depth session.

sticker_bikeEstimote, a leader in the iBeacon space, recently introduced Estimote Stickers, a low-powered device to go alongside their traditional beacons. Stickers can be attached to almost anything and turn any everyday item into a “nearable” – a smart object that can transmit data about its location, motion, temperature, and environment to nearby apps and devices. Today, we’re pleased to announce the Estimote SDK for iOS, available on the Xamarin Component Store, enabling developers to easily detect Beacons and Estimote Stickers with a beautiful C# API that includes events and async/await support.

Detecting Nearables

Nearables have a new, simplified API. Each Nearable has a specific NearableType that can be used to detect, for example, Car, Dog, or Bike. You can decide to range for a specific type or all nearby Nearable devices.

Let’s see how easy it is to get up and running with Nearables by scanning for all Nearables that are close by.

Install the Estimote SDK for iOS

The very first task is to set up a new Xamarin.iOS project and add the Estimote SDK for iOS from the component store.

2015-02-19_1313

In addition to the SDK, you must specify NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription in your Info.plst file with a description that will be prompted to your users, since iBeacons use CoreLocation functionality.

Setting Up App ID

When you log in to your Estimote Cloud, you are able to manage all of your Beacons and Stickers in addition to creating API keys for your mobile apps. Once you have an app set up in the Estimote Cloud, you can config the app in your AppDelegate’s OnFinishedLaunching method:

Config.SetupAppID ("<appId from cloud>", "<appToken from cloud>");

While not required, it’s recommended to set up your app ID so that the SDK can now communicate with the Estimote Cloud to pull in unique attributes.

Ranging Nearables

Using the new NearableManager you can easily range for Nearables by subscribing to the RangedNearables event.

NearableManager manager;
public override void ViewDidLoad ()
{
  base.ViewDidLoad ();
  manager = new NearableManager ();
  manager.RangedNearables += (sender, e) => {
    //Nearables detected, load into TableView or pop up alert
    new UIAlertView("Nearables Found", "Just found: " + e.Nearables.Length + " nearables.", null, "OK").Show();
  };

  //Specify the type of Nearable to range for. In this instance return All types.
  manager.StartRanging (NearableType.All);
}

Estimote Nearables Detected

The real power of Nearables is the additional attributes that are received when they are detected, such as their temperature, orientation, acceleration, and more. As an example, you could easily use these attributes to detect a Bike Nearable in motion for over 45 minutes and prompt your user to perhaps take a break.

NearableManager nearableManager;
public override void ViewDidLoad ()
{		
  var identifier = "94064be7a9d7c189"; //Identifier ranged earlier
  var durationThreshold = 45 * 60; //45 minutes

  nearableManager = new NearableManager ();

  nearableManager.RangedNearable += (sender, e) => {
    var bike = e.Nearable;
    if(bike.IsMoving && bike.CurrentMotionStateDuration > durationThreshold) {
      Console.WriteLine("Bike is moving and has been in motion for over 45 minutes!");
    }
  };

  nearableManager.StartRanging(identifier);
}

Triggers and Rules

In addition to ranging and monitoring Nearables, there is an advanced trigger system in the Estimote SDK that enables you to specify several rules that would trigger a notification. Let’s say you want to be notified every time a Nearable changes orientation and is laid down in a horizontal position. You would simply create a OrientationRule and use the TriggerManager to wait for the Nearable’s state to change.

TriggerManager triggerManager;
public override void ViewDidLoad ()
{
  var rule = OrientationRule.OrientationEquals (NearableOrientation.Horizontal, NearableType.Shoe);
  var trigger = new Trigger (new Rule[]{ rule }, "TriggerId");

  triggerManager = new TriggerManager ();
  triggerManager.StartMonitoring (trigger);
  triggerManager.ChangedState += HandleTriggerChangedState;
  triggerManager.ChangedState += (sender, e) => {
    Console.Log("Shoe nearable has been placed horizontal");
  };
}

More complex rules can be configured that are based on DateTime, temperature, proximity, and more.

Enhanced C# Beacon API

Xamarin.iOS has been able to detect iBeacons from any vendor since the feature was introduced in iOS 7 in CoreLocation. However, the Estimote SDK greatly simplifies the tasks of requesting and a simplified API for ranging and monitoring for beacons. In addition, if you are using Estimote Beacons you can tap into advanced features, such as their accelerometer.

0001125_estimote-beacons

Learn More

The Estimote SDK for iOS has plenty of great samples for both Nearables and Beacons for you to start out with, including a full Getting Started Guide. In addition, Estimote has SDK reference documentation and a developer portal with more information.

If you are interested in adding iBeacon functionality to your Xamarin.Android apps, be sure to check the component store for multiple libraries that you can take advantage of.

Discuss this post on the Xamarin Forums.

0 comments

Discussion is closed.

Feedback usabilla icon