Slides from Feb 2 Xamarin Melbourne Meetup presentation by Rod Hemphill on Location Based Development using Xamarin.
Lots of hard earned tips from the trenches in this presenation
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Location Based Development Using Xamarin
1.
2. Contents
• An
example
app
• Using
Beacons
for
loca3on
detec3on
• What
are
Beacons?
• Which
provider
should
I
choose?
• Which
protocol
should
I
use?
• GeoLoca3on
vs
Beacons
• Configuring
beacons
• Development
Code
• The
reality
of
how
they
work
3. The AudioPuppy App
• Both
beacon
and
GPS
loca3on
detec3on
• Plays
audio
files
based
on
physical
loca3on
4. Contents
• An
example
app
• Using
Beacons
for
loca3on
detec3on
• What
are
Beacons?
• Which
provider
should
I
choose?
• Which
protocol
should
I
use?
• GeoLoca3on
vs
Beacons
• Configuring
beacons
• Development
Code
• The
reality
of
how
they
work
5. What is a Beacon?
Es*mote
specifica*ons
as
an
example
It
is:
• A
small
computer
32
bit
ARM
Cortex
MO
CPU
• With
other
components
Es*mote
has
an
acceleromiter
and
temperature
sensor.
• A
Radio
2.4
Ghz
using
Bluetooth
4.0
SMART
• A
baJery
CR2477
-‐
3
years
on
default
seLngs.
• A
cover
Sealed
plas*c.
• Expect
a
signal
range
of
40-‐50
meters
• No
‘pairing’
required
• Smartphones
can
listen
to
many
at
the
same
3me
A
Beacon
is
a
Bluetooth
Low
Energy
(BLE)
devices.
6. Choosing a beacon manufacturer
They
must:
• support
the
beacon
protocol
you
with
to
use.
• have
appropriate
baJery
life
• baJery
life
3
months
or
3
years?
• do
they
have
baJery
conserva3on
op3ons
• no3fica3on
of
impending
baJery
expiry
• have
an
appropriate
form
factor.
Consider:
• physical
size
• weather
resistant
• can
be
physically
secured
(to
prevent
theY)
• blend
with
intended
environment
• be
configurable:
• Most
have
base
signal
configura3on
(frequency
and
strength
of
message)
• are
they
server
configurable
• -‐
are
they
wirelessly
configurable
(or
physically
take
baJery
out
to
configure)
• have
an
easily
replacable
baJery.
• be
cost
effec3ve:
• once
off
purchase
• charge
per
transac3on
use
• support
other
features
you
need:
• Temperature
detec3on
• mo3on
sensor
• Holding
user
data
(e.g.
url)
For
a
full
evalua3on
go
to
:
hJp://www.aislelabs.com/reports/beacon-‐guide/
7. Beacon Protocols
• There
are
different
protocols.
This
defines
the
data
you
get
from
the
beacon
into
your
app:
• iBeacon
(introduced
by
Apple
in
2013)
(see
slide)
• Eddystone
(introduced
by
Google
in
2015)
• Nearable
(introduced
by
Es3mote
in
2014
aimed
at
the
wearable
market)
• Manufacturer
proprietary
(e.g.
Gimbal
beacons
support
both
their
own
&
iBeacon)
• Poten3al
uses:
• Retails
store
product
informa3on,
aJach
to
retail
products,
auc3on
item
informa3on,
turn
on
the
TV,
loyalty
program
detec3on,
mapping
a
conferences
and
exhibi3ons,
direc3on
while
indoors.
• My
choices:
• Ini3ally:
Qualcom
and
Qualcom
protocol
• I
now
use:
Es3mote
and
iBeacon
8. iBeacon Protocol
Property
Description
proximityUUID
Your
businesses
UUID
that
the
beacon
is
assigned
to.
When
you
listen
for
beacon
signals
you
specify
this
value
and
you
will
only
get
these
beacon
message
back.
major
A
random
number
assigned
to
identify
a
beacon
which
you
can
change.
For
example
rather
than
register
beacons
for
different
project
to
different
UUID’s
you
could
assign
them
to
a
common
major
code.
The
names
‘major’
and
‘minor’
have
no
signiDicance
–
any
differentiation
between
this
is
within
your
app.
minor
A
random
number
assigned
to
identify
a
beacon.
proximity
Values:
Immediate,
Near,
Far,
Unknown.
With
the
Estimote
beacons
I
have
found
that
‘Immediate’
is
within
0.5m,
‘Near’
is
within
2.0m
and
‘Far’
could
be
anything
greater
than
2.0m
and
up
to
50m.
You
will
receive
‘Unknown’
values
regularly.
This
means
that
for
some
reason
the
Bluetooth
signal
was
temporarily
interrupted.
(No
signal
is
receive
if
a
beacon
is
out
of
range).
accuracy
(i.e.
distance)
Is
intended
to
represent
the
distance
in
meters,
but
we
advised
not
to
use
it
in
this
manner
as
it
will
usually
be
wrong.
You
can
use
this
to
determine
the
relative
closeness
between
two
beacons.
rssi
(in
dB)
Is
the
decibel
reading
of
the
signal
strength,
the
root
data
that
the
above
items
are
derived
from.
9. GeoLocation vs Beacons
• When
using
GPS
for
loca3on
detec3on
you
define
the
central
point
then
a
radius.
The
circumference
is
called
a
GeoFence
–
you
are
either
inside
or
outside
the
‘fence’.
• For
beacons
you
place
the
beacon
at
the
central
point,
measure
the
radius
using
signal
strength,
and
op3onally
record
the
La3tude
and
Longitude
of
where
you
placed
the
beacon.
• GPS
characteris3cs:
• Satellite
based
hence
it
doesn’t
work
well
indoors.
• Can
be
very
accurate,
but
not
on
a
standard
smartphone
…
they
are
dumbed
down
to
conserve
phone
baJery
life.
• Beacon
characteris3cs:
• Low
energy
radio
device
–
beacon
baJery
life
restricted.
• Ideal
for
indoors.
10. Configuring beacons
• Can
change:
• Frequency
messages
are
sent
• The
power
of
the
message
….
impac3ng
baJery
life
(more
on
this
later)
• Dynamic
configura3on:
• Does
your
beacon
have
the
ability
to
be
able
to
configure
the
above
remotely?
11. Contents
• An
example
app
• Using
Beacons
for
loca3on
detec3on
• What
are
Beacons?
• Which
provider
should
I
choose?
• Which
protocol
should
I
use?
• GeoLoca3on
vs
Beacons
• Development
Code
• The
reality
of
how
they
work
12. Xamarin Coding
• Two
op3ons:
• ‘Ranging’
-‐
scan
for
beacons
in
range
and
read
their
values,
• ‘GeoFencing’
-‐
not
supported
by
Es3mote
(and
I’m
not
sure
it
would
work
anyway
due
to
beacon
limita3ons)
• Coding
snippets
are
available
at:
• Android:
hJps://blog.xamarin.com/use-‐ibeacons-‐in-‐android-‐with-‐c/
• iOS:
hJps://blog.xamarin.com/play-‐find-‐the-‐monkey-‐with-‐ios-‐7-‐ibeacons/
• Use
the
Xamarin.Mobile
package
14. Coding considerations
• Make
sure
you
check
that
Bluetooth
is
turned
on
and
consider
what
to
do
both
when
the
user
has:
• forgoJen
to
turn
it
on,
and
• purposely
turned
it
off.
• Background
mode:
• iOS
has
the
ability
to
start
your
app
when
it
detects
a
beacon.
• Beacon
signals
arrive
less
frequently
in
background
mode.
15. Contents
• An
example
app
• Using
Beacons
for
loca3on
detec3on
• What
are
Beacons?
• Which
provider
should
I
choose?
• Which
protocol
should
I
use?
• GeoLoca3on
vs
Beacons
• Configuring
Beacons
• Development
Code
• The
reality
of
how
they
work
16. Limitation
Bluetooth:
• penetrates
most
materials,
and
• is
most
absorbed
by
water.
Beacon
limita3on:
• BaJery
life
• High
power
and
frequency
means
lower
baJery
life
• Power
fluctua3ons
Smartphone
limita3ons
• BaJery
life
compromises
17. Beacon lab test results
We
tested:
• 5
Es3mote
beacons
set
with
normal
power
sekngs,
and
• 5
with
a
high
power
and
high
frequency
sekng.
• At
0.2,
1.5,
2.5
and
4
meters.
• Each
with
50
message
(total
of
2000
readings).
18. Lab test results:
Higher
power
sekngs
had:
• An
increase
in
accuracy
up
to
2.5m,
• A
marked
increase
in
standard
devia3on
at
4m
(less
accuracy),
• BaJery
life
reduced
from
3-‐4
years
to
6
months.
19. Challenges
• Inundated
with
beacon
messages:
messages
from
all
beacons
with
50m
every
second.
• Too
much
Bluetooth
absorp3on
• Absorbed
by
water.
• 60%
of
human
are
water.
• Not
enough
Bluetooth
absorp3on
• The
floor
above
may
be
closer
than
your
current
floor.
• ‘Unknown’
message
• 1
in
10
is
a
message
“Unknown”
meaning
in
range
but
signal
is
unknown.
• Message
synchronisa3on
• (See
next
slide)
• Signal
strength
irregulari3es
• (see
lab
test
results)
• Out
of
range
detec3on
• If
no
messages?
• If
messages
in
and
out
of
power
range?
• “Significant
change”
problem
• Fluctua3ons
in
signal
strength
could
mean
many
things.
• User
behavior
irregulari3es
• Moves
forwards,
back,
away,
comes
back,
…
• Incoming
phone
calls
• How
do
you
handle
incoming
messages
when
user
is
talking
on
the
phone?
• Fast
moving
users
• Exaggera3ng
message
synchronisa3on
problem.
• Beacons
are
imperfect
and
have
their
own
characteris3cs.
• Thread
processing
• Make
sure
beacon
message
are
processed
on
a
background
thread.
20. Suggested coding
Create:
• A
Beacon
class:
• Handing
characteris3cs
of
an
individual
beacon
• calibra3on,
• averaging
of
messages,
• managing
when
goes
out
of
range
• A
BeaconsInRange
class:
• A
dic3onary
of
all
beacons
in
range
• Comparison
of
one
beacon
to
another
to
determine
highest
Rssi
• A
BeaconService
class
• Singleton
to
manage
mul3ple
beacon
ac3vity:
• Current
beacon
• Process
beacon
sigh3ngs
(adding
and
removing
beacons
from
BeaconsInRange)
24. Summary
• Beacons
are
used
to
detect
loca3on
indoors
• From
the
simple
to
the
complex:
• A
user
has
entered
a
coffee
shop
and
has
been
there
more
than
15
minutes.
• To
the
complex:
• To
mapping
100
stalls
within
an
exhibi3on
and
which
person
was
interested
in
which
stall.
• There
are
technology
limita3ons,
some
relevant
to
your
situa3on,
some
not.
Solving
the
problems
is
easy
…
but
only
aYer
you
know
what
they
are.