NFC : Arduino , Android with the PhoneGap Near Field communication ( The first comprehensive explanation NFC Technical works of applied development Mobile Smart Device near-distance communication programming Practical Introduction )
"Mei" Tom Igoe (Tom Ego), Don Coleman (Don Coleman), Brian Jepson (Brian Jepsen)
Jin Jiangang Von Yilen Translation
ISBN 978-7-121-23997-7
the published in the year September
Price: 65.00 RMB
244 page
- Open
Editor's recommendation
Welcome to the world of near-field communication (NFC), a rapidly evolving new technology that transmits data between nearby electronic devices via wireless signals. This book, as a Hands-on guide, teaches you how to develop an NFC application on Android devices, the Arduino microprocessor platform, and embedded Linux devices through a number of examples, code, exercises, and step-by-stage project operations.
You will also learn to write applications using the NFC Data Interchange Format (NDEF), read messages from the NFC tag via the NDEF functions provided in PhoneGap, Arduino, and node. js, or Exchange data with other NFC devices. If you're familiar with HTML and JavaScript, then you're ready to start NFC.
Dive into the NFC architecture to understand the relationship between NFC and RFID
Use PhoneGap and its NFC plugin to write NFC application use cases on Android
Learn more about the NDEF structure: test the existing write label program and then write your own labeling program
Use PHONEGAP event listener to listen and filter ndef messages
Write a complete Android app to control home lights and stereos
Create a hotel registration app with Arduino, from check-in to open door lock
Write an NFC messaging program that spreads messages between two Android devices
Explore the development of embedded Linux applications with examples on Raspberry Pi and Beaglebone
Content Summary
Nfc:arduino, Android and PhoneGap near Field communications will take you into the world of Near Field communication (NFC), a fast-growing technology that allows devices to exchange data at close range or use radio signals. Nfc:arduino, Android and phonegap near field communication shows you how to write applications for near-field communication for Arduino, Android, and PhoneGap through a number of examples, code samples, exercises, and stepwise analysis projects. "Nfc:arduino, Android and PhoneGap near Field communication" includes: in-depth study of the NFC architecture; Write an application sample with PhoneGap and NFC plugin for Android; Use PhoneGap event listener to listen and filter ndef information Create an Android app that controls lighting and music in your home, and write peer-to-peer NFC information between two Android devices.
Directory
The 1th chapter is about ... ..... .... ... .... ..... ..... ..... .......-....., ... and ..... ... and .... .......-...... 1
This book is intended for readers ..... ..... ............................ ..... ..... ..... ..... ..... ............... ......... 2
It is recommended to read ... ..... ..... ..... ..... ..... ........................ ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ....... ..... 2
What is in this book ...? ..... .....-... and ... and ........-................. ..... ..... ..... ..... ..... ..... ..... ....... .............. 3
What do you need ...? ....... ................................ ..... ..... ..... ..... ..... ..... ..... ..... ..... ...... ....... ....... 4
Hardware................................................................................................................. 4
Software................................................................................................................. 6
Other good NFC applications ...... ..... ....................... ....... ..... ................. ......... 7
The conventions used in this book ...... .............................. ..... ..... ..... ..... ..... ..... ............ ........... 7
Use the code sample ..... ..... ..... ..... ..... ....... .................. ..... ..... ..... ..... ..... ..... ..... ....... ....... ......... 8
safari® Books Online .................................................................................................... 8
Contact us ... ..... ..... ..... ................................. ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ....... ..... 9
Thanks..................................................................................................................... 10
The 2nd chapter is NFC and RFID ..... ..... ..... ..... ..... ..... .................. 11
What is RFID ...? ..... ..... ..... ..... ..... ...................... ..... ..... ..... ..... ..... ..... ..... ....... ....... ......... 11
What is NFC ...? ..... ..... ..... ..... .......................... ..... ..... ..... ..... ..... ..... ..... ....... ....... ......... 12
How RFID works ..... ..... ..... ............................ ..... ..... ..... ..... ..... ..... ............ ........... 13
RFID standard system ..... ..... ..... ..... ...................... ..... ..... ..... ..... ..... ............. .......... 13
How does NFC work ...? ..... ..... ....... ....................... ..... ..... ..... ..... ..... ..... ..... ....... .............. 13
NFC Data Interchange Format (NDEF) .......... .............. ....................... ........ 14
The architecture of NFC ..... ..... ..... ..... ........................ ..... ..... ..... ..... ..... ............... ......... 15
The type of NFC tag ..... ..... ..... ..... .................... ..... ..... ..... ..... ..... ............. .......... 16
Where to buy the label ...... ..... ........................... ..... ..... ..... ..... ..... .............. .......... 17
The device matches the label type ...... ..... ........................ ..... ..... ..... ..... .............. ........... 18
What you can do with NFC ......... ........................... ..... ..... ..... ..... ..... ............... ......... 19
Summarize..................................................................................................................... 20
The 3rd chapter begins with the PhoneGap and PHONEGAP-NFC libraries ... 21st
Why Choose android ...? .... ..... ..... ........................ ..... ..... ..... ..... .............. ........... 21st
Your first PhoneGap application: Hello, World! ..................................................... 22
Set up the development environment ..... ..... ..... ....... .................. ..... ..... ..... ..... ..... .............. .......... 22
Create a PhoneGap project ..... ...... ..... ................... ....... ..... ................. ......... 27
Important documents ..... ..... ..... ............................. ..... ..... ..... ..... ..... ..... ..... ....... .............. 30
A simple location application ...... ..... ...................... ....... ..... ................. ......... 32
NFC Reader ......................................................................................................... 38
Install the NFC plug-in ..... .... ..... ..... .................... ..... ..... ..... ..... ..... ............. .......... 39
Write an NFC Reader application ....... ................... ....................... ........ 40
Troubleshooting ..... ..... ..... ..... ..... ..... ..................... ..... ..... ..... ..... ..... ..... ..... ....... .............. 43
Summarize..................................................................................................................... 44
The 4th Chapter NDEF the introduction ..... ..... ............................... 45
NDEF structure ........................................................................................................... 45
TNF (type name format) ....... ..... ................... ....... ..... ................. ......... 46
The type of load ..... ..... ..... ..... ..... ..... .................. ..... ..... ..... ..... ..... ..... ..... ....... .............. 47
Load ID ..... ... ..... ..... ..... ..... ..... ...................... ..... ..... ..... ..... ..... ..... ..... ....... ....... ......... 48
Load............................................................................................................... 49
Record the structure ... ..... ... ..... ..... ..... ..... ..... ..................-..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ...... ....... ....... 49
Record the head ..... ..... ..... ..... ..... ...................... ..... ..... ..... ..... ..... ..... ..... ....... .............. 50
How big a NDEF message can be ... ..................... ....................... ........ 50
Record block ..... ..... ..... ..... ..... ..... ...................... ..... ..... ..... ..... ..... ..... ..... ....... .............. 51
Reference............................................................................................................... 51
NDEF Combat ........................................................................................................... 52
A label written to the application: Foursquare check-in ..... ... ..... ..... ..... ..... ..... ..... ..... .....? .................... 56
Write a ndef record to the label ........ ..... ............. ....................... ........ 57
Write a different record type ..... ..... ..... ..................... ..... ..... ..... ................. .......... 60
An overview of the Ndef auxiliary functions of PHONEGAP-NFC ..... ..... ..... ..... ........................... 65
Summarize..................................................................................................................... 67
The 5th chapter listens to the Ndef data ...... ..... ....... ................. 69
PHONEGAP-NFC's event monitoring ........ ..................... ........ ................... ....... 69
A ndef reader application ...... ..... ..... ..................... ....... ..... .................. ......... 71
Listen to multiple events ...... ..... ..... ..... .................... ..... ..... ..... ..... ..... .............. .......... 72
Read the NDEF message ...... ..... ..... ...................... ..... ..... ..... ................. .......... 75
Use record types to filter labels ....... ..... .................. ........ ................... ....... 78
Filter with MIME type ..... ..... ..... .................... ....... ..... ....................... 79
The Android label distribution system ..... ..... ........................ ..... ..... ..... ................. .......... 82
Intent type ..... ..... ..... ..... .......................... ..... ..... ..... ..... ..... ..... ............ ........... 83
Android app record ..... ..... ..... ....................... ....... ..... .................. ......... 86
Summarize..................................................................................................................... 87
The 6th chapter is an NFC application practice ........ ..................... 89
User interaction ..... ..... ..... ..... ..... ..... ....................... ..... ..... ..... ..... ..... ..... ..... ..... ..... ...... ....... ....... 91
Learn about Hue ..... ... ..... ..... ...................-.......-........ ..... ..... ..... ..... ..... ..... ..... ..... ..... ...... ....... ....... 92
Hue data Format ..... .... ..... ..... ....................... ..... ..... ..... ..... ..... .............. .......... 94
The rest API of Hue ..... ..... ......................... ..... ..... ..... ................. .......... 97
Android Shell ........................................................................................................ 97
PhoneGap Media API ..... ..... ..... ..... ...................... ..... ..... ..... ..... ..... ............. .......... 98
User interface (UI) ..... ..... ..... ..... ....................... ..... ..... ..... ..... ..... ..... ..... ....... .............. 99
Application code ..... ..... ..... ..... ....... ..................... ..... ..... ..... ..... ..... ..... ............ ........... 101
General functions ..... ..... ..... ..... .......................... ..... ..... ..... ..... ..... ............... ......... 102
Global event handlers ...... ..... ....................... ....... ..... ................. ......... 104
The Hub communication function ..... ..... ..... ........................ ..... ..... ..... ..... .............. ........... 106
User interface control event handlers ... ..... ... ... .... ... .... ... .... ..... .... ..... ..... ..... ..... ..... ..... ......? .............. 110
Event handlers in the music industry ..... ..... .................. ............................. 113
NFC event handlers ..... ..... ........................ ....... ..... ................. ......... 118
Enable background scheduling ..... ..... ..... ..... ...................... ..... ..... ..... ..... .............. ........... 120
Summarize................................................................................................................... 121
The 7th chapter is about Arduino and NFC introduction .......... ............. 123
Digital encounters physics: Arduino ..... ..... ..... .................. ........ ................... ....... 123
The hardware core of NFC ..... ..... ..... ......................... ..... ..... ..... ..... ..... .............. .......... 125
The Arduino development environment ..... ..... ..... ..... ..................... ..... ..... ..... ..... ..... ............. .......... 125
Serial communication ..... .... ..... ..... ..... ..... ..................... ..... ..... ..... ..... ..... ..... ............ ........... 129
Install the Arduino Library ...... ..... ..... ..................... ..... ..... ..... ................. .......... 130
The Ndef Library of Arduino ..... ..... ......................... ..... ..... ..... ................. .......... 132
Read the ndef in the Arduino ........ ................. ....................... ........ 134
Write Ndef in Arduino ..... ..... ................... ....................... ........ 137
Micro-Controller NFC application: Hotel Key card ..... ..... ... .... ..... ..... ..... ..... ..... ..... ..... ..... .....?????????? ..... 138
Interaction and data Format ..... ..... ..... ....................... ..... ..... ..... ................. .......... 140
The Ndef writer device for Arduino ... ..... ... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ................ 142
The Ndef reader and door lock device of the Arduino ..... ..... ..... ..... ..... ..... ..... ..... ..... .... ..... .....-..... 148
The browser interface of the Arduino NDEF writer device ... ..... .... ..... ..... .............................. 156
The Application Specification for node. JS: Package.json ..... ... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ........... 156
Client-side code ..... ..... ..... ....... ................... ..... ..... ..... ..... ..... .............. .......... 157
Server-side code ..... ..... ..... ........................ ..... ..... ..... ..... ..... ............. .......... 158
Summarize................................................................................................................... 162
The 8th chapter Point-to-point (to-peer) exchange ......... .............. 165
Send a peer message in the PhoneGap ....... ................. ....................... ........ 167
Receive peer-to phonegap in ..... ..... ................. ....................... ........ 175
Switch................................................................................................................... 177
Static switching ..... ..... ..... ..... ....... ..................... ..... ..... ..... ..... ..... ..... ............ ........... 178
Send a toggle message in the PhoneGap ..... ..... ................ ....................... ........ 178
Use the Arduino to peer ...... ..... ........................ ..... ..... ..... ................. .......... 184
Card emulation ... ..... ... ..... ..... .... ..... ..... ..... ..... .................. ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ....... ..... 184
Summarize................................................................................................................... 185
9th: NFC in the embedded system ......... ................. 187
The embedded Linux device and Package Manager introduce ... ..... ... .... ... .... ... .... ..... .... ..... ..... ...........-.....?????????? ..... 187
Network, USB and NFC ...... ..... ..... .................. ....... ..... ................. ......... 188
NFC on embedded Linux: At a glance ... ... ... ... ... ... ... ... ... ... ... ... ... .... ... .... ... .... .... ... ..... ..... ..... ..... ..... ..... ..... ..... ..... ...... 190
General functions ..... ... .... ..... ..... ..... ..... ....................... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ....... ....... 191
Choose a familiar editing Tool ..... ..... ...................... ....... ..... ....................... 191
Learn about the Package Manager ..... ..... ..... ....... .................. ..... ..... ..... ..... ..... ............. .......... 191
Set the date and time ....... ..... ........ ................ ..... ..... ..... ................. .......... 192
To build a download directory ..... ..... ........................ ..... ..... ..... ................. .......... 193
Beaglebone features ...... ..... ......................... ....... ..... ................. ......... 193
Raspberry Pi characteristics ...... ..... ........................ ....... ..... ................. ......... 193
Install the NFC tool ..... .... ..... ..... ......................... ..... ..... ..... ..... ..... ............... ......... 194
Install the LIBUSB Compatibility Library ...... ..... ..... .................. ....... ..... ................. ......... 195
Install LIBNFC ..... ..... ..... ..... ....... .................... ..... ..... ..... ..... ..... .............. .......... 195
Raspberry Pi or Beaglebone installation test ...... ..... ..... ..... ..... ..... ..... .................... 196
Install Libfreefare ..... ..... ..... ..... ..................... ..... ..... ..... ................. .......... 196
LIBNFC and Libfreefare's command-line tools ..... ... ..... ... ..... .... ..... .... ..... ..... ............................ 197
The ndef of node. JS is read and write ....... ..... ................ ....... ..... .................. ......... 199
The web interface of the tag writer ........ ..................... ....... ..... ................. ......... 203
The label controls the physical output ...... ..... ..... ..................... ..... ..... ..... ..... ..... ............. .......... 205
The Beaglebone version ..... ..... ..... ...................... ....... ..... .................. ......... 205
Raspberry Pi version ...... ..... ........................ ....... ..... ................. ......... 207
Summarize................................................................................................................... 211
Appendix A of the NFC specification code ..... ..... ..... ..... ..................... 213
About the author
Tom Igoe teaches physics computing and web-based interactive telecommunications programs at the Tisch College of Art, New York University.
Don Coleman is the author of PhoneGap NFC plug-in, leading the mobile practice of Chariot Solutions.
Brian Jepson is one of the organizers of maker Media Senior editor, a hacker, Providence Geeks and the Rhode Island Mini Maker Faire.
Objective
Translator sequence
At the beginning of this book, EoE Community CTO Yan Chanlang (ICESKYSL) recommended us to translate, it is very coincidence that I was in Shanghai with the Arduino mentioned in this book one side, and witnessed the program, and then run out after the effect. It's really cool, and it's very easy to get started, and it's not as mysterious as you think. The content of this book is very much connected with Android, and NFC is a very popular technology in the mobile Internet. After a few chapters, know that the book does not involve very mysterious, difficult to understand programming, or some other high threshold content.
This book is not written entirely for programmers, you can be a program enthusiast, can also be experienced programmers, can be software, or do related hardware, can be Android developers, also can be iOS, BlackBerry, Windows Phone, etc., and can even be a web developer. No matter what language you use for development, you can get started quickly. Of course, if you've just heard the technology I mentioned above, it doesn't matter, because the threshold of the book is very low, as long as you follow the book a step, as long as you are interested in NFC, want to know how it works, and know what to do with it, then this book is definitely a very good choice.
This book starts with what is NFC, and gradually tells us how to choose the right, simple tool to build a simple NFC application. This also involves some techniques, such as HTML, JavaScript, if you can fully understand the best of course, but even if you only know some basic tags, basic grammar is not a problem; Once you've developed a simple NFC application with this book, follow up on how you want to enrich it, I think that's all very easy. After all, everything starts hard.
In the process of translating this book, because of the development from Guangzhou to Beijing, so the progress of the translation is somewhat backward, especially thanks to the translation partner of this book Hexter to my Help, in my due to other things and I have no time to take care of a part of the work to help me. Also want to thank the publishing House editor of the book, because the translation is actually a very dull thing, in the process of translation will inevitably appear some words are not fluent, and even the context of the problem, editors have to line to see, do not understand the need to mark out, or provide better sentences. So thanks to them, let the book be published smoothly, and then provide some good introductory material for those who want to learn about NFC and want to do something about it.
Nfc:arduino, Android and phonegap near Field communication