Wednesday, October 05, 2016

RubyConf 2015 - Tagging your world with RFID by Adam Walker

is Tagging Your World With RFID
or how to annoy your friends, family and pets.
Which is something I'm a bit of an expert on.
You can find me on Twitter at @ACONTIUS,
you can also follow my live tweet streaming that I have
that has extra information, you know links to
details about RFID tags, that sort of thing, at #RUBYRFID.
So I work in laboratory information management software.
Basically what we do, I personally track vials
and robotic freezers using RFID tags.
It's freaking cool, it's a lot of fun.
The company that I work for JMI Laboratories,
we actually test the antibiotics
and find out which antibiotics are developing,
basically bacterias developing a resistance to.
We've been doing this for 15 years.
We pass the information off to the FDA,
we pass the information off to the European Health Agency
and then of course we help drug companies
develop better antibiotics as a side effect.
Lots of data to sift through, it's a lot of fun.
And while I'm up here I also kind of wanted to
promote Ruby For Good, I'm sure some of you
have already heard about it.
If you haven't, you can visit,
also talk to Sean Marcia or talk to,
to Chris Sexton.
It's basically a weekend hack-a-thon where you're
helping nonprofits and open source.
And we go out and last year we had kittens
'cause we worked with the Humane Society.
This upcoming year there's gonna be red pandas.
We're gonna actually be at the Smithsonian Mason
Research Center in Virginia.
And it should be pretty interesting.
So a couple personal things about me.
I think you'll understand what I'm doing later on
with some of the hardware, if you,
for those that don't know me,
by knowing that I'm a little bit of a weird dude.
I tired to bring back this '40s thin 'stache,
it did not work out.
I generally hike in a kilt, in Crocs.
I was a professional chef.
Not before IT, I quit IT, went to culinary school,
became a chef, came back because that turns out
that really sucks.
I go to a lot of punk rock shows with my daughter who is 18
and surprisingly not too embarrassed by me.
I'm Batman.
So I work remote.
One of the big reasons is because I have,
this is what I was known for when I worked in an office
is I was the person that did these horrible things
to their office mates.
But here's the thing,
I didn't actually have that many co-workers
so it was mostly just this guy.
(crowd laughing)
And we're still dear friends,
for the most part.
Random factoid, so this is a photo of
outside of the plane on the way here.
Absolutely beautiful, absolutely fascinating to me.
And I've done quite a bit of traveling,
but at the age of 38 this is actually the first time
I've ever been on a plane.
This is also the first time I've ever spoken
to a group this large.
So I figure it's a whole thing of firsts.
So let's actually move on to, what is RFID?
So RFID is a radio-frequency identification.
It is the use of, wireless use of electromagnetic fields
to transfer data.
You know you can do this for automatically identifying
and tracking tags that are attached to objects.
That's kind of the Wikipedia definition there.
But really no explanation of RFID or magnetic fields
and that sort of thing is gonna be complete
without talking about Tesla.
I'm sorry Nikola Tesla.
(crowd laughing)
You know, Tesla was without a question
the greatest geek that ever lived.
And actually if you're following that tweet stream,
there's a link to an explanation of why he was the greatest
geek to ever live.
So in 1894 Nikola Tesla used resonant inductive coupling
to wirelessly light up phosphorescent
and incandescent lamps.
Resonant inductive coupling is the near field wireless
transmission of electrical energy
between two magnetically coupled coils.
Resonant energy transfer is the operating principle
behind passive RFID tags, which you're gonna see here today,
wireless charging, which I think a lot of people have
probably adopted at this point,
as well as contactless smart cards.
Which if you've worked in the government
I'm sure you've dealt with.
So thank you Nikola.
There's a lot of practical uses for RFID
and a lot that many people in here have already used,
such as races.
Race timing, the bibs as well as shoe tags
have become very common, very popular.
DVD kiosks, I don't know why I put this one here,
these will be gone in like a year.
Authentication, doors, computer systems, medical carts.
This is becoming more and more and more common.
Toll collection, I'm sure that quite a few people here
have E-ZPass or whatever is common down here in Texas.
And asset tracking.
This is the bread and butter of the RFID industry.
This is what has driven prices down.
It used to cost several dollars to buy a single RFID tag
not that long ago, and now you can buy
a paper tag for 13 cents on a giant roll
because companies like Walmart and Best Buy
and all these large big box stores are using it.
Manufacturers are using it to track their assets.
It's easy, it's cheap and it's certainly
become more and more accessible to the rest of us, not just
to those industrial purposes.
And getting back to assets tracking for a moment,
this is what I get to do, which is really fun.
'Cause you're like oh, we have a bunch of vials of MRSA,
cool, don't touch that.
And actually there's,
there's a couple other random uses that I wanted to mention.
One just wireless access points and smartdust.
There's a thing called the Monza X-2K,
it's a UHS RFID reader.
Sorry and that's not it, ignore that.
It holds about 9,000 bits, it can actually be attached
to a circuit board and or to micro controller
and can be used to passively pass information
to the processor even if the device is turned off.
So where's this getting used and why is this handy?
So Microsoft is actually starting to use 'em in some
of their tablets.
And the idea is, you go into the store,
you purchase your product,
without anybody really even noticing that it's occurring,
it gets activated as you're purchasing it.
And a signal goes to that turned off device
and lets it know this was a legitimate purchase,
this is now under warranty, enjoy.
However, if you take it and you try to walk out of the store
with it, you'll never get to turn it on.
That's, it's kind of cool.
It's also kind of scary that you can wirelessly transfer
information to a turned off computer.
There's also a thing called smartdust,
which are tiny RFID chips that are actually used
to create wireless sensor networks.
These are starting to be used as neural networks
to control artificial robotic limbs.
I mean this is wild stuff.
And then of course I think most people are probably familiar
with RFID ear tags.
They're common in industrial farming
as well as with your pets.
That's a fairly common use.
And also people, they're used to track movements
of personnel within a building, at doors,
in elevators, that sort of thing.
Which every time I've had this conversation somewhere,
of course it's gonna, it brings up that question.
There's the privacy question,
there's this question.
So I did link the Google search to find these, it's great.
Just pages after pages of Google images.
So RFID is cheap, it's becoming more and more common,
but it's still not necessarily that understood
by the wide populace.
The range for reading one of these embeddable RFID chips
is centimeters, not feet,
not even inches.
So the concerns that you might be being tracked by RFID tags
are a little bit blown out of proportion.
There's still certain reasons to be cautious.
However, the reality is is that when you're running around
with these networked computers that are getting your
location from space in your pockets,
I'd be a little bit more concerned about that,
it's a lot easier.
But, this is a great picture.
I just wanna say, if this still really is a concern for you,
let me just give you some advice here.
(humming tune)
Oops, oh I left that one tiny.
Okay so here we have an RFID tag.
As we can see it read, no problem whatsoever.
Find yourself some tinfoil,
go ahead, put on the tinfoil hat.
(crowd laughing and applauding)
They work.
All right, so limitations.
There's certain disadvantages to RFID tags.
I'm sure that people that are aware of
iBeacons and other kinds of competing technologies,
there's areas where they're just quite a bit better.
There's physical limitations.
You can't read through aluminum foil
so how are you gonna track people?
It's difficult to read them through liquids.
There's a thing called signal collision.
So if you tried to read too many tags in a single spot,
things go bad.
Just as if you have two readers that are trying to read
a single tag, it doesn't know who to communicate to.
This causes issues.
Now the higher end you get with your hardware,
the easier, the more like collision detection there is
and the more it works against it.
And then of course standards.
For the most part there are standards.
Generally when you scan an RFID tag,
such as a UHF Gen2 tag, you can look at
the first three numbers of the tag
and immediately know the manufacturer.
If you bought it in the US.
Everywhere else it's just, who knows.
And there are privacy concerns.
There's a lot of people that have been working on this
and one of my personal favorite are zombie tags.
So zombie tags are really cool.
So you go into Best Buy, Best Buy uses these by the way,
and so you buy a high end computer.
It has an RFID tag in the box that gets picked up
at the front of the store.
Now you can imagine the potential security issue with that
of there's an RFID that might be linked to a product,
you leave the store, is it possible for somebody
to pick that up from a distance
and know that in your car is say a new MacBook Pro?
This is a concern and this is a concern privacy advocates
have had and I've certainly had as well.
So they came up with zombie tags.
So as you purchase the product, the tag is told,
you're dead and it no longer responds.
It might actually, you know, pick up a magnetic wave
and it'll resonate, but it won't respond,
unless it gets a very specific code in which case it goes,
oh sweet, I'm a live again.
And of course why would you do that?
Because somebody might return it to a store
and you have to add it back into your,
your store ready for sale.
I mean, come on, that's awesome.
So why Ruby?
And why am I just like rambling on about RFID tags
and all this goofiness?
Eh, and tinfoil hats.
So there's a bit of a lower technical debt.
When you look at this industry 10 years ago it was like,
you know, you gotta get your electrical engineer
in the room to help you, you know, write your software.
It was ridiculous.
There are libraries now, there are ways of accessing it.
The manufacturers are getting better at this,
so they're exposing APIs, they're exposing web sockets
that makes a language like Ruby perfect.
And in my industry personally, where I'm dealing
with scientists, who often times already know Python,
it's not that big of a jump.
And, you know, I can write script for them, pass it off,
and go here, enjoy and they can change it
if they need to in the future.
And it really makes me happy, it really does.
I was a PHP dev for many, many, many years.
I was dead inside.
(crowd laughing)
And then I found Ruby and it just,
it brings me, you know, absolute joy, it really does.
This is a bit of a high level overview.
If you wanna talk more in depth,
if you wanna talk about the frequency ranges
for UHF tags versus HF versus NFC tags,
I'll be more than happy to tonight after Matt's talks,
you know, let's grab a coffee.
We'll spend all the time that you want.
If you need something written of course just buy me a beer
and I'll just write it for you, that's fine.
Let's actually get to the fun part,
let's talk about the not so practical uses.
So this is Betty.
Betty is my dog.
I am so thankful to the RubyConf organizers
for doing all of this, but they did say that no,
I could not bring her today.
So this will be Betty
for this demonstration.
So Betty has recently, she signed up for Twitter
and she's been tweeting a little bit.
It's difficult, no thumbs.
Oh god.
So this is real, okay you know,
people go and we create goofy things and we throw 'em up
as a demo in a talk.
I have an RFID antenna by my back door
and I have this software running on a Raspberry Pi
because I'm a goof-nut.
Because I will let my dog out
and I'll go sit down and go I'm gonna get this
test patch real quick and then I'll go let her back in.
And then like an hour goes by and I hear the scratching
and she gives me that look of just you've betrayed me.
And I feel terrible, I love my dog,
she's absolutely wonderful.
So I had to come up with a different solution.
So basically what we have here instead
is let's go ahead and run Betty dot RB.
I'm now watching the door for Betty.
Betty, around her collar, the real Betty, not this Betty,
has an RFID chip.
So when Betty goes outside.
Woof, woof, woof, woof, woof, woof, woof.
Pretty sure that picked it up.
Oh my god you didn't do this on me did you?
Hardware talks, aren't they great.
Hold on.
I wrote a fail safe in there.
Woof, woof, woof.
(crowd laughing)
Yeah that could be it actually.
How is this not working?
All right, let me examine it real quick.
Like I said hardware talks.
Okay, I'm talking to it, that's fine.
Let's actually give it here.
So we have the sockets.
Let me use this.
Okay, that tag worked.
(crowd laughing)
You are dead to me.
(crowd laughing)
If Betty had not betrayed me
what would have occurred?
And I'll just do a proof of concept here,
we'll just go to the page where we can find this.
She has been basically tweeting me...
And I'm not logged in here never mind.
So she's been tweeting me letting me Adam I'm outside,
please don't forget me.
If you visit that website
you will actually, or visit her Twitter feed,
you'll be able to see the past tweets because
I'm sloppy.
When I let her back in it actually just goes ahead
and lets me know how long she's been out.
This is the code, if somebody notices why it doesn't
work now, feel free to let me know after the fact.
You know, we're just basically,
we're observing a web socket, that's all we're doing.
And we have a conditional there where
we're looking for Betty or for finding Betty's RFID tag,
we're performing one of two actions.
You know, this is one of the reasons I love Ruby,
it's just so quick to throw these things out
and or break them.
Let's move on to the Internet of Things.
I don't like this phrase, I really don't.
I mean, this is like, you know, such a buzz word,
everybody's into this.
So Julian Cheal on an episode Ruby Rose was quoted as saying
"Why should fridge be internet connected?
She goes, "Because it could tell you that you've
"run out of eggs, but it probably doesn't know that you
"stopped eating eggs months ago."
I mean what a great point.
There's no reason to have a smart fridge.
That's why I built the smart trashcan.
Which will work.
Oh my god you better work.
(crowd laughing)
So here's the idea.
I'm not good at switching it as quickly.
Let me just go and start up my smart trashcan.
Thank you very much smart trashcan.
And there's my smart trashcan.
So I have just gone to the store
and I've deleted my test data from last night.
There you go.
And I have, you know, say I wanna log these items
so that in the future I'll know when I run out.
I mean why else would you use a smart trashcan right?
All right, so I brought several items with me today.
So this is, I mean direct from my house,
this is a representation of the things
that I usually have around.
I have, of course, some taco shells.
We have some
mason jar covers, 'cause I can.
Egg drop soup.
I had something else, ah.
Ginseng tea, love tea.
And so your stool softener.
(crowd laughing)
(crowd laughing)
So it scanned your items.
I actually, I have a little API connection here
that goes up, looks up the bar codes and pulls them.
I'll show you the code for that I promise.
But now we've stocked our...
By the way, has anybody noticed the iPhone up there,
the 4G cover, that's the taco shells.
(crowd laughing)
I don't know why, I submitted a request to them.
It's not my problem.
So as your week goes on and you're ready to,
you know, you go through your food,
you've taken all 100 stool softeners, that sort of thing,
all you have to do is throw your items away,
in your smart trashcan.
You better work, I'm not even joking.
Oh, oh, oh, oh, no, no, no I hooked up to the wrong one.
Look at that, there you go.
(crowd applauding)
And now we just throw those all away,
and now we have a shopping list
and anybody can view the list from a web browser.
Your loved ones can be out shopping and go,
oh, he had that stool softener problem again
and they can just go ahead and pick 'em up.
Which that's what loved ones are for.
Yeah I've never talked to a loved one before.
That was the trashcan demo.
Actually the code for it's very simple.
Once again I'm just listening to a web socket
and performing an action in an active record
and also hitting this weird, funky API that I found
someplace that apparently doesn't work completely.
Somebody pointed out to me when I had actually
discussed this that if you wanna take this a step further,
you could actually get RFID bracelets, give them to people,
and find out who's the most wasteful in your house.
Because there's no better way to win over your family
than by tagging them
as in harassing them.
(crowd laughing)
So there's lots of other things
that you can do with RFID.
Personally, for me, I'm not the best dresser
and I've been accused of playing golf
because of my bad choices.
So I wanted to come up with a better way to deal with this.
So I have an RFID scanner
in my bedroom
because I'm that guy, and it's a fashion portal.
Once again, very simple, we're observing a web socket.
I'm actually not going to,
I'm actually missing the original portal
I was gonna bring it, so I'm not gonna bother
with the twice in a row situation,
but we are going to discuss kind of a pick me up.
How to do with your special clothes for special occasions.
Which I don't know about the rest of you
but I live a very rich fantasy life.
You know, I personally,
I enjoy being entertained and I enjoy it when
I can get like, you know, put into an excellent
mood first thing in the morning.
So I have a list of clothing,
they're rated based on different uses.
I have, you know, tuxedo, lab coat,
So basically the end result of this...
Maybe I should get off of this now.
I'm gonna switch this again.
Is when I get up in the morning and I grab my clothes,
I have a special purpose, I'm gonna get psyched up about it.
So like I said, I work for a lab.
You go and you put on your lab coat.
(She Blinded Me With Science)
♫ Science
♫ Science ♫
So I mean, you know you're gonna kick ass that day.
(crowd laughing)
When you're walking out like that and say, you know,
you get off and you have maybe an event after work.
(James Bond Theme)
I really thought I had cut those down a little bit, sorry.
Hawaiian shirt, Evan you wanna go ahead and guess
what this one's gonna do?
♫ Wasting away again in Margaritaville
♫ Searchin' for my lost shaker of salt
♫ Some people claim that there ♫
I will do one more and then I will stop beating
on this dead horse.
Because it entertained, I was up in the hotel room
like all weekend just playing and having fun with it.
And my last one was I know that this tie looks--
(electronic rock music)
Good lord.
Once again, simple.
Same pattern, we're listening to a web socket.
I have been, like I said,
there's been some information tweeted out
because there's a lot of different devices out there.
You can get RFID readers now that are
$200 range.
Not this setup, but you can get
cheap, working RFID readers on Alibaba,
several other sources.
Like I said before one of the things I didn't cover
is I didn't cover writing.
I would love to talk to anybody that's interested in that.
I did not talk about password locking, kill commands,
didn't cover any of that because the reality is
RFID has it's own conferences, it's a huge topic,
and it's just too much to go into.
But what I wanna do is I wanna spark your imagination.
This language, the happiness that comes with it,
I think you can spark creativity.
And I think it gives us an opportunity to,
you know, instead of beating our heads against the wall,
we can explore it and we can have fun and we can
entertain ourselves when we get up in the morning.
So I'm hoping that what everybody takes away from this
is that they kind of
see there's all this stuff out there that you can
go play with and you can make anything that you want.
However, I do realize I said this was about harassing,
I'm sorry not harassing, that's horrible,
this was about annoying your pets
and your family and your loved ones.
Now okay, admittedly, having this music playing,
that annoys your loved ones at home,
the pets (laughing)...
Hey, she's dead to me.
But what about your friends?
So I wanna tell you a story and I actually wanna invite you
to explore some of the possibilities here a little bit more.
This is Dana,
Dana Skully.
Don't look at me, I didn't name it.
This is Coraline Ada Ehmke's teddy bear
that she brought with her from Chicago.
Dana's missing by the way.
So if after Matt's talk, if anybody wants a little something
to do and you're not leaving tonight
this is your starter card Coraline, grab some people,
I'll give you this bar code scanner.
As you reveal the correct RFID tags,
it will give you the next clue.
I hope, for your sake,
that you get them all.
- [Voiceover] (mumbles) I get them all.
(crowd laughing)
So I think with that and everyone heard that threat,
I think that's it.
Thanks for letting me talk, if you have any questions,
I'll be happy to answer them.
(crowd applauding)
Does anybody want a foil hat?
It depends on the kinds of tags,
the higher end tags have,
you know, like a 0.01% failure rate.
These types of tags, the paper ones like I placed on my head
probably somewhere in the 85% range.
So generally speaking what you do
is you would load these into like a,
let's see Brady makes an RFID printer,
you start printing the spool, it'll read the tag first,
write a corresponding bar code to the tag,
verify that it operates, then continue printing it out.
Otherwise you can black it out
and you know the tag's bad and you just don't use it.
No I am, yeah, it's NFC, so it's in a different range
than what I've been showing up here.
NFC is really interesting but, you know, it has a range
of a few inches.
I can actually, the tag that's in Betty,
who is dead to me, can be read from
about 30 feet away with this equipment in theory.
I guess not.
Or not.
So there's a big difference there.
But yeah, NFC's great, I mean there's a lot of cool stuff
you can do with it and definitely a lot of fun.
If you have an Android phone it's even more fun.
Those, I'm sorry are those,
oh those are tiles, those are iBeacons.
I'm sorry, I'm sorry.
Talk to Chris Sexton.
Oh the antenna's are like 300 each
and the reader itself is 15 to 1,600.
Yeah this is industrial equipment,
this is not home equipment.
So I should like cover that, there is cheaper,
you know, play equipment out there.
And in fact actually if you have a Raspberry Pi, Arduino
or something of that nature, there are now UHF Gen2
shields that you can get for them.
Which is like 50 bucks, which is a little cheaper.
They can take a bit of a beating.
Most of that comes down to the casing.
So one of the things that you find with RFID
is things like antenna shape
play a big role,
which limits how you can package them.
You can't melt them to metal as well.
So they usually have to be, they're usually backed on paper
or they're backed on paper that is sealed inside of plastic.
okay she really is gone.
So Betty is wearing a fireproof RFID tag
and as well as the real Betty
because I don't know why.
I mean they put them on steal beams
in case they get crushed, they'll survive.
I mean they're used to like, they're usually
used in industrial applications where you might
see a construction site, piles and piles and piles of beams
everywhere, they put RFID tags on 'em.
And they'll go through and they'll read a pile
and they'll know exactly what they have
and they'll have the GPS coordinates for it
and now they have their inventory.
So they have to take a beating.
Those tags in particular last,
I think they're guaranteed to last 20 years,
but I would suspect they'll probably at least last 50.
So yeah, when several tags are trying to respond
at the same time, you're gonna get a signal collision.
Generally comes down to the reader,
gets to deal with that.
Industrial readers like this, I can read about
a hundred tags at a time within a span of,
I don't know, like 500 milliseconds.
With lower end like, you know, hobbyist type readers,
you might be able to read five at a time.
And it's all about sorting through that...
You know it's like,
it's like packet collision, similar concept.
And on the other side of that, if it's caused
from two readers reading the same tag,
you just screwed up the placement of the readers.
You're gonna have to figure that out.
Yes and no.
So a tag can only respond to one antenna at a time.
So generally what you do,
actually here's a great, you'll probably enjoy this.
So we, the company I work for, we had actually
wired up a anti-doping lab in the Middle East.
And what we did was we put RFID readers,
which were, they were
a very low-range reader into carts,
and in the ceilings, like every six feet,
more readers and antennas.
And then when the athletes would comes in
and they would give their urine sample,
it was sealed in a glass container
that has an RFID chip built into it.
So now as it would move,
through the doping lab, they saw who had it
because it had a tag, they saw what cart it was on,
they saw which floor, which room,
because as you would pass each tag it would just
take a log of it.
The only way that you would now, though,
which direction it was going is
because the previous reader had read it.
So this becomes kind of the issue.
And because you can't read it with two points,
you have to play with location
and worry a little bit about that.
But yeah, I mean, it's,
it's the exact kind of project that it's
becoming more and more common for.
All right, I think we're good.
All right, well once again, thank you everyone.