{"id":1511,"date":"2015-06-07T00:29:15","date_gmt":"2015-06-07T06:29:15","guid":{"rendered":"http:\/\/dev.iachieved.it\/iachievedit\/?p=1511"},"modified":"2020-09-06T09:54:26","modified_gmt":"2020-09-06T14:54:26","slug":"getting-started-with-ibeacon","status":"publish","type":"post","link":"https:\/\/dev.iachieved.it\/iachievedit\/getting-started-with-ibeacon\/","title":{"rendered":"Getting Started with iBeacon"},"content":{"rendered":"<p><b>Editor&#8217;s Note:<\/b>  This is Part One in a series of articles on creating a Swift <a href=\"http:\/\/en.wikipedia.org\/wiki\/IBeacon\">iBeacon<\/a> application.  By the end of the <i>series<\/i> you will have written a &#8220;game&#8221; in Swift called <i>You&#8217;re Getting Warmer!<\/i> which allows you to track down and find a beacon.  Part One gets you up and running iBeacon with a Gimbal Proximity Beacon Series 10.<\/p>\n<p>To get started with iBeacon you&#8217;re going to need some iBeacon-compliant Bluetooth Low Energy devices.  The immediate question is &#8220;What does it mean to be iBeacon-compliant?&#8221; Simply put, Apple has specified a Proximity Beacon Specification for Bluetooth Low Energy that advertises three pieces of information in a single packet:<\/p>\n<ul>\n<li>a UUID\n<li>a major version number\n<li>a minor version number\n<\/ul>\n<p>And that&#8217;s it.  Seriously, that&#8217;s <i>all<\/i> an iBeacon does, broadcasts its identifier into the ether.  Think of it as an AM radio station stuck on a <i>taking a pause for station identification<\/i> loop.<\/p>\n<p>As simple as the beacon specification is, all sorts of applications are possible with it.  The most commonly cited application is <a href=\"http:\/\/www.bloomberg.com\/bw\/articles\/2014-08-28\/apples-ibeacon-retail-stores-make-little-use-of-it-so-far\">targeted retail<\/a>, though as the article makes clear, consumers haven&#8217;t actually embraced the idea of shopping while being bombarded with advertisements and offers through apps.<\/p>\n<p>Regardless, iBeacon remains an interesting technology to work with, and in this tutorial we&#8217;re going to order up some beacons and track them in our iOS Swift application.<\/p>\n<h3>Get Some Beacons<\/h3>\n<p>This tutorial will utilize the <a href=\"https:\/\/store.gimbal.com\/collections\/beacons\/products\/s10\">Gimbal Proximity Beacon Series 10<\/a> beacons.  Order some up, wait a few a days (or a day if you pay for it), and you&#8217;ll get one of these in the mail:<\/p>\n<p><center><a href=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/06\/FullSizeRender-51.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/06\/FullSizeRender-51.jpg\" alt=\"FullSizeRender 5\" width=\"236\" height=\"240\" class=\"alignnone size-full wp-image-1513\" \/><\/a><\/center><\/p>\n<p>If you&#8217;re like me you were <i>dying<\/i> to open it and get it working.  But there&#8217;s a few steps you&#8217;ll need to do first, starting with creating a developer account at <a href=\"http:\/\/gimbal.com\">Gimbal.com<\/a>.<\/p>\n<h3>Gimbal Developer Account<\/h3>\n<p>Browse to the <a href=\"https:\/\/manager.gimbal.com\/login\/users\/sign_in\">Gimbal Manager Sign In<\/a> page and click <b>Register<\/b>.  Fill out the required fields, check the <b>I accept<\/b> checkbox to accept the Gimbal Developer Agreement, and then click <b>Sign Up<\/b>.  You will be sent an e-mail to confirm your registration.  Click <b>Confirm my account<\/b> in the e-mail.<\/p>\n<p>Once your account is confirmed you will be directed to the <b>Gimbal Manager<\/b> portal.  It is here in the portal where you can <i>activate<\/i> a new beacon, as well as create <b>Beacon Configurations<\/b>.<\/p>\n<h3>All Beacons are not iBeacons<\/h3>\n<p>It should noted here that while all mammals are animals, not all animals are mammals.  The same is to be said about iBeacons:  all iBeacons are beacons, but not all beacons are iBeacons.  In fact, the Gimbal Proximity Beacon Series 10 beacons you received <i>are not<\/i> configured as iBeacons at the factory, but rather as <b>Series 10 Presence<\/b>.   Before we can make use of the <code>CLLocationManager<\/code> beacon API we will need to reconfigure our Gimbal as an iBeacon.  Here&#8217;s how we do that.<\/p>\n<p>Step 1.  Download the <a href=\"https:\/\/itunes.apple.com\/app\/id785688563\">Gimbal Beacon Manager<\/a> application on your iPhone.<\/p>\n<p>Allow <b>Beacon Manager<\/b> to access your location in order to see your Gimbal Beacons.<\/p>\n<p>Press <b>Get Started<\/b> and Accept the <b>Terms of Service<\/b> and <b>Privacy Policy<\/b>.<\/p>\n<p>When you get to the Sign In screen enter your email and password used to register with the developer portal.<\/p>\n<p><center><a href=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/06\/IMG_4722.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/06\/IMG_4722.jpg\" alt=\"IMG_4722\" width=\"270\" height=\"480\" class=\"aligncenter size-full wp-image-1539\" \/><\/a><\/center><\/p>\n<p>Once you are logged in you will see <b>My Beacons<\/b> with a note that &#8220;we don&#8217;t see any of your beacons nearby.&#8221;<\/p>\n<p><center><a href=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/06\/IMG_4723.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/06\/IMG_4723.jpg\" alt=\"IMG_4723\" width=\"270\" height=\"480\" class=\"aligncenter size-full wp-image-1541\" \/><\/a><\/center><\/p>\n<p>Now, let&#8217;s set one up as an iBeacon.<\/p>\n<p>Step 2.  Obtain a UUID<\/p>\n<p>Recall that iBeacons broadcast a UUID.  You can obtain one <a href=\"http:\/\/dev.iachieved.it\/uuid.html\">here<\/a>.  Copy the UUID generated because you are going to use it in the <b>Gimbal Manager<\/b> <i>as well as<\/i> your iPhone app.<\/p>\n<p>Step 3.  Create an iBeacon configuration in the <a href=\"https:\/\/manager.gimbal.com\/\">Gimbal Manager<\/a> by clicking the <b>Beacon Configurations<\/b> menu option.<\/p>\n<p><center><a href=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/06\/beacon_configurations.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/06\/beacon_configurations.png\" alt=\"beacon_configurations\" width=\"570\" height=\"285\" class=\"alignnone size-full wp-image-1524\" \/><\/a><\/center><\/p>\n<p>In the upper-right corner of the <b>Beacon Configurations<\/b> page click <b>New Configuration<\/b>.<\/p>\n<p>We&#8217;ll name our configuration <b>iBeacon Demo<\/b>, set the <b>Beacon type<\/b> to <b>iBeacon<\/b>, provide our UUID (obtained in Step 2), and set our <b>Major<\/b> and <b>Minor<\/b> version numbers.  Click <b>Create Configuration<\/b> when done.<\/p>\n<p><a href=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/06\/ibeacon_configuration.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/06\/ibeacon_configuration.png\" alt=\"ibeacon_configuration\" width=\"959\" height=\"448\" class=\"alignnone size-full wp-image-1522\" \/><\/a><\/p>\n<p>Step 4.  Activate our beacon.<\/p>\n<p>Now to the fun part, activating our beacon!  If you recall, our Gimbal beacon was delivered to us with a tab marked <b>OPEN DEVICE TO REMOVE TAB<\/b>.  Now its time to open it.  I have found that a United States penny is useful here.  Take the penny and insert it into the notch at the bottom of the beacon like so:<\/p>\n<p><center><a href=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/06\/penny.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/06\/penny.jpg\" alt=\"penny\" width=\"214\" height=\"240\" class=\"alignnone size-full wp-image-1525\" \/><\/a><\/center><\/p>\n<p>Holding the sides of the beacon twist the penny clockwise and you should hear a hearty snap and the top cover pop off.  Place the negative side of the battery into the battery holder and make note of the 9-character alphanumeric code.  This is referred to as the <b>Factory ID<\/b>.<\/p>\n<p><center><a href=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/06\/button_code.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/06\/button_code.png\" alt=\"button_code\" width=\"244\" height=\"185\" class=\"alignnone size-full wp-image-1526\" \/><\/a><\/center><\/p>\n<p>Don&#8217;t put the cover back on yet (you&#8217;ll be tempted to I know).<\/p>\n<p>To activate the beacon go to the <b>Beacons<\/b> page in the <b>Gimbal Manager<\/b> and click <b>Activate Beacon<\/b> in the upper-right hand corner.  Fill out the beacon information, uncheck <b>Create Place<\/b> (we won&#8217;t be using this feature) and click <b>Activate Beacon<\/b>.<\/p>\n<p>The <b>Factory ID<\/b> is the 9-character alphanumeric code printed on the label inside the beacon.  You can omit the dash when entering the <b>Factory ID<\/b> if you like.<\/p>\n<p><a href=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/06\/beacon_config.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/06\/beacon_config.png\" alt=\"beacon_config\" width=\"955\" height=\"294\" class=\"alignnone size-full wp-image-1528\" \/><\/a><\/p>\n<p>Your beacon is now activated!<\/p>\n<p>Step 5.  Configure our beacon.<\/p>\n<p>Okay, it&#8217;s clear from Step 4 that activating a beacon doesn&#8217;t mean that the beacon is broadcasting anything.  In fact, it might as well have been called <i>register beacon<\/i>, because that&#8217;s really what you are doing, registering your ownership of a valid Gimbal beacon.  To configure the beacon we need to turn to the <b>Beacon Manager<\/b> iPhone application.  Why?  Because your iPhone can communicate with the beacon via BTLE, query its information, upgrade its firmware, and upload all of this information to the <b>Gimbal Manager<\/b> portal in the cloud.<\/p>\n<p>Notice how in the <b>Gimbal Manager<\/b> our beacon is reporting &#8220;Unknown&#8221; as the battery level.  Of course it does; our beacon has never reported in via the <b>Beacon Manager<\/b> iPhone app.<\/p>\n<p>However, for the <b>Beacon Manager<\/b> application to know what configuration to update the beacon with, it must obtain that information from the <b>Gimbal Manager<\/b> portal.<\/p>\n<p>Step 5a.  Assign a Configuration in <b>Gimbal Manager<\/b><\/p>\n<p>In the <b>Beacons<\/b> page in <b>Gimbal Manager<\/b>, select the beacon you just activated, and then click on the disclosure triangle on the <b>Configuration<\/b> bar.<\/p>\n<p><center><a href=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/06\/open_configuration.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/06\/open_configuration.png\" alt=\"open_configuration\" width=\"630\" height=\"534\" class=\"alignnone size-full wp-image-1520\" \/><\/a><\/center><\/p>\n<p>Set the <b>Assigned Configuration<\/b> to <b>iBeacon Demo<\/b>.<\/p>\n<p>Scroll to the bottom of the page and click <b>Save<\/b>.<\/p>\n<p>Step 5b.  Configure the beacon in <b>Beacon Manager<\/b>.<\/p>\n<p>On your iPhone open the <b>Beacon Manager<\/b> app and select <b>Configure<\/b> from the menu.  Note that it says <i>Scanning for beacons<\/i> and hints that in order to configure a beacon you need to effectively reboot it.  <i>This<\/i> is why we didn&#8217;t bothering popping the cover back on earlier!<\/p>\n<p><center><a href=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/06\/IMG_4727.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/06\/IMG_4727.jpg\" alt=\"IMG_4727\" width=\"270\" height=\"480\" class=\"aligncenter size-full wp-image-1547\" \/><\/a><\/center><\/p>\n<p><b>Now<\/b> you can place the cover back on the Gimbal beacon!  Once the cover is on you will see the <b>Beacon Manager<\/b> update to something like this:<\/p>\n<p><center><a href=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/06\/beaconfound.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2015\/06\/beaconfound.png\" alt=\"beaconfound\" width=\"270\" height=\"480\" class=\"aligncenter size-full wp-image-1548\" \/><\/a><\/center><\/p>\n<p>Press <b>Update Beacon<\/b>.  The <b>Beacon Manager<\/b> app will use BTLE to update your beacon to the configuration you created in the <b>Gimbal Manager<\/b> application.<\/p>\n<p>Once the update is complete you&#8217;ll be ready for some <code>CLLocationManager<\/code> coding!<\/p>\n<h3>Next Up<\/h3>\n<p>In Part Two of this series we will write a iOS Swift application that listens for and displays details about our newly created iBeacon.  Stay tuned!<\/p>\n<h3>Postscript<\/h3>\n<p>As you&#8217;ve walked through this tutorial and worked in the <b>Gimbal Manager<\/b> portal, you undoubtedly came across the Gimbal <a href=\"https:\/\/gimbal.com\/doc\/proximity_overview.html\">Proximity<\/a> SDK.  The first question you might ask is, &#8220;Why is there an iOS SDK for Gimbal when iOS already supports iBeacon?&#8221;<\/p>\n<p>Like we said above, all beacons are not necessarily iBeacons.  <b>Proximity<\/b> is a <i>different<\/i> beacon technology from iBeacon, and to enable integration into iOS and Android, Gimbal provides SDKs for the two platforms.  With iOS we know that <code>CLLocationManager<\/code> supports receiving updates from iBeacon-compliant beacons, whereas with <b>Proximity<\/b> we would have to use the Gimbal SDK.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Editor&#8217;s Note: This is Part One in a series of articles on creating a Swift iBeacon application. By the end of the series you will have written a &#8220;game&#8221; in Swift called You&#8217;re Getting Warmer! which allows you to track down and find a beacon. Part One gets you up and running iBeacon with a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-1511","post","type-post","status-publish","format-standard","hentry","category-ibeacon"],"_links":{"self":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts\/1511"}],"collection":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/comments?post=1511"}],"version-history":[{"count":31,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts\/1511\/revisions"}],"predecessor-version":[{"id":4180,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts\/1511\/revisions\/4180"}],"wp:attachment":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/media?parent=1511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/categories?post=1511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/tags?post=1511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}