DesignSpark Electrical Logolinkedin
Menu Search
Ask a Question

14 Sep 2015, 14:00

How to Build an extendable DIY iBeacon

How to Build an extendable DIY iBeacon

 

After reading about the Eddystone release, I got really excited about the concept of the physical web. The thought of walking out of a mall with two hundred notifications harbors my enthusiasm to some degree, however using iBeacons for something other than advertising and sales is a really interesting opportunity.

I had a quick google. but nothing off the shelf would do, as I was looking for the ability to easily read custom data form the device/iBeacon.

Most iBeacons broadcast a payload usually in the form of a UUID (Apple's iBeacon) or a URL (Google's Eddystone). What I would like to do is to extend my beacons with data they generate themselves to give real-time device readings to nearby Bluetooth devices and their owners. In the following example I will host a web accessible server on my device, where I will stream the CPU usage of that device via a web socket. This server's URL is then broadcast to all devices capable of receiving an Eddystone URL. 

Creating your DIY iBeacon

What you will need

To get started, we need to get a hackable device on resin.io. If you haven't come across it yet, resin.io is a deployment and management platform for IoT, and it allows you to deploy Docker containers on your devices with a simple git push.

Provision your device

•          Sign up with resin.io & create an application.

•          Download the Device OS image.

•          Burn the image to an SD card:

–         Burning instructions for OSX and LINUX

–         Burning instructions for Windows

•          After booting, your device will pop up on your resin.io application's dashboard.

•          If you get really stuck, this video gives you a full walk-through on getting a device on resin.io and pushing code to it.

Take a look at the code. The Dockerfile is very important, as it tells resin.io how to build and run your container. Take a look at the comments for a line-by-line description.

# Declare base image, in this case intel edison with node pre-installed

FROM resin/edison-node

# Install native dependencies

RUN apt-get update && apt-get install -y bluetooth bluez libbluetooth-dev

># Enable systemd (not compulsory)

ENV INITSYSTEM on

# Make the project available to the container

ADD . /usr/src/app

# Set root working directory

WORKDIR /usr/src/app

# Install all npm (node.js) dependencies

RUN npm install express eddystone-beacon socket.io tinyurl

# Run start script which fires up eddy.js and an express server

CMD ["bash", "/usr/src/app/start.sh"]

eddy.js is where we broadcast the URL served from the device. We have to shorten the URL as Eddystone has an 18-character cap.

var url = "https://" + process.env.RESIN_DEVICE_UUID + ".resindevice.io"

var powerLevel = process.env.PWR || -21;

TinyURL.shorten(url, function(res) {

eddystoneBeacon.advertiseUrl(res, { txPowerLevel: powerLevel });

console.log("Beacon broadcasting " + res + " with txPowerLevel : " + powerLevel)

});

server.js reads CPU-usage from the device, then opens a socket to the client to display the live readings (every 1s) on the browser. I have used CPU usage for easy of use but this reading could be replaced with any sensor reading you like!

Now we need to get the code on to the device. Start by associating your local repository with resin.io:

$ git remote add resin @git.resin.io:/.git

Then run $ git push resin master. This pushes your code to your resin.io application's remote endpoint. It is then cross-compiled and transferred to your device. You can see the progress from your resin.io dashboard. Note that the first push will take some time because nothing is cached. If you'd like to learn more about how we cache between pushes read this

Next, we need to enable the device-url feature.

This allows our content to be served even if the client is not on the local network. You enable this from the device page on the resin.io dashboard. Select "Actions" menu item and then

"Enable public URL for this device".

title

Once the container starts, all that's left to do is get the 'Physical Web' app on your phone so you receive the notifications.

Happy hacking!

Raspberry Pi's & Accessories from RS Components

ResinIO has not written a bio yet…

14 Sep 2015, 14:00