Epic Intro Music: BLE Beacons and Ruby
This is a modal window.
The media could not be loaded, either because the server or network failed or because the format is not supported.
Formal Metadata
Title |
| |
Title of Series | ||
Number of Parts | 65 | |
Author | ||
License | CC Attribution - ShareAlike 3.0 Unported: You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this | |
Identifiers | 10.5446/37602 (DOI) | |
Publisher | ||
Release Date | ||
Language | ||
Producer |
Content Metadata
Subject Area | ||
Genre | ||
Abstract |
|
Ruby Conference 201449 / 65
2
3
4
6
9
11
14
17
18
19
20
25
27
29
30
32
34
35
39
40
46
47
50
53
55
56
58
61
63
00:00
Computer animation
00:40
Keyboard shortcutComputer animationXML
01:02
Keyboard shortcutFocus (optics)Cellular automatonRadiusUniform resource locatorProduct (business)Process (computing)SoftwareDistanceService (economics)Computer animationMeeting/Interview
01:24
Computer networkRadiusOffice suiteDistanceComputer hardwareService (economics)Product (business)Uniform resource locatorOffice suiteNumberMusical ensembleSpacetimeComputer animation
02:14
Office suiteMobile WebFood energyType theoryAxiom of choiceNeuroinformatikNumberAxiom of choiceOffice suitePhysical systemMusical ensembleDifferent (Kate Ryan album)Type theoryPoint (geometry)Mobile WebRepresentation (politics)Term (mathematics)DatabasePrisoner's dilemmaIdentifiabilityMultiplication signKey (cryptography)Food energyMobile appArmBit rateComputer animation
05:24
BitCategory of beingWordAuthorizationoutput
05:48
FreewareCategory of beingDifferent (Kate Ryan album)Computer hardwareNumberBitMechanism designLatent heatProgram flowchart
06:32
Online helpQuicksortComputer animation
06:55
Curve fittingWhiteboardMereologyServer (computing)QuicksortFront and back endsComputer animation
07:18
Server (computing)Musical ensembleIdentifiabilityOperating systemPoint (geometry)Broadcasting (networking)Mobile appComputer animation
08:02
Fitness functionAbstractionDemo (music)CuboidPhysical systemPiComputer animation
08:38
Musical ensemblePower (physics)Physical systemComputer animation
09:18
Physical systemBroadcasting (networking)Generic programmingEndliche ModelltheorieComputer animation
09:43
Broadcasting (networking)IdentifiabilityFirmwareBroadcasting (networking)Office suiteMusical ensembleEvent horizonPhysical systemPower (physics)Mobile appArm
10:57
Musical ensemblePhysical systemBroadcasting (networking)Mobile appGreatest elementMP3MathematicsNumberServer (computing)Event horizonArmInternetworkingMultiplication signSocket-SchnittstelleComputer animation
11:51
InternetworkingSoftwareServer (computing)InternetworkingEvent horizonFirewall (computing)Socket-SchnittstelleArmElectronic visual displayOffice suiteComputer animation
12:17
InternetworkingWeb 2.0Projective plane
12:39
Event horizonDependent and independent variablesComputer wormServer (computing)outputMobile appPhysical systemEvent horizonOrder (biology)System callServer (computing)Line (geometry)Core dumpHookingMultiplication signQuicksortUniform resource locatorCodeLibrary (computing)Connectivity (graph theory)Operating system
14:50
Physical systemEvent horizonCircleMusical ensemblePrototypeMereologyArmComputer animation
15:30
PrototypeArithmetic meanComputer animation
16:00
Content (media)Content (media)IdentifiabilityEvent horizonArmDistanceDemo (music)EstimatorGroup actionGodBroadcasting (networking)InformationComputer animation
18:00
Broadcasting (networking)DistanceAverageTheory of relativityHydraulic jumpMetreEstimatorFigurate numberGroup actionDemo (music)CASE <Informatik>Right angle2 (number)Computing platformLine (geometry)Default (computer science)Power (physics)Multiplication signGame controllerProcess (computing)Computer animation
21:05
Core dumpLibrary (computing)Uniform resource locatorMobile appCAN busComputing platformOpen sourceImplementationAndroid (robot)Disk read-and-write headComputer animation
22:08
TrailMobile appMassEvent horizonQuicksortPhysical systemMusical ensembleTrailLocal ringOffice suiteLattice (order)Computer animation
24:18
Computer networkRadiusSoftwareEvent horizonVideoconferencingComputer animation
Transcript: English(auto-generated)
01:02
Hi, I'm Christopher. I have no keyboard focus. It's very annoying. I like to build things. This particular thing I built mostly out of cardboard, but we also used an Arduino to make the light on the top of the TARDIS work. That was a lot of fun. And I work
01:24
for a company called Radius Networks. We build products around proximity and location, and one of the things that we do a lot with is beacons. We actually build and sell the hardware devices as well as a bunch of services that kind of go on top of it.
01:41
And this is our office. It's the powerhouse in DC, one of two locations where you don't have to give a street or number in DC if you want to send a letter to it. It's really cool. It is like a hundred-year-old renovated powerhouse kind of turned into an office space. And we all work on a mezzanine, and the doors to come
02:02
in are down low on the main floor where everyone will walk in. And as they come in, then you stomp up these loud metal stairs. But you don't know who's coming in, which made us wonder, well, we're a proximity company. We can figure this out. Wouldn't it be really cool if some music would just magically play when somebody
02:22
walks into the office? And so we, of course, started talking about, like, cool, what would we play when the CEO walks into the office and comes up the stairs?
02:46
And the same thing when we talk about the chief financial officer, what's he going to do when he walks up carrying all his ledgers and things that he carries? That was pretty obvious.
03:04
And then I was faced with a real dilemma, which was, what am I going to play when I walk in? And I thought about it for a long time, and then it seemed just so blatantly obvious.
03:25
I was very happy that I had the first slot talking because I thought I'd be the very first person at this RubyConf to Rick Roll You. Okay, so we have this thing. Let's build it. What do we need? We're going to need three different things. First, we're going to need speakers, some way to actually play the music
03:44
connected to a small computer. We're going to need a mobile app, so something on your phone. Luckily, you always carry your phone with you, so this is a good representation of where you are. And then we're going to need a beacon. And you probably already know about computers
04:01
and mobile phones, but I don't know if everyone's familiar with what exactly is a beacon. So there's a couple of different things that could be a beacon. The one I'm talking about today are the Bluetooth Low Energy beacons, or the BLE beacons, or the Bluetooth Smart, or the Bluetooth 4.0, which are all the same thing. They're just marketing terms that the
04:22
Bluetooth SIG has come up with to talk about these things. I think most people tend to have settled on Bluetooth Low Energy at this point. And what exactly are one of these beacons? It's kind of like a PA system. It just makes announcements over and over, and it ignores everything else.
04:41
That means that you don't connect to it. It doesn't know if you've heard it. It doesn't know pretty much anything. It's just sending out the same thing over and over again. And what it's sending out is just identifiers. This is nothing complicated. It looks something like this, which is just a big UUID and plus a couple other numbers.
05:01
And that's kind of all that it has. And you can use these identifiers as like a foreign key, like you would in a database, or something to do a lookup to figure out what it means when you see that beacon. So there's a couple of different types of beacons, and choices are good, right? It's never bad to have too many players, too many cooks in the kitchen.
05:25
The obvious one is iBeacon. So this is a spec by Apple. And whenever I talk about beacons, I almost always mean this, and I kind of use the word beacon synonymous with a beacon with iBeacon technology, which is the way you're supposed to say it. This came out with iOS 7.
05:44
They introduced it, and it works really good on iOS, but the iBeacon spec isn't completely free of proprietary intellectual property. So there's this thing called alt-beacon. And to be completely honest, this is a little bit of a shameless plug, because
06:04
my company authored that spec. And it's also a little different than some of the other specifications that are out there, because it was written with the idea of interoperability, and it's supposed to work one-to-one with iBeacons. And in fact, we have a number of
06:23
hardware devices that do both, and you wouldn't notice the difference between the two. It's just kind of a mechanism that we're using. And then finally, there are other proprietary beacons. These can do some really cool stuff, include other sensors. You might notice on Kickstarter,
06:41
these sorts of things will come around that help you find your lost bike or have an accelerometer or temperature sensor and can do other cool things. But these are outside of the scope of what I'm talking about, which are the simple BLE beacons. So cool. We kind of know the different parts we're going to need. Let's kind of whiteboard
07:06
and walk through exactly what we would do to make all of this work. So first, we're going to need a beacon. We'll set that up. We'll need a mobile device, some sort of Ruby backend server, and then the thing that's actually going to play the audio.
07:29
And what happens first is the beacon will broadcast out its identifiers, and it just shouts these out, not knowing anything around it, sending those, and the phone is going to
07:41
notice that. So the operating system on the phone will wake up the app and tell it that I've seen this beacon. That app can now post off to the server, which will in turn tell whatever needs to play the music, that it should go ahead and play the music. And this is, of course,
08:01
the point where the epic music actually plays. So cool. So what exactly are all these kind of abstract, weird drawings? So if we're going to build it, how does this fit all together? And what I do is, for the demo for this talk, I built it all together. So everything in the
08:26
box all runs on a Raspberry Pi, and it's all sitting there together. And then we have the phone kind of as a separate system, and these are the two things that need to interact together. And this is the actual system that I built. I brought it along.
08:43
So you can see we have Raspberry Pi. It's got a little Bluetooth nub plugged in. I had some speakers. The USB hub, it was only for power. And you'll notice that there's a network cable because it needed to be connected because that was the only way that we could actually tell
09:03
the Pi to play anything, since the beacon that's sticking out here would only broadcast out. It wasn't receiving anything back. So we have this epic music system running
09:23
on a Raspberry Pi. There's a few things that we needed to do for us. One is broadcast as a beacon. So if you're just using a Bluetooth, just a generic Bluetooth module, you can still have it broadcast as a beacon. And luckily, the command line that you need to run
09:46
is pretty intuitive. So you can do that. It's using the BlueZStack, which is kind of the drivers for Linux for Bluetooth. And we use something called HCI tool, and you can basically
10:01
just command your Bluetooth radio to broadcast something. And I kind of highlighted the different identifiers. So the thing that's kind of in the dark red is the main UUID, and then the other two identifiers are that kind of mustard and dark blue. Or the easy approach
10:22
is to just plug in a Bluetooth-powered beacon. And so it looks almost the exact same thing as a Bluetooth radio, but it has our firmware running on it. And you can just configure it in advance. All it needs is power and it'll broadcast. So that's kind of the cheap, easy way
10:41
that I was able to get it to broadcast as a beacon, or if I wanted to have more... If I want to cover more doors. So if you're walking into the office, we have two doors, and I need beacons at every entrance. So when you walk past them, I'll know that you're there. Okay, so now we need a music player. We have the system broadcasts. We need something
11:05
that's going to listen for events and play the music. And I did it with a Sinatra app, which is very complicated. And you'll see... We'll start at the bottom. It takes a post.
11:21
When the post comes in, it just converts the params. It looks for a param called name. And then what we do is it calls up to the method at the top, which is play. All I'm going to do is shout out to a little command line app called MPEG321, and then I resolve the path and tack on .mp3. So if I want to add more songs for
11:41
other people, I would just add chris.mp3 to the Raspberry Pi, and you can change out whatever song you wanted. Now, since I want it all to run on one device, and I didn't want to have a server and a Raspberry Pi connected somewhere with sockets going and pushing events
12:03
up and down, I wanted to just tunnel out to the internet. And so this was an easy way to kind of have my server run within the firewall that's at my office, connected to that network there. And I just used a tool called ngrok. This thing is amazing. I discovered it while I was
12:24
working on this little project, but it actually gives you introspected tones. So you can see what's going over the wire for the stuff that you've tunneled out. So if you've ever worked with webhooks and other things and you want to test them, just check this out. Okay, so the iOS app. So I have an iPhone, so I decided I wanted to write an iOS app,
12:46
and I used RubyMotion for it because we were talking about it at RubyConf. So this is a little more scary. This is how you tell the core location APIs to listen for a beacon.
13:04
And there's a couple of things. Like I say, look for any beacons with a specific UUID, and then tell me about it in any possible time that you can. And so I would set this up. When I first launched the app, I set up all these things and I register with the operating
13:22
system. Please tell me about these beacons. And then I need to implement some sort of a callback. So I have a method that's just something, a delegate to core location. But all that means is that when the core location system sees something happening, it's going to
13:42
notice that and call back to my app and let me know. What's really cool about this and what was novel about when Apple introduced iBeacons was that this happens even if my app is in the background. And it also happens even if you went through and explicitly
14:02
terminated the app, the phone is locked and in your pocket, all these sorts of things. It gives you an extra little hook, that event that you need to make something happen that you just didn't have before. And then once we do all that, we are going to post it up to the server. On RubyMotion, I used a library called bubble wrap, which if you've done anything
14:26
with RubyMotion, bubble wrap is awesome. Because in order to do this same amount of work of just doing HTTP post in Ruby, we're spoiled by it because you can do it in three lines. But if you were trying to use the APIs, the native APIs, it winds up being something like 30 lines
14:45
of code in order to handle all of that. So cool. Now we have, we basically have a working system. We have the two components, the raspberry pi that's going to be listening to things and the phone that will react to it, take that event and post it back to the raspberry
15:06
pi. So it's kind of a full circle of the events are coming out of the music player, so that the phone can react to being near it. And it posts it back and lets the, it sends it off to the phone, which then turns around and sends it back to
15:24
the actual raspberry pi system. Cool. So we have a working prototype. Let's go over,
15:41
I'd like to talk a little more about how iBeacons work, in particular about some of the misconceptions and the other kind of nuances of working with them, because there's definitely a lot of things when you're working with iBeacons that's not obvious.
16:00
So a couple of main, of the big misconceptions that we see over and over again are, there we go, are that the beacons actually deliver the content. They don't, they just send out identifiers. And I feel like I should just be up here just
16:23
saying that over and over again, because that's something that seems that's hard for people to really ingest. And people tend to actually think that they're getting something off of these little bluetooth devices that they're, you know, they need to get the content and the pictures, or god help us all, more coupons off of these devices. And that doesn't
16:46
work that way at all. The way it works is it sends out those identifiers, and you see those, and then that gives you a chance to react to them, go look up at those identifiers in some
17:00
other place, pull those down onto the phone or to whatever device is actually using them, and take action on it. So it really is just providing you the event and none of the actual data or messaging or content. The other one is that the beacons
17:27
know when they're detected. They don't have a clue. They are just dumb broadcasters, and all they do are announce their identifiers over and over again. The way it works is
17:44
actually using a bluetooth ad packet, and so as it's sending out these advertising packets, it contains a couple of bytes of information. That's it, and sends it out.
18:02
This one's important. We haven't talked about the distance estimate at all in our demo. It was just, if you see the beacon at all, take this action. But one of the things that you can do with the beacon is you can use the RSSI, the relative signal intensity, to figure out approximately, it's very important, approximately
18:27
how far away you are from the beacon. Now, this uses bluetooth. It uses RF, and neither one of these, bluetooth wasn't intended for figuring out how far away you
18:40
are from something, so there are other RF-based things that you can use that are more accurate, but this is great because it's built into my phone by default, and so out the door, I have something in my pocket that can estimate distance. The problem is,
19:00
on your phone, you get back an estimate. You can convert it to meters using the signal strength, and you can configure the devices to have a baseline broadcast power, and what that is is you configure it, you set it up, and you set something exactly one meter away, and you figure out what the signal strength is at that one meter away, and it's all very environmental,
19:24
so if I plugged one in underneath the podium and I wanted to measure one meter in front of it, it would make a difference whether or not this podium was wood or metal and how much of the signal you'll see, and a lot of, we've seen a lot of use cases where folks come in
19:41
and they're like, oh, it'd be great. I want to use beacons. We're going to do something amazing at our cash register, and I need to know when the person is the second person in line, and that's just not going to work because even standing still at one meter away in the lab, like under control, you know, situation, you'll see the distance estimate jump around,
20:03
and you can do things like running averages to kind of figure these things out, but it's not very accurate, and over enough time, you could probably get accurate, but that's not going to work for somebody standing in line at the cash register,
20:20
and the other thing to know is that the accuracy gets less accurate the further away you get, so if you are, you know, immediate, like you want to be within an inch of the beacon, you want to hold your phone right up next to it, and you want to know if whether or not somebody is holding the phone right next to it, that's actually pretty reliable,
20:41
and once you get out to a couple of meters away, it kind of starts to jump around, but when you're at 15, 20 meters away, it'll be all over the place, and sometimes the Bluetooth on the phone will be like, I don't even know what the RSSI is. All right, so one thing to know is that not all the platforms behave the same way.
21:13
A lot of people tend to think that you can set up an app on your iPhone and have it look for
21:20
all the beacons that are out there. You can't. That's not allowed by the core location APIs that might be allowed on other platforms, and you know, it might be allowed on other platforms that are using the Android beacon library, which is another slightly shameless plug.
21:43
Which is a completely open source implementation, re-implementation of kind of how the core location beacon API works, but being on Android, you have a much more open platform for better or worse for exactly what you can do. All right, the other thing, another misconception
22:10
is that the beacons track you. There's been some interesting things in the news where I think in London, they put a bunch of beacons in trash cans, and then people flipped out and
22:21
made them rip them out of the trash cans, and then in New York, they were doing something similar where they had some sort of big fashion show, and somebody made an amazing app that interacted to you wandering around the city, and so they used old phone booths because they didn't want to use pay phones anymore, and they installed a bunch of beacons which could make the apps do interesting things, and of course people flipped out and the mayor announced
22:44
that they were going to have to go and rip all of these things out. That was very frustrating working at a place where we think about this stuff all day long. The beacons aren't tracking you. They're not doing anything. They are giving your phone something that they can trigger
23:01
to make the tracking happen, but there's a lot of other ways to do this. There's nothing kind of inherently bad about how the beacon system works. It's not more invasive, and the thing I like about it is it's completely up to you
23:22
to control whether or not you leave it on or turn it off, and on iOS, it's all opt-in, and so it's a pretty good way of actually using it to engage people. It's really helpful when I want to play music when I walk into the office. That's cool. If I'm going to my
23:43
my local sports ball event and I don't want to hear events or offers to upgrade my seat because seriously, no more coupons, then you can opt out of that sort of thing, and that's I actually really like the way it works, and I get frustrated when you hear
24:03
politicians politicianing and doing their thing and causing some sort of massive backlash and saving the day by having a bunch of phone booths, Bluetooth beacons ripped out.
24:21
Awesome. All right, well, thank you guys very much.