NFC – Research & Development
Those who know me know I’m into home-brew electronics and anything involving modular electronics from companies such as Ciseco, or Adafruit and I’ve probably got a crate full of tech like this in the workshop garage down the garden.
A year ago, I developed a product called SmartWhere using a micro-sized cellular transmitter stitched into clothing (such as a jacket or a pair of shoes) and coupled with a tracking application the idea was to give carers of those with Alzheimer’s the ability to track them, in real time on a map, and use geo-fencing for alerting when they wander beyond a pre-set limit.
This worked well, in fact I turned down a commercial offer at the time. (long story for another blog post maybe)
I enjoyed playing around with this really accessible and super low cost technology to implement really innovative solutions to real world problems at a fraction of the cost than you would think. I’m not entirely sure people are aware of all this kit we have available as everyday consumers so I was pretty happy when at work the potential to run an NFC based project came up for a worldwide client. It reminded me how much I love playing around with this stuff.
NFC – Connecting everything
So if you don’t know, NFC or (near field communication) is a comms-protocol, the term arbitrarily can often refer to anything involving tap-to-connect or swipe-to-activate type of transactions regardless of whether it’s using WiFi, Bluetooth or NFC specifically. Each has its own performance envelope, Bluetooth coming in two flavours, low or high power, Wifi utilises the 27Mhz frequency band as a standard but NFC is specific, and new. (ish).
You’ll have heard of NFC I’m sure with the hurraw of Apple Pay which uses just that to allow tap-to-pay transactions using a comms-protocol which is small payload, high performance and mostly secure.
The team & I wanted to leverage NFC to solve a real world problem. I’ve changed specifics here to protect any intellectual property (IP) but you’ll get the jist of the technology.
Logging into the myriad of websites we use nowadays can be a chore. We save tens of passwords in our Apple Key Chain, or use third party Windows software to manage our passwords & automatically log us in (think LastPass or OnePassword), and occasionally of course we write them down. How many times do you find yourself constantly performing password resets on our cloud services because it’s quicker than hunting down the password you’ve scribbled onto the back of a beer mat? So the first problem which needed solving was how, from an e-commerce perspective do you simplify and shallow out the transaction of accessing a website, and logging into your account. From that we’ll explore more about starting a chain of events, maybe logging into a website, going to your account page and doing ‘something’.
UPDATE: Another scenario which came to mind when working through the above was a pay-to-donate system. I like the idea of this. Imagine you’re at a key dwell area in a restaurant and on a wall there’s a large screen interactive display with an NFC reader built in, and a call to action to donate to some cause. Would you? Because it was so easy you probably would.
I’ll work through this second scenario first & come back to the other one in due course.
Firstly, let’s discuss the NFC standard NDEF. The ‘Near field Data Exchange Format’ you can read about it here but that’s the format I’ll be playing with.
MiFare often confused with a communication protocol standard, is actually the biggest manufacturer of IC tags so the tags I’m using with my Go to NFC tag reader comes with MiFare manufactured tags.
I went on Amazon and purchased some tags from RapidNFC. http://www.amazon.co.uk/gp/product/B00M5PC0FG?refRID=J484A9H8AZRGSYACN1QF&ref_=pd_ys_sf_s_192413031_b2_1_p I like these because they are very ‘low profile’ meaning once removed from their sticky backing, they are extremely thin. This is useful when placing them on smaller objects. Also, because you can see the antenna and EEPROM, it’s easy to carve out (using a craft knife) completely removing it from the sticky backing leaving you with just the ‘clever bit’ and you can then miniaturise this even further.
Then I needed a reader. I find the physical hardware readers so much more accurate and quick than the ones currently in handsets. Whether its something to do with the surrounding housing (the phone case) or the fact it’s competing with both Bluetooth & cellular wave lengths in close proximity I don’t know, but I purchased this bad boy
This came with a few tags too so that was useful. The app I noticed only allowed you to program a certain amount of times per day, I think fifty or something, but then infinite reads of course. It just makes sense to check these things before hand.
So two pieces of software are needed to program the NFCs.
There’s the Windows desktop app (download here) which is a very simple GUI driven app to allow you to specify actions after a tag is read. It walks you through using very clear pictures and this is good for novices to get up to speed. You can program a tag by simply holding it close to the reader for a few seconds.
The downside of using this simple app is you don’t seem to be able to do anything too complex with it. Including being able to ‘string’ actions together. So sure you can open a website, but you can’t pass anything to that action beyond the very simple so logging into a service or such like is a no go.
The other application is the NFC encoder app (download here) which is seemingly for bulk programming and doing anything more complex. You can use data fed from a CSV file to perform complex actions and this is what I wanted to do. From here, I’d encode a tag to open a website, login to a service, launch a text message (the bit which would drive the micropayment for the donation) and then notify the user the donation was a success or failure.
So the last thing needed was a payment gateway, ideally designed to do micro payments and SMS type of payments. After some R&D and lots of strong black coffee I picked ZayPay (www.zaypay.com) who seemed geared up for developers pretty well & have an excellently documented API and library of tools & pre-written code snippets to help with integration.
For testing purposes, after creating an account, the process is quite simple;
- Set up an app with a reference URL (this will live on your website/demo page and will be what the user see’s)
- Set up a ‘price setting’ which governs how the user will pay & what details they are expected to hand over
- Set up a ‘payalogue’ which is Zaypay speak for the action-after-tap, i.e the bit on screen which shows the donation amount, messaging, the button etc.
For demo purposes I didn’t really need to use the API, I used their PHP call back library to call the ZayPay platform from within my webpage. It should be noted there are two really useful code snippets in HTML which you can bury inside a page. Call this from within your <head> as you would any other script,
(the number relates to the price setting you set up) and then display a button to call the script
Each payment price setting has it’s own unique identifier which you’re able to retrieve from the ZayPay control panel, and you need to specify it when you call it of course, along with a couple of other bits, so it looks something like this;
$price_setting_id = 123456; // Id
$price_setting_key = '8379f93116ad623a5547ddddd'; // Hash
$payalogue_id = 138617; // Id
So both the price setting IT and price setting API key are available from within your zaypay control panel.
Easy stuff so far.
So I wrote a simple single HTML page http://www.creativepixel.me.uk/nfc/payment.html which contains all the guff above, with a payment button. So now, I need to trigger not only the site URL after reading a tag, but to make the payment.
Now, if you click the button from within your browser, after some lightbox content, you’ll see you need to send PAY 4421 to 6041. So I thought maybe I bypass this button and go straight to payment. That would mean the NFC action would be;
- Launch SMS app, and parse PAY 4421to 6041. So the results are the video below and it seems to work. The next step for this is to get this running on a battery powered Pi and integrated onto a physical real-world object that users can touch their phone to donate. There’s an article on how to set up your Pi here, and I’ll continue this article in Part 2 – coming soon