Proximity-based Bluetooth triggers with Arduino + iOS

This tutorial shows you how to get started with Temboo's support for Arduino + Bluetooth when you're using an iOS device to interact with the Bluetooth shield. We assume that you've read our Bluetooth getting started tutorial, and are looking for specific help with setting up your iOS app.

Get Set up

1First, make sure you've read our Bluetooth getting started tutorial. If you haven't already you should go and do that now.

2Next, download the iOS app from the Choreo page that you're interested in. Make sure that you've entered some inputs and successfully tested out the Choreo first.

3Now, download the Temboo iOS SDK if you don't have it already.

Create the app

4To create your app, open Xcode (we're using version 6.1) and create a new iOS application. Choose the "Single View Application" option.

5Name the project "TembooBLE".

6Next, download the RedBearLab BLE framework. An easy way to get these files is by hitting the "Download ZIP" button on their top-level iOS repository page.

7We'll add the RedBearLab BLE framework folder to our project by right-clicking on your "TembooBLE" folder and selecting "Add files to TembooBLE."

8Now we'll add the files we need from the Temboo iOS SDK. Right-click on the "Supporting Files" folder in Xcode and select "Add files to TembooBLE". Browse to where you saved the Temboo iOS SDK, locate and click on the "core" folder inside the "src" folder. Make sure that "Create groups" is selected, then and select "Add".

9Repeat the above steps to add the .h and .m files for the Choreos you're using, which you can find in the iOS SDK's src/library folder. For example, if you're using a Google Choreo you'd include TMBGoogle.h and TMBGoogle.m.

10Add the Apple Bluetooth, Foundation and the UIKit Frameworks to your project by doing the following:

  1. In the Project Navigator, select TembooBLE at the top of the tree.
  2. Scroll to the bottom of Xcode's middle pane and hit the + icon to add a new Framework to your project
  3. Find the CoreBluetooth.framework and add it to your project
  4. Find the Foundation.framework and add it to your project
  5. Find the UIKit.framework and add it to your project

11Now it's time to add the project files. Delete the "AppDelegate.m", "ViewController.h", "ViewController.m" file from your new project's "TembooBLE" folder, then right-click on that folder, select "Add files to TembooBLE" and add all of the files in the "TembooBLE" directory of the downloaded iOS app. Make sure that "Copy items if needed" is unchecked and "Create groups" is selected, then and select "Add".

12Locate the "TembooTask.h" file, and add an import statement for the UIKit framework.

13 Before running the application, let's take a look at where the signal strength threshold is being set so that you can easily adjust the distance which will trigger the Choreo call. Locate the ViewController.m class. The method bleDidUpdateRSSI is where the signal strength is checked to determine when the Choreo is called.

Run The App

14Connect your iOS device to your computer and make sure that your device has Bluetooth enabled.

15Select your iOS device in Xcode and run the app.

16With the app on your device, make sure that your Arduino board + BLE shield are set up and running the Temboo BLE sketch that you downloaded earlier.

17With the app open on your iOS device, move it close to your Arduino board + BLE shield. The proximity reading should cross the threshold and your Choreo will be triggered on the Temboo platform!

18The result object of the Choreo is returned to the choreographyDidFinishExecuting method in TembooTask.m. You can do whatever you want with these results. For example, you could print the outputs to the console:

NSLog(@"%@", [result getResponse]);

19That's it! Once you've got the basis for the app set up, you can use it to can run any Choreo in our Library by replacing TembooTask.m with the iOS Choreo Code and TembooTask.h with the iOS Header generated on our site. Make sure to include the relevant iOS SDK Choreo files in "Supporting Files" too.

What Next?

Now that you know how use Bluetooth and iOS to interact with Temboo, you're ready to create a project that uses auto-generated code from any of our 2000+ Choreos. We'd love to hear about what you make - hey@temboo.com.

Once you've got your code up and running, you're ready to move on and do more. From monitoring your running applications, to moving your generated Temboo code to your preferred development environment and sharing it with colleagues, collaborators and friends - we've got you covered.

Get Live Updates About Your Application

Integrate Temboo with Slack to get up-to-the-second notifications and alerts about your deployed Temboo code.

Commit Code to GitHub

Commit Temboo-generated code directly to GitHub and share with the world. Learn more.

Need Help?

If you ever need help with IoT Mode, now or in the future, please don't hesitate to get in touch.

Email us at support@temboo.com and we'll answer your questions.