Beginning NFC: Near Field Communication with Arduino, Android, and PhoneGap

Beginning NFC: Near Field Communication with Arduino, Android, and PhoneGap

Tom Igoe, Don Coleman, Brian Jepson

Language: English

Pages: 246

ISBN: 1449372066

Format: PDF / Kindle (mobi) / ePub

Jump into the world of Near Field Communications (Nfc), the fast-growing technology that lets devices in close proximity exchange data, using radio signals. With lots of examples, sample code, exercises, and step-by-step projects, this hands-on guide shows you how to build Nfc applications for Android, the Arduino microcontroller, and embedded Linux devices.

You’ll learn how to write apps using the Nfc Data Exchange Format (Ndef) in PhoneGap, Arduino, and node.js that help devices read messages from passive Nfc tags and exchange data with other Nfc-enabled devices. If you know Html and JavaScript, you’re ready to start with Nfc.

  • Dig into Nfc’s architecture, and learn how it’s related to Rfid
  • Write sample apps for Android with PhoneGap and its Nfc plugin
  • Dive into Ndef: examine existing tag-writer apps and build your own
  • Listen for and filter Ndef messages, using PhoneGap event listeners
  • Build a full Android app to control lights and music in your home
  • Create a hotel registration app with Arduino, from check-in to door lock
  • Write peer-to-peer Nfc messages between two Android devices
  • Explore embedded Linux applications, using examples on Raspberry Pi and BeagleBone

Network Warrior

SSH Mastery: OpenSSH, PuTTY, Tunnels and Keys

Oh My JS: The Best JavaScript Articles

Java: The Complete Reference (9th Edition)



















.bash_profile or .profile. If the file doesn’t exist, you can just create it. Add the following lines to that file: export ANDROID_HOME=/Applications/android-sdk-macosx export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools Change the ANDROID_HOME path if you stored the SDK somewhere other than the Applications directory, of course. Then save your profile file, and log out of the Terminal and log back in to reset the PATH variable. On Windows You have to find your way to the “System

see the advantage to MIME-type fil‐ tering here in action: your app only gets events generated by tags with the appropriate MIME-type. Figure 5-4 shows the results of this app. The full source code can be found on GitHub. Figure 5-4. Results from the MimeReader app: waiting for tags (left) and reading a text tag with MIME type “text/plain” (right) 88 | Chapter 5: Listening for NDEF Messages Android’s Tag Dispatch System Thus far, you’ve used Android’s foreground dispatch system to capture

write to the NFC tags used in this app. As mentioned before, you’ll send it as a MIME type, text/hue. The Hue’s REST API As you’ve probably noticed from the debug tool, the Hue’s request API is RESTful. To get data, you use the format /api/MoodSetterApp/ then add on the specifics you want and make an HTTP GET request. For example, to get the state of light 1, it’s /api/Mood‐ SetterApp/lights/1/state. To change data, you use the same basic format with a PUT request. In the app you’re building,

the settings to work. Pulling away before the device has read the tag and acted on it will cause read errors. This is the most you’ve probably written to a tag before, and it shows you that the interaction between reading and writing and the actions they are meant to trigger can have effects on the physical interaction between user, device, and tag. The more you can write your program to keep them independent of each other, the better the interaction will be. If you decide to get fancy with the

if (now() <= checkin) { Serial.println("You haven't checked in yet."); Serial.println("Current time " + formatTime(now())); Serial.println("Your arrival " + formatTime(checkin)); } else if ((now() >= checkin) && (now() <= checkout)) { Serial.println("Welcome back to your room, " + cardName + "."); result = true; } else if (now() >= checkout) { Serial.println("Thanks for staying with us! You've checked out."); Serial.println("Current time " + formatTime(now())); Serial.println("Your departure " +

Download sample