-
Notifications
You must be signed in to change notification settings - Fork 3
/
writeURItoNFCtag.py
64 lines (55 loc) · 2.08 KB
/
writeURItoNFCtag.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
# -*- coding: latin-1 -*-
#
# Author: Jose Miguel Esparza (jesparza AT eternal-todo DOT com)
# Date: 2012-07-01
# Description: Simple script to write any URI to an NFC tag. Using the 0x00 URI type we can write any type of
# URI in the tag, without thinking about it. Based on the helloworld.py (nfcpy) script.
# You can take a look at:
# - The different URIs defined by the specification: http://www.maintag.fr/fichiers/pdf-fr/nfcforum-ts-rtd-uri-1-0.pdf
# - Other special URIs related to installed mobile applications: http://sixrevisions.com/web-development/qr-codes-uri-schemes/
# Requirements: nfcpy
#
#
# -----------------------------------------------------------------------------
# Copyright 2011 Stephen Tiedemann <[email protected]>
#
# Licensed under the EUPL, Version 1.1 or - as soon they
# will be approved by the European Commission - subsequent
# versions of the EUPL (the "Licence");
# You may not use this work except in compliance with the
# Licence.
# You may obtain a copy of the Licence at:
#
# http://www.osor.eu/eupl
#
# Unless required by applicable law or agreed to in
# writing, software distributed under the Licence is
# distributed on an "AS IS" basis,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied.
# See the Licence for the specific language governing
# permissions and limitations under the Licence.
# -----------------------------------------------------------------------------
import os
import sys
import time
sys.path.insert(1, os.path.split(sys.path[0])[0])
import nfc
import nfc.ndef
import nfc.ndef.Uri
if len(sys.argv) != 2:
sys.exit('Usage: '+sys.argv[0]+' uri')
myURI = sys.argv[1]
clf = nfc.ContactlessFrontend()
print "Please, touch a tag to send your URI to the world..."
while True:
tag = clf.poll()
if tag and tag.ndef:
break
time.sleep(1)
uri = nfc.ndef.Uri.UriRecord(myURI)
uri._data = '\x00'+myURI
message = nfc.ndef.Message(uri)
tag.ndef.message = message.tostring()
print "Thanks, you can remove the tag..."