Professional Documents
Culture Documents
Manikantan Krishnamurthy
Technical Manager Nokia, SEAP
2011 Nokia Nokia NFC Development v. 1.1.6 NFC Forum and the NFC Forum logo are trademarks of the Near Field Communication Forum.
2005
Nokia 5140i
3
2007
Nokia 3220 Nokia 6131 NFC
2008
Nokia 6212 classic
P6/2011
Nokia C7 Symbian Anna
Pairing
Connect easily with other NFC devices
Reader mode
4
Secure NFC
Mobile device is a credit card and travel card
Card emulation mode
on NFC devices.
Publisher makes sure that the application is only available to NFC enabled devices
available on device
Check for presence of NFC feature and adapt the user experience or... Make 2 versions of the application
Collect, classify and share NFC tag info View contacts and collection in a dynamic timeline
8
NFC Basics
http://www.nfc-forum.org/specs/
9
Spec overview
Omits specific bit / byte encodings,
details and alternatives Gives high-level overview of the concepts!
10 The 'N' Logo is a trademark of the NFC Forum, Inc. in the United States and in other countries.
Reader / Writer
RTD (Record Type Definition) NDEF (NFC Data Exchange format)
Tag Type 1, 2, 3, 4
Peer-2-Peer
LLCP (Logical Link Control Protocol) NFCIP
Operating Modes
Reader/writer: when reader is polling for a tag Peer to Peer: communicate with another NFC device (share information) Card Emulation*: where the NFC device acts as a card (e.g. credit card or gift card)
Card Emulation*
Reader /writer
Peer to Peer
NFC Controller
Tag (Initiator)
Simple, thin device containing antenna and small amount of memory Passive, powered by magnetic field that can
Reader (Target) Active device generating radio signals to communicate with tags
be picked up by Target
Can be Read-Only/Rewritable/Writable once
13
Poster
Magazine page
Gadgets
Works by touching, instant Design can be merged with product Larger data storage possible Multiple use cases (app launch, BT pairing) Re-writable (if desired)
Inconvenient (camera, focus, take picture) Large visual impact on product Very limited data storage Limited use cases (no app launch, BT pairing) Write-only
15
16
Nokia 700
17
24
Qt NFC Development
Requirements
Qt SDK 1.1.3
Contains: Qt 4.7.3, Qt Mobility 1.1.3 Contains: Qt 4.7.4, Qt Mobility 1.2.0
MeeGo
Nokia N9 Install Qt SDKs experimental MeeGo Harmattan target
25 2011 Nokia Nokia NFC Development v. 1.1.6
Device Setup
Install Symbian Belle (Windows Start menu) Qt 4.7.4
Qt Mobility
Mobility 1.0 Bearer Management API Contacts Location Messaging Multimedia Publish and Subscribe Service Framework Sensors System Information Versit Mobility 1.1 Camera Document Gallery Feedback Landmarks Maps/Navigation Organizer Service Framework Out of process Mobility 1.2 develop now, deploy later this year Connectivity (Bluetooth, NFC)
27
API Overview*
* Not a class diagram, but explains sequential usage order
QNearFieldManager
Detects and filters targets
QLlcpServer
QNdefMessage
QNearFieldTarget
QLlcpSocket
QNdefRecord
https://projects.developer.nokia.com/nfccorkboards
NFC Corkboards
Tasks Extend Qt SDK example with NFC: Touch tag to create note Qt Quick based UI C++ based NFC Integrate C++ with QML
31
32
Choosing Targets
If you are using SDK 1.1.2, Select our new Qt 4.7.3 for Symbian^3 with QtM1.2b target
33
Choosing Targets
If you are using SDK 1.1.3,
Select Qt Simulator
34
35
App Overview
main.cpp
Application startup Loads and shows corkboards.qml
36
corkboards.qml
UI definition Defines data model and view
Day.qml
Delegate for drawing the UI for a single day Interaction for notes
ListView
Shows data from a model in a list Horizontal or vertical
Delegate
Template defining each item instantiated by the view
in: Day.qml
37
Add Connectivity
Edit the Qt project file (corkboards.pro)
Uncomment & add mobility component: connectivity
CONFIG += mobility MOBILITY += connectivity
38
(See: developer.nokia.com/Community/Wiki/Capabilities)
Capability
NetworkServices Location UserEnvironment ReadUserData / WriteUserData LocalServices ReadDeviceData
Basic Capabilities
Extended Capabilities
Access
Capability
LocalServices ReadUserData WriteUserData NetworkServices UserEnvironment Location
SwEvent ProtServ TrustedUI PowerMgmt SurroundingsDD ReadDeviceData WriteDeviceData CommDD DiskAdmin MultimediaDD NetworkControl AllFiles DRM
User Grantable
Express Signed
Certified Signed
Sales version
For testing
Sales version
Device
Manufacturer
approval
For testing
Sales version
TCB
Lead-time
Note
Immediate
Developer Tested
Immediate
Upload SIS
Immediate
Certify on PC
Immediate
Developer tested
1 week
1 week
Extended Capabilities
Sign up for Ovi Publish account (1)
publish.ovi.com
developer.nokia.com/Distribute/Packaging_and_signing.xhtml
developer.nokia.com/Distribute/Packaging_and_signing.xhtml
Need Certified Signed capabilities? Publish developer.nokia.com/Community/Wiki/Capabilities -> Purchase a Publisher ID ($200 / year) Submit to Certified Signed process @ www.symbiansigned.com
42 2011 Nokia Nokia NFC Development v. 1.1.6
NdefManager
New C++ class
Right-click the project
43
Qt Meta-Object System
C++ extended with QObject
Introspection: meta-information at runtime
management
44
Include
Headers, define member variable
ndefmanager.h
#include <qnearfieldmanager.h> #include <qndeffilter.h> #include <qnearfieldtarget.h> #include <qndefmessage.h> #include <qndefrecord.h> #include <qndefnfcurirecord.h> #include <QUrl> #include <QDebug> // we will test first! QTM_USE_NAMESPACE // Use Qt Mobility namespace [...] private: QNearFieldManager *nfcManager;
45 2011 Nokia Nokia NFC Development v. 1.1.6
Start Waiting
ndefmanager.cpp
NdefManager::NdefManager(QObject *parent) : QObject(parent) { // NdefManager (this) is the parent; will automatically delete nfcManager nfcManager = new QNearFieldManager(this); nfcManager->setTargetAccessModes(QNearFieldManager::NdefReadTargetAccess); // React only to Uri records (NfcRtd, "U") QNdefFilter filter; filter.appendRecord<QNdefNfcUriRecord>(); // Registers message handler with criteria - Uri nfcManager->registerNdefMessageHandler(filter, this, SLOT(targetDetected(QNdefMessage,QNearFieldTarget*))); // Get notified when the tag gets out of range connect(nfcManager, SIGNAL(targetLost(QNearFieldTarget*)), this, SLOT(targetLost(QNearFieldTarget*))); }46
2011 Nokia Nokia NFC Development v. 1.1.6
Slot
Function called in response to a signal Qt objects: predefined slots (e.g., quit()) Also create your own slots
Loosely coupled
Emitter doesnt know or care which slots receive signal Information encapsulation
Tip
Alt + Enter, and Qt Creator writes the .cpp method definition!
49
React
New target: write debug output to console for now
ndefmanager.cpp
void NdefManager::targetDetected(const QNdefMessage &message, QNearFieldTarget *target) { qDebug() << "Uri Target detected!"; }
NdefManager in QML
Import module
corkboards.qml
import Nfc 1.0
Create Instance
corkboards.qml
NdefManager { id: ndefManager }
52
Test! #2
Run the app Touch a URI formatted NDEF tag
53
55
Test! #3
Touch Uri-formatted NDEF NFC tags to create notes on the current page!
57
Tasks Extend previous example React to any kind of tags Write tags by pressing the red flag while touching a tag
58
Overview Before
Register NDEF filters and detect targets
Signal is only emitted when a tag containing all records defined in the filter are found
59
Overview After
Detect any kind of targets
void targetDetected(QNearFieldTarget *target) { const bool hasNdefMessage = target->hasNdefMessage(); if (hasNdefMessage) { connect(target, SIGNAL(ndefMessageRead(QNdefMessage)), this, SLOT(ndefMessageRead(QNdefMessage))); target->readNdefMessages(); } }
Another signal is emitted when reading the message from the target is finished
Target Lost
Set cached target to NULL
ndefmanager.cpp
void NdefManager::targetLost(QNearFieldTarget *target) { cachedTarget = NULL; // New target->deleteLater(); }
64
66
NfcFlag.png
67 2011 Nokia Nokia NFC Development v. 1.1.6
<project dir>\qml\
Test!
https://projects.developer.nokia.com/nfccorkboards
Touch a tag, at the same time press the NFC flag of a note
Writes the note text to the tag Remember to enter a valid URI!
The extended solution on Nokia Developer Projects additionally handles text tags and potential errors.
68
https://projects.developer.nokia.com/nfccorkboards
NFC Corkboards
69
71
ndefmanager.cpp
void NdefManager::targetMessageDetected(const QNdefMessage &message, QNearFieldTarget *target) { qDebug() << "Target detected!"; ndefMessageRead(message); }
73 2011 Nokia Nokia NFC Development v. 1.1.6
https://projects.developer.nokia.com/nfcchat
NFC Chat
Tasks Develop an NFC chat from scratch NFC Peer to Peer mode LLCP Protocol (server & client sockets) Qt Quick UI
74
App Overview
main.cpp
Application startup Loads and shows main.qml
main.qml
UI definition Defines data model and view
nfcpeertopeer.cpp/.h
Target discovery NFC Peer to peer sockets (client & server)
75
Add Connectivity
Edit the Qt project file (nfcchat.pro)
Uncomment & add mobility component: connectivity
CONFIG += mobility MOBILITY += connectivity
78
UI Design
Delete existing main.qml and MainPage.qml
79
Solution: (main.qml)
import QtQuick 1.0 Rectangle { id: rectangle1 width: 360 height: 360 Image { id: sendButton x: 291 anchors.right: parent.right anchors.rightMargin: 0 anchors.top: parent.top anchors.topMargin: 0 source: "NfcButton.png" MouseArea { id: mouse_area1 anchors.fill: parent }} // continue next page }
80 2011 Nokia Nokia NFC Development v. 1.1.6
Solution: (main.qml)
TextEdit { id: sendTextEdit width: 80 height: 20 text: "Hello NFC" anchors.left: parent.left anchors.leftMargin: 0 anchors.top: parent.top anchors.topMargin: 0 font.pixelSize: 10 } ListModel { id:messageModel } // continue next page
81 2011 Nokia Nokia NFC Development v. 1.1.6
Solution: (main.qml)
ListView { id: messageView model: messageModel delegate: Text {text: chatMessage } anchors.right: parent.right anchors.rightMargin: 0 anchors.left: parent.left anchors.leftMargin: 0 anchors.bottom: parent.bottom anchors.bottomMargin: 0 anchors.top: sendButton.bottom anchors.topMargin: 0
}
82 2011 Nokia Nokia NFC Development v. 1.1.6
NfcPeerToPeer
Go to the Edit view New C++ class
Right-click the project
Add New ...
C++ Class
Class name: NfcPeerToPeer Base class: QObject
86 2011 Nokia Nokia NFC Development v. 1.1.6
Include
Headers, define member variable
nfcpeertopeer.h
#include <qnearfieldmanager.h> #include <qllcpserver.h> #include <qllcpsocket.h> QTM_USE_NAMESPACE // Use Qt Mobility namespace
[...] private: QLatin1String nfcUri; QNearFieldManager *nfcManager; QLlcpServer *nfcServer; QLlcpSocket *nfcClientSocket; QLlcpSocket *nfcServerSocket;
87 2011 Nokia Nokia NFC Development v. 1.1.6
}
88 2011 Nokia Nokia NFC Development v. 1.1.6
89
React
New target: emit info message
nfcpeertopeer.cpp
void NfcPeerToPeer::targetDetected(QNearFieldTarget *target) { emit chatMessage("Target detected"); }
NfcPeerToPeer in QML
Import module
main.qml
import NfcPeerToPeer 1.0
Test!
Note: NFC app cannot be deploy on C7 with Symbian Anna at this moment With SDK 1.1.3 .
93
Test in simulator!
94
96
97
Cleanup in targetLost()
nfcpeertopeer.cpp
nfcClientSocket->disconnectFromService();
99
Test! #2
Touch upper back of two phones
Note: NFC app cannot be deploy on C7 with Symbian Anna at this moment With SDK 1.1.3 . Click on the link to view details
https://projects.developer.nokia.com/nfcchat
The extended solution on Nokia Developer Projects includes cached text sending and error handling and is based on Qt Quick Components. Note: if installing the solution, uninstall your own app first to avoid a name conflict..
100
Compatible with Qt 4.6 (Qt mobility 1.0) All of the above S60 3rd Edition: E72, E71, E66, E63 and E52 Check here for the updated list: http://www.developer.nokia.com/Distribute/Packaging_and_signing.xhtml
101 2011 Nokia Nokia NFC Development v. 1.1.6
e-Learning materials
http://qt.nokia.com/developer/learning/online/training/ http://qt.nokia.com/services-partners/qt-in-education/qt-in-education-course-material
Community
http://www.qtcentre.org/
102
Qt Books
(some recommendations)
Ray Rischpater, Daniel Zucker. Apress. Complete end-to-end story of developing for Symbian
and MeeGo with Qt (Quick) and HTML 5. Status: Qt 4.7, December 2010
Foundations of Qt Development
More in-depth and technically oriented explanation of Qt different approach to many other books. Generic Qt, no mobile. Status: 2007
Official book for generic Qt development (no mobile). Good for looking things up or for enhancing your knowledge, average for learning from scratch. Status: Qt 4.3, 2008
103
104
105
Universities
Qt is a good way to teach software development
Instant results to motivate attendees Graphical tools make entry easier Flexible system, extensible with own libraries and still standard C++!
University support
Free Qt course materials under Creative Commons (PPT and OpenOffice)
107
Thank You.
108